From 44382eecc71eacf9fc6fb9828bda06d63f3d01c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pillevesse?= Date: Wed, 10 Jan 2024 09:23:01 +0100 Subject: [PATCH 1/3] add get case feature --- src/Model/Case/CaseDetailed.php | 64 ++++++++ src/Service/CaseService.php | 20 +++ tests/FunctionalTests/CaseGetTest.php | 58 +++++++ .../case_get_with_minimal_data_response.json | 143 ++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 src/Model/Case/CaseDetailed.php create mode 100644 tests/FunctionalTests/CaseGetTest.php create mode 100644 tests/fixtures/case_get_with_minimal_data_response.json diff --git a/src/Model/Case/CaseDetailed.php b/src/Model/Case/CaseDetailed.php new file mode 100644 index 0000000..9e0aab6 --- /dev/null +++ b/src/Model/Case/CaseDetailed.php @@ -0,0 +1,64 @@ +|null + */ + public ?array $metadata = null; + + /** + * Optional custom properties in a format of key (string) / value (string|boolean|[string]|null) for this case. + * + * @see https://docs.dotfile.com/reference/cases-guide#custom-properties + * + * @var array + */ + public ?array $customProperties = null; + + /** + * @var Individual[] + */ + public array $individuals; + + /** + * @var Company[] + */ + public array $companies; + + public \DateTimeImmutable $createdAt; + public \DateTimeImmutable $updatedAt; + public \DateTimeImmutable $lastActivityAt; +} diff --git a/src/Service/CaseService.php b/src/Service/CaseService.php index c6d8da8..a3a72cb 100644 --- a/src/Service/CaseService.php +++ b/src/Service/CaseService.php @@ -7,6 +7,7 @@ use Dotfile\Exception\DotfileApiException; use Dotfile\Model\Case\CaseCreated; use Dotfile\Model\Case\CaseCreateInput; +use Dotfile\Model\Case\CaseDetailed; use Dotfile\Model\Case\CaseTags; use Dotfile\Model\Case\CaseUpdated; use Dotfile\Model\Case\CaseUpdateInput; @@ -61,6 +62,25 @@ public function update(string $caseId, CaseUpdateInput $input): CaseUpdated return $caseUpdated; } + public function get(string $caseId): CaseDetailed + { + $response = $this->client->request(Request::METHOD_GET, 'cases/'.$caseId, [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + ]); + + $caseDetailed = $this->serializer->deserialize($this->getContent($response), CaseDetailed::class, 'json'); + + if (null !== $caseDetailed->risk) { + if (RiskLevel::NotDefined === $caseDetailed->risk->level) { + $caseDetailed->risk = null; + } + } + + return $caseDetailed; + } + public function getTags(string $caseId): CaseTags { $response = $this->client->request(Request::METHOD_GET, 'cases/'.$caseId.'/tags', [ diff --git a/tests/FunctionalTests/CaseGetTest.php b/tests/FunctionalTests/CaseGetTest.php new file mode 100644 index 0000000..29e2af2 --- /dev/null +++ b/tests/FunctionalTests/CaseGetTest.php @@ -0,0 +1,58 @@ +case->get('946a9af4-67ff-44e6-a0dc-a73e022365ff'); + + $this->assertInstanceOf(CaseDetailed::class, $caseDetailed); + $this->assertSame('946a9af4-67ff-44e6-a0dc-a73e022365ff', $caseDetailed->id); + $this->assertSame('A case created from tests', $caseDetailed->name); + $this->assertSame(CaseStatus::Open, $caseDetailed->status); + $this->assertSame('06042010', $caseDetailed->externalId); + $this->assertSame('78bb7107-afd9-4681-9093-42ead2c14f68', $caseDetailed->templateId); + $this->assertCount(1, $caseDetailed->flags); + $this->assertSame(CaseFlag::ForFirstCollect, $caseDetailed->flags[0]); + $this->assertCount(1, $caseDetailed->tags); + $this->assertSame('A faire', $caseDetailed->tags[0]); + $this->assertNull($caseDetailed->risk); + $this->assertSame(['metadata_key1' => 'metadata_value1'], $caseDetailed->metadata); + $this->assertSame(['a_custom_property' => null], $caseDetailed->customProperties); + $this->assertInstanceOf(\DateTimeImmutable::class, $caseDetailed->createdAt); + $this->assertInstanceOf(\DateTimeImmutable::class, $caseDetailed->updatedAt); + $this->assertInstanceOf(\DateTimeImmutable::class, $caseDetailed->lastActivityAt); + + $this->assertCount(1, $caseDetailed->individuals); + $this->assertInstanceOf(Individual::class, $caseDetailed->individuals[0]); + $this->assertSame('fae4446d-915f-4417-9412-895f07edf37d', $caseDetailed->individuals[0]->id); + $this->assertSame('946a9af4-67ff-44e6-a0dc-a73e022365ff', $caseDetailed->individuals[0]->caseId); + $this->assertSame('IndividualFirstName', $caseDetailed->individuals[0]->firstName); + $this->assertSame('IndividualLastName', $caseDetailed->individuals[0]->lastName); + + $this->assertCount(1, $caseDetailed->companies); + $this->assertInstanceOf(Company::class, $caseDetailed->companies[0]); + $this->assertSame('a5569aaa-fd71-494c-895c-c374a4470a86', $caseDetailed->companies[0]->id); + $this->assertSame('946a9af4-67ff-44e6-a0dc-a73e022365ff', $caseDetailed->companies[0]->caseId); + $this->assertSame('CompanyA', $caseDetailed->companies[0]->name); + $this->assertNull($caseDetailed->companies[0]->commercialName); + } +} diff --git a/tests/fixtures/case_get_with_minimal_data_response.json b/tests/fixtures/case_get_with_minimal_data_response.json new file mode 100644 index 0000000..e694176 --- /dev/null +++ b/tests/fixtures/case_get_with_minimal_data_response.json @@ -0,0 +1,143 @@ +{ + "id": "946a9af4-67ff-44e6-a0dc-a73e022365ff", + "name": "A case created from tests", + "status": "open", + "external_id": "06042010", + "template_id": "78bb7107-afd9-4681-9093-42ead2c14f68", + "flags": [ + "for_first_collect" + ], + "tags": [ + "A faire" + ], + "risk": { + "level": "not_defined" + }, + "custom_properties": { + "a_custom_property":null + }, + "metadata": { + "metadata_key1": "metadata_value1" + }, + "last_activity_at": "2024-01-09T15:59:34.921Z", + "individuals": [ + { + "id": "fae4446d-915f-4417-9412-895f07edf37d", + "case_id": "946a9af4-67ff-44e6-a0dc-a73e022365ff", + "roles": [ + "legal_representative" + ], + "first_name": "IndividualFirstName", + "middle_name": null, + "last_name": "IndividualLastName", + "maiden_name": null, + "email": null, + "birth_date": null, + "birth_country": null, + "birth_place": null, + "address": {}, + "banking_information": { + "iban": null, + "bic": null + }, + "tax_identification_number": null, + "social_security_number": null, + "phone_number": null, + "position": null, + "ownership_percentage": null, + "custom_properties": {}, + "checks": [ + { + "id": "276adba3-379c-4cba-88fe-51b9ed8bcf72", + "individual_id": "fae4446d-915f-4417-9412-895f07edf37d", + "company_id": null, + "status": "in_progress", + "type": "id_document", + "subtype": null, + "created_at": "2024-01-09T15:59:34.446Z", + "updated_at": "2024-01-09T15:59:34.482Z", + "last_activity_at": "2024-01-09T15:59:34.478Z" + }, + { + "id": "464c4f7a-671f-4898-973e-50838c60bae7", + "individual_id": "fae4446d-915f-4417-9412-895f07edf37d", + "company_id": null, + "status": "in_progress", + "type": "document", + "subtype": "document_type:proof_of_address", + "created_at": "2024-01-09T15:59:34.647Z", + "updated_at": "2024-01-09T15:59:34.716Z", + "last_activity_at": "2024-01-09T15:59:34.687Z" + }, + { + "id": "b1b115ca-8c3e-4f5d-8cd7-3e617072b588", + "individual_id": "fae4446d-915f-4417-9412-895f07edf37d", + "company_id": null, + "status": "in_progress", + "type": "document", + "subtype": "document_type:id_document", + "created_at": "2024-01-09T15:59:34.539Z", + "updated_at": "2024-01-09T15:59:34.571Z", + "last_activity_at": "2024-01-09T15:59:34.566Z" + } + ], + "created_at": "2024-01-09T15:59:34.009Z", + "updated_at": "2024-01-09T15:59:34.716Z", + "last_activity_at": "2024-01-09T15:59:34.687Z" + } + ], + "companies": [ + { + "id": "a5569aaa-fd71-494c-895c-c374a4470a86", + "case_id": "946a9af4-67ff-44e6-a0dc-a73e022365ff", + "name": "CompanyA", + "commercial_name": null, + "registration_number": "070490", + "registration_date": "2024-01-11", + "status": "live", + "legal_form": null, + "country": "FR", + "address": {}, + "classifications": null, + "banking_information": { + "iban": null, + "bic": null + }, + "share_capital": null, + "tax_identification_number": null, + "website_url": null, + "employer_identification_number": null, + "custom_properties": {}, + "document_orders": [], + "checks": [ + { + "id": "21b31de6-bf3a-43b6-bf00-cbe038bc04b0", + "individual_id": null, + "company_id": "a5569aaa-fd71-494c-895c-c374a4470a86", + "status": "in_progress", + "type": "document", + "subtype": "document_type:articles_of_association", + "created_at": "2024-01-09T15:59:34.200Z", + "updated_at": "2024-01-09T15:59:34.232Z", + "last_activity_at": "2024-01-09T15:59:34.229Z" + }, + { + "id": "f2bdfa54-7db8-4138-9921-556e71f6587f", + "individual_id": null, + "company_id": "a5569aaa-fd71-494c-895c-c374a4470a86", + "status": "in_progress", + "type": "document", + "subtype": "document_type:registration_certificate", + "created_at": "2024-01-09T15:59:34.314Z", + "updated_at": "2024-01-09T15:59:34.349Z", + "last_activity_at": "2024-01-09T15:59:34.345Z" + } + ], + "created_at": "2024-01-09T15:59:34.009Z", + "updated_at": "2024-01-09T15:59:34.349Z", + "last_activity_at": "2024-01-09T15:59:34.345Z" + } + ], + "created_at": "2023-12-27T09:39:49.256Z", + "updated_at": "2024-01-09T15:59:34.924Z" +} \ No newline at end of file From 861c58dd4273de24861958f57984c59ac2b95827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pillevesse?= Date: Wed, 10 Jan 2024 09:24:29 +0100 Subject: [PATCH 2/3] add get case example in README --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 160f4d5..c928e01 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,23 @@ See [dotfile documentation](https://docs.dotfile.com/reference/case-create-one).
+Get a case + +```php +use Dotfile\Model\Case\CaseDetailed; + +$caseId = '39cbd6d5-4da5-4d94-ae71-84895c5e552a'; + +$caseDetailed = $client->case->get($caseId); // Returns an instance of CaseDetailed + +echo $caseDetailed->name; // Display "This is the name of the case you retrieved." +``` + +See [dotfile documentation](https://docs.dotfile.com/reference/case-get-one). +
+ +
+ Update a case ```php From d20bc1e935c6b5a7b74dfcca1ad92bc8546718c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pillevesse?= Date: Wed, 10 Jan 2024 09:33:35 +0100 Subject: [PATCH 3/3] update test function name --- tests/FunctionalTests/CaseGetTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FunctionalTests/CaseGetTest.php b/tests/FunctionalTests/CaseGetTest.php index 29e2af2..80b1626 100644 --- a/tests/FunctionalTests/CaseGetTest.php +++ b/tests/FunctionalTests/CaseGetTest.php @@ -16,7 +16,7 @@ class CaseGetTest extends TestCase { - public function testCaseUpdateWithMinimumValidData(): void + public function testCaseGet(): void { $client = new DotfileClient(new MockHttpClient([ new MockResponse((string) file_get_contents(__DIR__.'/../fixtures/case_get_with_minimal_data_response.json')),