Skip to content

Commit

Permalink
Add multiple Identifications endpoints (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
spajxo authored Feb 27, 2024
1 parent 4304023 commit 40f57c2
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [Unreleased]
### Added
- Add multiple Identifications endpoints
- Add `IdentificationInspection.claims`
- Add `Identificaiton.cancelledAt`
- Add `Identificaiton.discardedAt`
Expand Down
39 changes: 39 additions & 0 deletions src/Endpoint/IdentificationDocumentEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\Resource\BaseResource;
use DigitalCz\DigiSign\Resource\Identification;
use DigitalCz\DigiSign\Stream\FileResponse;

/**
* @extends ResourceEndpoint<BaseResource>
*/
final class IdentificationDocumentEndpoint extends ResourceEndpoint
{
public function __construct(
IdentificationsEndpoint $parent,
Identification|string $identification,
string $resourcePath,
) {
parent::__construct($parent, "/{id}$resourcePath", resourceOptions: ['id' => $identification]);
}

/**
* @param array<string, mixed> $query
*/
public function front(array $query = []): FileResponse
{
return $this->stream(self::METHOD_GET, '/front', ['query' => $query]);
}

/**
* @param array<string, mixed> $query
*/
public function back(array $query = []): FileResponse
{
return $this->stream(self::METHOD_GET, '/back', ['query' => $query]);
}
}
49 changes: 43 additions & 6 deletions src/Endpoint/IdentificationsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\DigiSign;
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\GetEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\ListEndpointTrait;
use DigitalCz\DigiSign\Resource\Identification;
use DigitalCz\DigiSign\Stream\FileResponse;

/**
* @extends ResourceEndpoint<Identification>
Expand All @@ -16,8 +18,9 @@
*/
final class IdentificationsEndpoint extends ResourceEndpoint
{
/** @use CRUDEndpointTrait<Identification> */
use CRUDEndpointTrait;
/** @use ListEndpointTrait<Identification> */
use ListEndpointTrait;
use GetEndpointTrait;

public function __construct(DigiSign $parent)
{
Expand All @@ -30,18 +33,26 @@ public function approve(Identification|string $id): Identification
}

/**
* @param mixed[] $body
* @param array<string, mixed> $query
*/
public function deny(Identification|string $id, array $body = []): Identification
public function bankStatement(Identification|string $id, array $query = []): FileResponse
{
return $this->makeResource($this->postRequest('/{id}/deny', ['id' => $id, 'json' => $body]));
return $this->stream(self::METHOD_GET, '/{id}/bank-statement', ['id' => $id, 'query' => $query]);
}

public function cancel(Identification|string $id): Identification
{
return $this->makeResource($this->postRequest('/{id}/cancel', ['id' => $id]));
}

/**
* @param mixed[] $body
*/
public function deny(Identification|string $id, array $body = []): Identification
{
return $this->makeResource($this->postRequest('/{id}/deny', ['id' => $id, 'json' => $body]));
}

/**
* @param mixed[] $body
*/
Expand All @@ -50,6 +61,32 @@ public function discard(Identification|string $id, array $body = []): Identifica
return $this->makeResource($this->postRequest('/{id}/discard', ['id' => $id, 'json' => $body]));
}

public function primaryDocument(Identification|string $id): IdentificationDocumentEndpoint
{
return new IdentificationDocumentEndpoint($this, $id, '/primary-document');
}

/**
* @param array<string, mixed> $query
*/
public function protocol(Identification|string $id, array $query = []): FileResponse
{
return $this->stream(self::METHOD_GET, '/{id}/protocol', ['id' => $id, 'query' => $query]);
}

public function secondaryDocument(Identification|string $id): IdentificationDocumentEndpoint
{
return new IdentificationDocumentEndpoint($this, $id, '/secondary-document');
}

/**
* @param array<string, mixed> $query
*/
public function selfie(Identification|string $id, array $query = []): FileResponse
{
return $this->stream(self::METHOD_GET, '/{id}/selfie', ['id' => $id, 'query' => $query]);
}

public function restore(Identification|string $id): Identification
{
return $this->makeResource($this->postRequest('/{id}/restore', ['id' => $id]));
Expand Down
28 changes: 28 additions & 0 deletions tests/Endpoint/IdentificationDocumentEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

/**
* @covers \DigitalCz\DigiSign\Endpoint\IdentificationDocumentEndpoint
*/
class IdentificationDocumentEndpointTest extends EndpointTestCase
{
public function testFront(): void
{
self::endpoint()->front(['foo' => 'bar']);
self::assertLastRequest('GET', '/api/identifications/foo/primary-document/front?foo=bar');
}

public function testBack(): void
{
self::endpoint()->back(['foo' => 'bar']);
self::assertLastRequest('GET', '/api/identifications/foo/primary-document/back?foo=bar');
}

protected static function endpoint(): IdentificationDocumentEndpoint
{
return self::dgs()->identifications()->primaryDocument('foo');
}
}
41 changes: 39 additions & 2 deletions tests/Endpoint/IdentificationsEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@
*/
class IdentificationsEndpointTest extends EndpointTestCase
{
public function testCRUD(): void
public function testChildren(): void
{
self::assertCrudRequests(self::endpoint(), '/api/identifications');
self::assertDefaultEndpointPath(
self::endpoint()->primaryDocument('foo'),
'/api/identifications/foo/primary-document',
);
self::assertDefaultEndpointPath(
self::endpoint()->secondaryDocument('foo'),
'/api/identifications/foo/secondary-document',
);
}

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

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

public function testApprove(): void
Expand Down Expand Up @@ -56,6 +75,24 @@ public function testRestore(): void
self::assertLastRequest('POST', '/api/identifications/foo/restore');
}

public function testBankStatement(): void
{
self::endpoint()->bankStatement('foo', ['foo' => 'bar']);
self::assertLastRequest('GET', '/api/identifications/foo/bank-statement?foo=bar');
}

public function testProtocol(): void
{
self::endpoint()->protocol('foo', ['foo' => 'bar']);
self::assertLastRequest('GET', '/api/identifications/foo/protocol?foo=bar');
}

public function testSelfie(): void
{
self::endpoint()->selfie('foo', ['foo' => 'bar']);
self::assertLastRequest('GET', '/api/identifications/foo/selfie?foo=bar');
}

protected static function endpoint(): IdentificationsEndpoint
{
return self::dgs()->identifications();
Expand Down

0 comments on commit 40f57c2

Please sign in to comment.