From e2085bd518e6c0cabf1fbbdc0b7bc429cc033310 Mon Sep 17 00:00:00 2001 From: Nick de Vries Date: Thu, 15 Feb 2024 17:13:54 +0100 Subject: [PATCH] :construction: Working on create collection feature. --- .../MyParcelComApi/CollectionsTest.php | 16 +++++ tests/Stubs/post/https---api-collections.json | 71 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tests/Stubs/post/https---api-collections.json diff --git a/tests/Feature/MyParcelComApi/CollectionsTest.php b/tests/Feature/MyParcelComApi/CollectionsTest.php index 7f5f0194..07946a0f 100644 --- a/tests/Feature/MyParcelComApi/CollectionsTest.php +++ b/tests/Feature/MyParcelComApi/CollectionsTest.php @@ -6,6 +6,8 @@ use DateTime; use MyParcelCom\ApiSdk\Collection\CollectionInterface as ResourceCollectionInterface; +use MyParcelCom\ApiSdk\Resources\Collection; +use MyParcelCom\ApiSdk\Resources\CollectionTime; use MyParcelCom\ApiSdk\Resources\Interfaces\CollectionInterface; use MyParcelCom\ApiSdk\Tests\TestCase; @@ -58,4 +60,18 @@ public function testItRetrievesASingleCollection(): void $this->assertEquals('8d8d63aa-032b-4674-990b-706551a2bf23', $collection->getId()); $this->assertEquals('Test', $collection->getDescription()); } + + public function testItCreatesANewCollection(): void + { + $newCollection = new Collection(); + $newCollection->setDescription('Some description'); + $newCollection->setCollectionTime( + (new CollectionTime())->setFrom(123456789)->setTo(987654321) + ); + + $collection = $this->api->createCollection($newCollection); + + $this->assertInstanceOf(CollectionInterface::class, $collection); + $this->assertEquals('Test collection 3', $collection->getDescription()); + } } diff --git a/tests/Stubs/post/https---api-collections.json b/tests/Stubs/post/https---api-collections.json new file mode 100644 index 00000000..311e39c7 --- /dev/null +++ b/tests/Stubs/post/https---api-collections.json @@ -0,0 +1,71 @@ +{ + "data": { + "id": "8d8d63aa-032b-4674-990b-706551a2bf23", + "type": "collections", + "attributes": { + "description": "Test create", + "collection_time": { + "from": 1708085160, + "to": 1708096680 + }, + "register": false, + "address": { + "street_1": "200 Westminster Bridge Rd", + "postal_code": "SE1 7UT", + "city": "London", + "country_code": "GB", + "company": "MyParcel.com", + "first_name": "MP", + "last_name": "Sender", + "email": "info@myparcel.com", + "phone_number": "+31 85 208 5997" + }, + "tracking_code": "TRK-1234567890", + "created_at": 1707991769 + }, + "links": { + "self": "https:\/\/api.localhost.private\/collections\/8d8d63aa-032b-4674-990b-706551a2bf23" + }, + "relationships": { + "shop": { + "data": { + "id": "1ebabb0e-9036-4259-b58e-2b42742bb86a", + "type": "shops" + }, + "links": { + "related": "https:\/\/api.localhost.private\/shops\/1ebabb0e-9036-4259-b58e-2b42742bb86a" + } + }, + "status": { + "data": { + "id": "583e311f-8f03-4b34-84dd-5a82305ce5a8", + "type": "statuses" + }, + "links": { + "related": "https:\/\/api.localhost.private\/statuses\/583e311f-8f03-4b34-84dd-5a82305ce5a8" + } + }, + "shipments": { + "data": [ + { + "id": "65e10ca7-5e34-40da-9da5-928f8aa57f97", + "type": "shipments" + }, + { + "id": "872960ef-2a2c-4ab5-9a36-01478fd20276", + "type": "shipments" + } + ] + }, + "contract": { + "data": { + "id": "be5c82fd-e936-440a-a5d8-9a3124d86fcf", + "type": "contracts" + }, + "links": { + "related": "https:\/\/api.localhost.private\/contracts\/be5c82fd-e936-440a-a5d8-9a3124d86fcf" + } + } + } + } +}