From e4c7667b472293ab67bb1536c68d0c25ab064dd3 Mon Sep 17 00:00:00 2001
From: Jan Henk Hazelaar
Lange beschrijving
') + ->and($unitType->count)->toBe(22) + ->and($unitType->price_from)->toBe(317600) + ->and($unitType->price_to)->toBe(423300) + ->and($unitType->lot_area_from)->toBe(50) + ->and($unitType->lot_area_to)->toBe(80) + ->and($unitType->living_area_from)->toBe(79) + ->and($unitType->living_area_to)->toBe(79) + ->and($unitType->volume_from)->toBe(200) + ->and($unitType->volume_to)->toBe(240) + ->and($unitType->bedrooms_from)->toBe(2) + ->and($unitType->bedrooms_to)->toBe(2) + ->and($unitType->rooms_from)->toBe(3) + ->and($unitType->rooms_to)->toBe(3) + ->and($unitType->ownership)->toBe('Eigendom') + ->and($unitType->tenure)->toBe('Koopwoning'); +}); diff --git a/tests/Requests/UnitTypes/GetUnitTypeRequestTest.php b/tests/Requests/UnitTypes/GetUnitTypeRequestTest.php index be7bfd2..38b7c10 100644 --- a/tests/Requests/UnitTypes/GetUnitTypeRequestTest.php +++ b/tests/Requests/UnitTypes/GetUnitTypeRequestTest.php @@ -1,7 +1,11 @@ getMethod())->toBe(Method::GET); @@ -18,3 +22,62 @@ expect((new GetUnitTypeRequest('proj-1', 'unit-9'))->resolveEndpoint()) ->toBe('/projects/proj-1/projectwoningen/unit-9/'); }); + +it('creates a UnitType DTO from the response', function () { + $mockClient = new MockClient([ + GetUnitTypeRequest::class => MockResponse::make([ + 'data' => [ + 'object' => [ + 'Projectwoning_UUId' => '631c2a57a0ce5edc989c67d3661f4711', + 'Projectwoning_Online' => '-1', + 'Plandeel' => null, + 'Projectwoning_Titel' => 'Rug-aan-rug woning', + 'Woning_Type' => 'Tussenwoning', + 'Projectwoning_Volgorde' => '1', + 'Projectwoning_Beschrijving_Kort' => null, + 'Projectwoning_Beschrijving_Lang' => null, + 'Projectwoning_Beschrijving_HTML' => null, + 'Projectwoning_Aantal' => '22', + 'Projectwoning_PrijsVan' => '317600', + 'Projectwoning_PrijsTot' => '423300', + 'Projectwoning_KavelOppVan' => null, + 'Projectwoning_KavelOppTot' => null, + 'Projectwoning_WoonOppVan' => '79', + 'Projectwoning_WoonOppTot' => '79', + 'Projectwoning_InhoudVan' => null, + 'Projectwoning_InhoudTot' => null, + 'Projectwoning_SlaapkamersVan' => '2', + 'Projectwoning_SlaapkamersTot' => '2', + 'Eigendom' => 'Eigendom', + 'Huurkoop' => 'Koopwoning', + 'NrWoningen' => '22', + 'NrMedia' => '7', + 'Projectwoning_KamersVan' => null, + 'Projectwoning_KamersTot' => null, + ], + ], + ]), + ]); + + $connector = new NieuwbouwOffice('test-token'); + $connector->withMockClient($mockClient); + + $unitType = $connector->send(new GetUnitTypeRequest('proj-1', '631c2a57a0ce5edc989c67d3661f4711'))->dto(); + + expect($unitType)->toBeInstanceOf(UnitType::class) + ->and($unitType->uuid)->toBe('631c2a57a0ce5edc989c67d3661f4711') + ->and($unitType->is_online)->toBeTrue() + ->and($unitType->title)->toBe('Rug-aan-rug woning') + ->and($unitType->kind)->toBe('Tussenwoning') + ->and($unitType->order)->toBe(1) + ->and($unitType->count)->toBe(22) + ->and($unitType->price_from)->toBe(317600) + ->and($unitType->price_to)->toBe(423300) + ->and($unitType->living_area_from)->toBe(79) + ->and($unitType->bedrooms_from)->toBe(2) + ->and($unitType->rooms_from)->toBeNull() + ->and($unitType->ownership)->toBe('Eigendom') + ->and($unitType->tenure)->toBe('Koopwoning') + ->and($unitType->home_count)->toBe(22) + ->and($unitType->media_count)->toBe(7); +}); diff --git a/tests/Requests/UnitTypes/GetUnitTypesRequestTest.php b/tests/Requests/UnitTypes/GetUnitTypesRequestTest.php index 566d471..619df87 100644 --- a/tests/Requests/UnitTypes/GetUnitTypesRequestTest.php +++ b/tests/Requests/UnitTypes/GetUnitTypesRequestTest.php @@ -1,7 +1,11 @@ getMethod())->toBe(Method::GET); @@ -15,3 +19,57 @@ expect((new GetUnitTypesRequest('proj-1'))->resolveEndpoint()) ->toBe('/projects/proj-1/projectwoningen/'); }); + +it('creates an array of UnitType DTOs from the response', function () { + $mockClient = new MockClient([ + GetUnitTypesRequest::class => MockResponse::make([ + 'data' => [ + 'objects' => [ + [ + 'Projectwoning_UUId' => 'dc28a597e2661a3bf7f84737eb1f38c9', + 'Projectwoning_Online' => '-1', + 'Projectwoning_Titel' => 'Gezinswoning M', + 'Woning_Type' => 'Tussenwoning', + 'Projectwoning_Volgorde' => '2', + 'Projectwoning_Beschrijving_Kort' => null, + 'NrWoningen' => '2', + 'NrMedia' => '6', + ], + [ + 'Projectwoning_UUId' => 'a8caa9dc5a353a938440361e8005d06d', + 'Projectwoning_Online' => '-1', + 'Projectwoning_Titel' => 'Appartement', + 'Woning_Type' => 'Appartement', + 'Projectwoning_Volgorde' => '5', + 'Projectwoning_Beschrijving_Kort' => null, + 'NrWoningen' => '14', + 'NrMedia' => '5', + ], + ], + ], + 'meta' => ['count' => 2], + ]), + ]); + + $connector = new NieuwbouwOffice('test-token'); + $connector->withMockClient($mockClient); + + $unitTypes = $connector->send(new GetUnitTypesRequest('proj-1'))->dto(); + + expect($unitTypes)->toBeArray()->toHaveCount(2) + ->and($unitTypes[0])->toBeInstanceOf(UnitType::class) + ->and($unitTypes[0]->uuid)->toBe('dc28a597e2661a3bf7f84737eb1f38c9') + ->and($unitTypes[0]->is_online)->toBeTrue() + ->and($unitTypes[0]->title)->toBe('Gezinswoning M') + ->and($unitTypes[0]->kind)->toBe('Tussenwoning') + ->and($unitTypes[0]->order)->toBe(2) + ->and($unitTypes[0]->home_count)->toBe(2) + ->and($unitTypes[0]->media_count)->toBe(6) + ->and($unitTypes[0]->price_from)->toBeNull() + ->and($unitTypes[1])->toBeInstanceOf(UnitType::class) + ->and($unitTypes[1]->uuid)->toBe('a8caa9dc5a353a938440361e8005d06d') + ->and($unitTypes[1]->title)->toBe('Appartement') + ->and($unitTypes[1]->kind)->toBe('Appartement') + ->and($unitTypes[1]->order)->toBe(5) + ->and($unitTypes[1]->home_count)->toBe(14); +}); diff --git a/tests/Resources/UnitTypeResourceTest.php b/tests/Resources/UnitTypeResourceTest.php index 6b8c56e..369e47b 100644 --- a/tests/Resources/UnitTypeResourceTest.php +++ b/tests/Resources/UnitTypeResourceTest.php @@ -1,35 +1,41 @@ MockResponse::make([ 'data' => [ - ['uuid' => 'u1', 'name' => 'Type A'], - ['uuid' => 'u2', 'name' => 'Type B'], + 'objects' => [ + [ + 'Projectwoning_UUId' => 'u1', + 'Projectwoning_Titel' => 'Type A', + ], + [ + 'Projectwoning_UUId' => 'u2', + 'Projectwoning_Titel' => 'Type B', + ], + ], ], + 'meta' => ['count' => 2], ]), ]); $connector = new NieuwbouwOffice('test-token'); $connector->withMockClient($mockClient); - $response = $connector->unitTypes('proj-1')->list(); + $unitTypes = $connector->unitTypes('proj-1')->list(); - expect($response)->toBeInstanceOf(Response::class) - ->and($response->json())->toBe([ - 'data' => [ - ['uuid' => 'u1', 'name' => 'Type A'], - ['uuid' => 'u2', 'name' => 'Type B'], - ], - ]); + expect($unitTypes)->toBeArray()->toHaveCount(2) + ->and($unitTypes[0])->toBeInstanceOf(UnitType::class) + ->and($unitTypes[0]->uuid)->toBe('u1') + ->and($unitTypes[1]->uuid)->toBe('u2'); $mockClient->assertSent(function ($request) { return $request instanceof GetUnitTypesRequest @@ -38,24 +44,26 @@ }); }); -it('get() sends a GetUnitTypeRequest with the right project uuid and uuid', function () { +it('get() sends a GetUnitTypeRequest with the right project uuid and uuid and returns a UnitType DTO', function () { $mockClient = new MockClient([ GetUnitTypeRequest::class => MockResponse::make([ - 'uuid' => 'unit-9', - 'name' => 'Type Z', + 'data' => [ + 'object' => [ + 'Projectwoning_UUId' => 'unit-9', + 'Projectwoning_Titel' => 'Type Z', + ], + ], ]), ]); $connector = new NieuwbouwOffice('test-token'); $connector->withMockClient($mockClient); - $response = $connector->unitTypes('proj-1')->get('unit-9'); + $unitType = $connector->unitTypes('proj-1')->get('unit-9'); - expect($response)->toBeInstanceOf(Response::class) - ->and($response->json())->toBe([ - 'uuid' => 'unit-9', - 'name' => 'Type Z', - ]); + expect($unitType)->toBeInstanceOf(UnitType::class) + ->and($unitType->uuid)->toBe('unit-9') + ->and($unitType->title)->toBe('Type Z'); $mockClient->assertSent(function ($request) { return $request instanceof GetUnitTypeRequest