Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnvelopeTemplateDocumentAssignments endpoint #254

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Extend `AccountBilling` resource with identify limits
- Add `AccountBilling.userContactLimit`
- Add `IdentifyScenarioVersion.restrictedCountries`
- Add `EnvelopeTemplateDocumentAssignments` endpoint

## [2.4.0] - 2024-05-14
### Added
Expand Down
37 changes: 37 additions & 0 deletions src/Endpoint/EnvelopeTemplateDocumentAssignmentEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\Resource\BaseResource;

/**
* @extends ResourceEndpoint<BaseResource>
*/
final class EnvelopeTemplateDocumentAssignmentEndpoint extends ResourceEndpoint
{
public function __construct(EnvelopeTemplateDocumentsEndpoint $parent)
{
parent::__construct($parent, '/assignments');
}

/**
* @return array<string, array<string, string>>
*/
public function get(): array
{
/** @var array<string, array<string, string>> $result */
$result = $this->parseResponse($this->getRequest());

return $result;
}

/**
* @param array<string, array<string, string>> $body
*/
public function set(array $body): void
{
$this->putRequest('', ['json' => $body]);
}
}
5 changes: 5 additions & 0 deletions src/Endpoint/EnvelopeTemplateDocumentsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public function replaceFile(EnvelopeTemplateDocument|string $document, array $bo
$this->postRequest('/{document}/replace-file', ['document' => $document, 'json' => $body]),
);
}

public function assignments(): EnvelopeTemplateDocumentAssignmentEndpoint
{
return new EnvelopeTemplateDocumentAssignmentEndpoint($this);
}
}
39 changes: 39 additions & 0 deletions tests/Endpoint/EnvelopeTemplateDocumentAssignmentsEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

/**
* @covers \DigitalCz\DigiSign\Endpoint\EnvelopeTemplateDocumentAssignmentEndpoint
*/
final class EnvelopeTemplateDocumentAssignmentsEndpointTest extends EndpointTestCase
{
public function testGet(): void
{
self::endpoint()->get();
self::assertLastRequest('GET', '/api/envelope-templates/bar/documents/assignments');
}

public function testSet(): void
{
self::endpoint()->set([
'8a071df9-aa9a-4607-9bc4-1c148ae6d384' => [
'd73be485-731a-45b4-9566-489643952db0' => 'show',
'ed37dd22-cd24-47c6-ab22-f014bcd30c9d' => 'hide',
],
]);

self::assertLastRequest('PUT', '/api/envelope-templates/bar/documents/assignments', [
'8a071df9-aa9a-4607-9bc4-1c148ae6d384' => [
'd73be485-731a-45b4-9566-489643952db0' => 'show',
'ed37dd22-cd24-47c6-ab22-f014bcd30c9d' => 'hide',
],
]);
}

protected static function endpoint(): EnvelopeTemplateDocumentAssignmentEndpoint
{
return self::dgs()->envelopeTemplates()->documents('bar')->assignments();
}
}
8 changes: 8 additions & 0 deletions tests/Endpoint/EnvelopeTemplateDocumentsEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
*/
class EnvelopeTemplateDocumentsEndpointTest extends EndpointTestCase
{
public function testChildren(): void
{
self::assertDefaultEndpointPath(
self::endpoint()->assignments(),
'/api/envelope-templates/bar/documents/assignments',
);
}

public function testCRUD(): void
{
self::assertCrudRequests(self::endpoint(), '/api/envelope-templates/bar/documents');
Expand Down