From 413ecd6bc6062a1b28c4907fd54ef3bbb761bc47 Mon Sep 17 00:00:00 2001 From: Rhys Lees <43909932+RhysLees@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:16:09 +0200 Subject: [PATCH] WIP --- README.md | 8 +- .../AddApplicationProperties.php | 56 ++++++++++++ .../DeleteApplicationProperties.php | 63 ++++++++++++++ .../UpdateApplicationProperties.php | 56 ++++++++++++ .../GetApplicationPropertiesResponse.php | 2 +- .../ApplicationPropertiesTest.php | 87 +++++++++++++++++++ .../GetApplicationPropertiesTest.php | 26 ------ 7 files changed, 267 insertions(+), 31 deletions(-) create mode 100644 src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php create mode 100644 src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php create mode 100644 src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php create mode 100644 tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php delete mode 100644 tests/Feature/Requests/Documents/ApplicationProperties/GetApplicationPropertiesTest.php diff --git a/README.md b/README.md index 6a28f06..492e811 100644 --- a/README.md +++ b/README.md @@ -132,10 +132,10 @@ then optimize the processes that power the core of your business. | Documents/DocumentsTrashBin | Get Documents | ✅ | | | Documents/DocumentsTrashBin | Delete Documents | ✅ | | | Documents/DocumentsTrashBin | Restore Documents | ✅ | | -| Documents/ApplicationProperties | Get Application Properties | ❓ | - | -| Documents/ApplicationProperties | Add Application Properties | ❌ | - | -| Documents/ApplicationProperties | Delete Application Properties | ❌ | - | -| Documents/ApplicationProperties | Update Application Properties | ❌ | - | +| Documents/ApplicationProperties | Get Application Properties | ✅ | - | +| Documents/ApplicationProperties | Add Application Properties | ✅ | - | +| Documents/ApplicationProperties | Delete Application Properties | ✅ | - | +| Documents/ApplicationProperties | Update Application Properties | ✅ | - | | Documents/Sections | Get All Sections from a Document | ✅ | - | | Documents/Sections | Get a Specific Section | ✅ | - | | Documents/Sections | Delete Section | ✅ | - | diff --git a/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php new file mode 100644 index 0000000..2d05564 --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php @@ -0,0 +1,56 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + return [ + 'DocumentApplicationProperty' => $this->properties, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php new file mode 100644 index 0000000..8225369 --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php @@ -0,0 +1,63 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + $props = collect($this->propertyNames)->map(function ($name) { + return [ + 'Name' => $name, + 'Value' => null, + ]; + }); + + return [ + 'DocumentApplicationProperty' => $props, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php new file mode 100644 index 0000000..fc33e59 --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php @@ -0,0 +1,56 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + return [ + 'DocumentApplicationProperty' => $this->properties, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php b/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php index de30c79..35d9184 100644 --- a/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php +++ b/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php @@ -14,6 +14,6 @@ public static function fromResponse(Response $response): mixed EnsureValidResponse::from($response); - return $response->throw()->json(); + return collect($response->throw()->json('DocumentApplicationProperty')); } } diff --git a/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php b/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php new file mode 100644 index 0000000..3bfc5cd --- /dev/null +++ b/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php @@ -0,0 +1,87 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $addProperties = $this->connector->send(new AddApplicationProperties( + $fileCabinetId, + $document->id, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value', + ], + [ + 'Name' => 'Key2', + 'Value' => 'Key2 Value', + ], + ], + ))->dto(); + + expect($addProperties)->toBeInstanceOf(Collection::class) + ->and($addProperties->count())->toBe(2) + ->and($addProperties->first()['Name'])->toBe('Key1') + ->and($addProperties->first()['Value'])->toBe('Key1 Value') + ->and($addProperties->last()['Name'])->toBe('Key2') + ->and($addProperties->last()['Value'])->toBe('Key2 Value'); + + $updateProperties = $this->connector->send(new UpdateApplicationProperties( + $fileCabinetId, + $document->id, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value Updated', + ], + ], + ))->dto()->sortBy('Name'); + + expect($updateProperties)->toBeInstanceOf(Collection::class) + ->and($updateProperties->count())->toBe(2) + ->and($updateProperties->first()['Name'])->toBe('Key1') + ->and($updateProperties->first()['Value'])->toBe('Key1 Value Updated') + ->and($updateProperties->last()['Name'])->toBe('Key2') + ->and($updateProperties->last()['Value'])->toBe('Key2 Value'); + + $deleteProperties = $this->connector->send(new DeleteApplicationProperties( + $fileCabinetId, + $document->id, + [ + 'Key1', + ], + ))->dto(); + + expect($deleteProperties)->toBeInstanceOf(Collection::class) + ->and($deleteProperties->count())->toBe(1) + ->and($deleteProperties->first()['Name'])->toBe('Key2') + ->and($deleteProperties->first()['Value'])->toBe('Key2 Value'); + + $properties = $this->connector->send(new GetApplicationProperties( + $fileCabinetId, + $document->id, + ))->dto(); + + expect($properties)->toBeInstanceOf(Collection::class) + ->and($properties->count())->toBe(1) + ->and($properties->first()['Name'])->toBe('Key2') + ->and($properties->first()['Value'])->toBe('Key2 Value'); + + Event::assertDispatched(DocuWareResponseLog::class); +})->only(); diff --git a/tests/Feature/Requests/Documents/ApplicationProperties/GetApplicationPropertiesTest.php b/tests/Feature/Requests/Documents/ApplicationProperties/GetApplicationPropertiesTest.php deleted file mode 100644 index 0192d88..0000000 --- a/tests/Feature/Requests/Documents/ApplicationProperties/GetApplicationPropertiesTest.php +++ /dev/null @@ -1,26 +0,0 @@ -connector->send(new CreateDataRecord( - $fileCabinetId, - '::fake-file-content::', - 'example.txt' - ))->dto(); - - $properties = $this->connector->send(new GetApplicationProperties( - $fileCabinetId, - $document->id, - ))->dto(); - - Event::assertDispatched(DocuWareResponseLog::class); - -});