-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
267 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties; | ||
|
||
use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse; | ||
use Illuminate\Support\Facades\Cache; | ||
use Saloon\CachePlugin\Contracts\Cacheable; | ||
use Saloon\CachePlugin\Drivers\LaravelCacheDriver; | ||
use Saloon\CachePlugin\Traits\HasCaching; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class AddApplicationProperties extends Request implements Cacheable, HasBody | ||
{ | ||
use HasCaching; | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected readonly string $fileCabinetId, | ||
protected readonly string $documentId, | ||
protected readonly array $properties, | ||
) { | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/FileCabinets/'.$this->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); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties; | ||
|
||
use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse; | ||
use Illuminate\Support\Facades\Cache; | ||
use Saloon\CachePlugin\Contracts\Cacheable; | ||
use Saloon\CachePlugin\Drivers\LaravelCacheDriver; | ||
use Saloon\CachePlugin\Traits\HasCaching; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class DeleteApplicationProperties extends Request implements Cacheable, HasBody | ||
{ | ||
use HasCaching; | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected readonly string $fileCabinetId, | ||
protected readonly string $documentId, | ||
protected readonly array $propertyNames, | ||
) { | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/FileCabinets/'.$this->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); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace CodebarAg\DocuWare\Requests\Documents\ApplicationProperties; | ||
|
||
use CodebarAg\DocuWare\Responses\Documents\ApplicationProperties\GetApplicationPropertiesResponse; | ||
use Illuminate\Support\Facades\Cache; | ||
use Saloon\CachePlugin\Contracts\Cacheable; | ||
use Saloon\CachePlugin\Drivers\LaravelCacheDriver; | ||
use Saloon\CachePlugin\Traits\HasCaching; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class UpdateApplicationProperties extends Request implements Cacheable, HasBody | ||
{ | ||
use HasCaching; | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected readonly string $fileCabinetId, | ||
protected readonly string $documentId, | ||
protected readonly array $properties, | ||
) { | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/FileCabinets/'.$this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
use CodebarAg\DocuWare\Events\DocuWareResponseLog; | ||
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\AddApplicationProperties; | ||
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\DeleteApplicationProperties; | ||
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\GetApplicationProperties; | ||
use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\UpdateApplicationProperties; | ||
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Event; | ||
|
||
it('can add get update delete application properties to a document', function () { | ||
Event::fake(); | ||
|
||
$fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); | ||
|
||
$document = $this->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(); |
26 changes: 0 additions & 26 deletions
26
tests/Feature/Requests/Documents/ApplicationProperties/GetApplicationPropertiesTest.php
This file was deleted.
Oops, something went wrong.