refactor(dashboard,history): replace ViewModels with Pinia stores and improve backend

This commit is contained in:
2026-08-05 09:23:18 +02:00
parent a0387126de
commit 90930cd223
29 changed files with 1372 additions and 237 deletions
@@ -0,0 +1,143 @@
<?php
namespace Tests\Unit\Clients;
use App\Clients\ZonneplanPriceClient;
use Carbon\Carbon;
use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Response;
use Mockery;
use Tests\TestCase;
class ZonneplanPriceClientTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
public function test_get_electricity_prices_returns_collection(): void
{
$response = Mockery::mock();
$response->shouldReceive('throw')->once();
$response->shouldReceive('json')
->once()
->with('data', [])
->andReturn([
['start_date' => Carbon::now()->format('Y-m-d H:i:s'), 'total_price_tax_included' => 15.0],
]);
$response->shouldReceive('status')->once()->andReturn(200);
$http = Mockery::mock(Factory::class);
$http->shouldReceive('baseUrl')->once()->andReturnSelf();
$http->shouldReceive('withQueryParameters')->once()->andReturnSelf();
$http->shouldReceive('timeout')->once()->andReturnSelf();
$http->shouldReceive('retry')->once()->andReturnSelf();
$http->shouldReceive('get')->once()->andReturn($response);
$client = new ZonneplanPriceClient($http);
$result = $client->getElectricityPrices();
$this->assertCount(1, $result);
}
public function test_get_gas_prices_returns_collection(): void
{
$response = Mockery::mock();
$response->shouldReceive('throw')->once();
$response->shouldReceive('json')
->once()
->with('data', [])
->andReturn([
['start_date' => Carbon::now()->format('Y-m-d H:i:s'), 'total_price_tax_included' => 5.0],
]);
$response->shouldReceive('status')->once()->andReturn(200);
$http = Mockery::mock(Factory::class);
$http->shouldReceive('baseUrl')->once()->andReturnSelf();
$http->shouldReceive('withQueryParameters')->once()->andReturnSelf();
$http->shouldReceive('timeout')->once()->andReturnSelf();
$http->shouldReceive('retry')->once()->andReturnSelf();
$http->shouldReceive('get')->once()->andReturn($response);
$client = new ZonneplanPriceClient($http);
$result = $client->getGasPrices();
$this->assertCount(1, $result);
}
public function test_get_electricity_prices_for_date_returns_collection(): void
{
$date = Carbon::today();
$response = Mockery::mock();
$response->shouldReceive('throw')->once();
$response->shouldReceive('json')
->once()
->with('data', [])
->andReturn([
['start_date' => $date->format('Y-m-d H:i:s'), 'total_price_tax_included' => 15.0],
]);
$response->shouldReceive('status')->once()->andReturn(200);
$http = Mockery::mock(Factory::class);
$http->shouldReceive('baseUrl')->once()->andReturnSelf();
$http->shouldReceive('withQueryParameters')->once()->andReturnSelf();
$http->shouldReceive('timeout')->once()->andReturnSelf();
$http->shouldReceive('retry')->once()->andReturnSelf();
$http->shouldReceive('get')->once()->andReturn($response);
$client = new ZonneplanPriceClient($http);
$result = $client->getElectricityPricesForDate($date);
$this->assertCount(1, $result);
}
public function test_get_gas_prices_for_date_returns_collection(): void
{
$date = Carbon::today();
$response = Mockery::mock();
$response->shouldReceive('throw')->once();
$response->shouldReceive('json')
->once()
->with('data', [])
->andReturn([
['start_date' => $date->format('Y-m-d H:i:s'), 'total_price_tax_included' => 5.0],
]);
$response->shouldReceive('status')->once()->andReturn(200);
$http = Mockery::mock(Factory::class);
$http->shouldReceive('baseUrl')->once()->andReturnSelf();
$http->shouldReceive('withQueryParameters')->once()->andReturnSelf();
$http->shouldReceive('timeout')->once()->andReturnSelf();
$http->shouldReceive('retry')->once()->andReturnSelf();
$http->shouldReceive('get')->once()->andReturn($response);
$client = new ZonneplanPriceClient($http);
$result = $client->getGasPricesForDate($date);
$this->assertCount(1, $result);
}
public function test_client_throws_exception_on_api_failure(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Kon energieprijzen niet ophalen');
$response = Mockery::mock();
$response->shouldReceive('throw')->once()->andThrow(
new \Illuminate\Http\Client\ConnectionException('API Error')
);
$http = Mockery::mock(Factory::class);
$http->shouldReceive('baseUrl')->once()->andReturnSelf();
$http->shouldReceive('withQueryParameters')->once()->andReturnSelf();
$http->shouldReceive('timeout')->once()->andReturnSelf();
$http->shouldReceive('retry')->once()->andReturnSelf();
$http->shouldReceive('get')->once()->andReturn($response);
$client = new ZonneplanPriceClient($http);
$client->getElectricityPrices();
}
}