Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Add get case feature #12

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ See [dotfile documentation](https://docs.dotfile.com/reference/case-create-one).

<details>

<summary>Get a case</summary>

```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).
</details>

<details>

<summary>Update a case</summary>

```php
Expand Down
64 changes: 64 additions & 0 deletions src/Model/Case/CaseDetailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Dotfile\Model\Case;

use Dotfile\Model\Company\Company;
use Dotfile\Model\Individual\Individual;

/**
* Response when a specific case have been retrieved.
*
* @see https://docs.dotfile.com/reference/case-get-one
*/
class CaseDetailed
{
public string $id;
public string $name;
public CaseStatus $status;
public ?string $externalId = null;
public ?string $templateId = null;

/**
* @var CaseFlag[]
*/
public array $flags;
/**
* @var string[]
*/
public array $tags;
public ?Risk $risk = null;

/**
* Optional metadata in a format of key (string) / value (string) for this case.
*
* @see https://docs.dotfile.com/reference/cases-guide#metadata
*
* @var array<string, string>|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<string, string|boolean|string[]|null>
*/
public ?array $customProperties = null;

/**
* @var Individual[]
*/
public array $individuals;

/**
* @var Company[]
*/
public array $companies;

public \DateTimeImmutable $createdAt;
public \DateTimeImmutable $updatedAt;
public \DateTimeImmutable $lastActivityAt;
}
20 changes: 20 additions & 0 deletions src/Service/CaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', [
Expand Down
58 changes: 58 additions & 0 deletions tests/FunctionalTests/CaseGetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Dotfile\Tests\FunctionalTests;

use Dotfile\DotfileClient;
use Dotfile\Model\Case\CaseDetailed;
use Dotfile\Model\Case\CaseFlag;
use Dotfile\Model\Case\CaseStatus;
use Dotfile\Model\Company\Company;
use Dotfile\Model\Individual\Individual;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;

class CaseGetTest extends TestCase
{
public function testCaseGet(): void
{
$client = new DotfileClient(new MockHttpClient([
new MockResponse((string) file_get_contents(__DIR__.'/../fixtures/case_get_with_minimal_data_response.json')),
]));

$caseDetailed = $client->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);
}
}
143 changes: 143 additions & 0 deletions tests/fixtures/case_get_with_minimal_data_response.json
Original file line number Diff line number Diff line change
@@ -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"
}