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

[Feature] Added list guest request #3

Merged
merged 2 commits into from
Mar 22, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This package is currently work in progress
- PHP 8.2
- Composer


## Installation
Add the package to your composer.json repositories array.
``` json
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/GuestResourceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

interface GuestResourceContract
{
public function list(): Response;

public function validateCode(string $code): Response;

public function get(string $code): Response;
Expand Down
25 changes: 25 additions & 0 deletions src/Requests/Guest/ListRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace AirLST\SdkPhp\Requests\Guest;

use Saloon\Enums\Method;
use Saloon\Http\Request;

class ListRequest extends Request
{
protected Method $method = Method::GET;

public function resolveEndpoint(): string
{
return '/';
}

protected function defaultQuery(): array
{
return [
'perPage' => 100,
];
}
}
8 changes: 7 additions & 1 deletion src/Resources/GuestResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use AirLST\SdkPhp\Contracts\GuestResourceContract;
use AirLST\SdkPhp\Requests\Guest\CreateRequest;
use AirLST\SdkPhp\Requests\Guest\GetRequest;
use AirLST\SdkPhp\Requests\Guest\ListRequest;
use AirLST\SdkPhp\Requests\Guest\UpdateRequest;
use AirLST\SdkPhp\Requests\Guest\ValidateCodeRequest;
use Saloon\Http\BaseResource;
use Saloon\Http\Response;
use AirLST\SdkPhp\Requests\Guest\ValidateCodeRequest;

class GuestResource extends BaseResource implements GuestResourceContract
{
Expand All @@ -19,6 +20,11 @@ public function validateCode(string $code): Response
return $this->connector->send(new ValidateCodeRequest($code));
}

public function list(): Response
{
return $this->connector->send(new ListRequest());
}

public function get(string $code): Response
{
return $this->connector->send(new GetRequest($code));
Expand Down
20 changes: 20 additions & 0 deletions tests/Requests/Guest/ListRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace AirLST\SdkPhp\Tests\Requests\Guest;

use AirLST\SdkPhp\Requests\Guest\ListRequest;
use AirLST\SdkPhp\Tests\TestCase;

class ListRequestTest extends TestCase
{
public function testList(): void
{
$mockClient = $this->mock(ListRequest::class);

$this->core->withMockClient($mockClient)->send(new ListRequest());

$mockClient->assertSent(ListRequest::class);
}
}
2 changes: 1 addition & 1 deletion tests/Resources/EventResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testList(): void

$resource = $this->resource($this->core->withMockClient($mockClient));
$result = $resource->list();

$mockClient->assertSent(
fn (Request $request, Response $response) => $result->body() === $response->body()
);
Expand Down
13 changes: 13 additions & 0 deletions tests/Resources/GuestResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AirLST\SdkPhp\CoreApi;
use AirLST\SdkPhp\Requests\Guest\CreateRequest;
use AirLST\SdkPhp\Requests\Guest\GetRequest;
use AirLST\SdkPhp\Requests\Guest\ListRequest;
use AirLST\SdkPhp\Requests\Guest\UpdateRequest;
use AirLST\SdkPhp\Requests\Guest\ValidateCodeRequest;
use AirLST\SdkPhp\Resources\GuestResource;
Expand All @@ -16,6 +17,18 @@

class GuestResourceTest extends TestCase
{
public function testList(): void
{
$mockClient = $this->mock(ListRequest::class, ['data' => ['guests' => []]]);

$resource = $this->resource($this->core->withMockClient($mockClient));
$result = $resource->list();

$mockClient->assertSent(
fn (Request $request, Response $response) => $request instanceof ListRequest && $result->body() === $response->body()
);
}

public function testValidateCode(): void
{
$mockClient = $this->mock(ValidateCodeRequest::class, ['data' => ['valid' => true]]);
Expand Down
Loading