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

Change Create BatchSendingItem endpoint from POST to PUT #267

Merged
merged 2 commits into from
Sep 24, 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
22 changes: 18 additions & 4 deletions src/Endpoint/BatchSendingItemsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@

namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\DeleteEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\GetEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\ListEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\UpdateEndpointTrait;
use DigitalCz\DigiSign\Resource\BatchSending;
use DigitalCz\DigiSign\Resource\BatchSendingItem;

/**
* @extends ResourceEndpoint<BatchSendingItem>
* @method BatchSendingItem get(string $id)
* @method BatchSendingItem create(array $body)
* @method BatchSendingItem update(string $id, array $body)
* @method BatchSendingItem delete(string $id)
*/
final class BatchSendingItemsEndpoint extends ResourceEndpoint
{
/** @use CRUDEndpointTrait<BatchSendingItem> */
use CRUDEndpointTrait;
/** @use ListEndpointTrait<BatchSendingItem> */
use ListEndpointTrait;
use GetEndpointTrait;
use UpdateEndpointTrait;
use DeleteEndpointTrait;

public function __construct(BatchSendingsEndpoint $parent, BatchSending|string $batchSending)
{
Expand All @@ -36,4 +42,12 @@ public function import(array $body): void
{
$this->postRequest('/import', ['json' => $body]);
}

/**
* @param mixed[] $body
*/
public function create(array $body): BatchSendingItem
{
return $this->makeResource($this->putRequest('', ['json' => $body]));
}
}
4 changes: 2 additions & 2 deletions src/Resource/BatchSendingItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class BatchSendingItem extends BaseResource
/** @var array<BatchSendingItemRecipientRaw> */
public array $recipients;

/** @var array<Violation>|null */
public ?array $violations;
/** @var array<Violation> */
public array $violations;
}
29 changes: 27 additions & 2 deletions tests/Endpoint/BatchSendingItemsEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,34 @@ public function testImport(): void
self::assertLastRequest('POST', "/api/batch-sendings/bar/items/import", ['file' => 'bar']);
}

public function testCRUD(): void
public function testList(): void
{
self::assertCrudRequests(self::endpoint(), '/api/batch-sendings/bar/items');
self::endpoint()->list(['foo' => 'bar']);
self::assertLastRequest('GET', '/api/batch-sendings/bar/items?foo=bar');
}

public function testGet(): void
{
self::endpoint()->get('foo');
self::assertLastRequest('GET', '/api/batch-sendings/bar/items/foo');
}

public function testCreate(): void
{
self::endpoint()->create(['foo' => 'bar']);
self::assertLastRequest('PUT', '/api/batch-sendings/bar/items', ['foo' => 'bar']);
}

public function testUpdate(): void
{
self::endpoint()->update('foo', ['foo' => 'bar']);
self::assertLastRequest('PUT', '/api/batch-sendings/bar/items/foo', ['foo' => 'bar']);
}

public function testDelete(): void
{
self::endpoint()->delete('foo');
self::assertLastRequest('DELETE', '/api/batch-sendings/bar/items/foo');
}

protected static function endpoint(): BatchSendingItemsEndpoint
Expand Down