-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from esign/feature/categories
Added (sub)category/relationship Requests + tests
- Loading branch information
Showing
27 changed files
with
830 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\DataTransferObjects; | ||
|
||
use Spatie\LaravelData\Attributes\MapInputName; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\Mappers\SnakeCaseMapper; | ||
|
||
#[MapInputName(SnakeCaseMapper::class)] | ||
class ProductAttribute extends Data | ||
{ | ||
public function __construct( | ||
public readonly string $id, | ||
public readonly ?array $groups, | ||
public readonly ?string $label, | ||
public readonly ?string $name, | ||
public readonly ?string $typeClass | ||
) {} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\ProductCategory; | ||
use Esign\Plytix\DataTransferObjects\RelationshipInformation; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class AssignProductsToRelationshipRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected string $productId, | ||
protected string $relationshipId, | ||
protected array $payload | ||
) { } | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/products/' . $this->productId . "/relationships/" . $this->relationshipId; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $relationshipInfo) { | ||
return RelationshipInformation::from($relationshipInfo); | ||
}, $response->json('data')); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\Asset; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateAssetRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected array $payload) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/assets'; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $product) { | ||
return Asset::from($product); | ||
}, $response->json('data')); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\ProductAttribute; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateProductAttributeRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected array $payload) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/attributes/product'; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $attribute) { | ||
return ProductAttribute::from($attribute); | ||
}, $response->json('data')); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\ProductCategory; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateProductCategoryRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected array $payload) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/categories/product'; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $productCategory) { | ||
return ProductCategory::from($productCategory); | ||
}, $response->json('data')); | ||
} | ||
} |
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
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,39 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\ProductCategory; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateProductSubcategoryRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected string $categoryId, | ||
protected array $payload | ||
) { } | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/categories/product/' . $this->categoryId; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $productCategory) { | ||
return ProductCategory::from($productCategory); | ||
}, $response->json('data')); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\Relationship; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class CreateRelationshipRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected array $payload) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/relationships'; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $relationship) { | ||
return Relationship::from($relationship); | ||
}, $response->json('data')); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\Asset; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class LinkAssetToProductRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected string $productId, | ||
protected array $payload | ||
) { } | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/products/' . $this->productId . "/assets"; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $asset) { | ||
return Asset::from($asset); | ||
}, $response->json('data')); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Requests; | ||
|
||
use Esign\Plytix\DataTransferObjects\Product; | ||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class ModifySelectedProductAttributesRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::PATCH; | ||
|
||
public function __construct( | ||
protected string $productId, | ||
protected array $payload | ||
) { } | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/v1/products/' . $this->productId; | ||
} | ||
|
||
public function defaultBody(): array | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
return array_map(function (array $product) { | ||
return Product::from($product); | ||
}, $response->json('data')); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Feature/Requests/AssignProductsToRelationshipRequestTest.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,35 @@ | ||
<?php | ||
|
||
namespace Esign\Plytix\Tests\Feature\Requests; | ||
|
||
use Esign\Plytix\Plytix; | ||
use Esign\Plytix\Requests\AssignProductsToRelationshipRequest; | ||
use Esign\Plytix\Tests\Support\MockResponseFixture; | ||
use Esign\Plytix\Tests\TestCase; | ||
use Saloon\Http\Faking\MockClient; | ||
|
||
class AssignProductsToRelationshipRequestTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_assign_products_to_relationship() | ||
{ | ||
$plytix = new Plytix(); | ||
$mockClient = MockClient::global([ | ||
MockResponseFixture::make(fixtureName: 'token.json', status: 200), | ||
MockResponseFixture::make(fixtureName: 'assign-products-to-relationship.json', status: 201), | ||
]); | ||
|
||
$response = $plytix->send(new AssignProductsToRelationshipRequest('productid', 'relationshipid',[ | ||
'name' => '12345' | ||
])); | ||
|
||
$relationshipInformation = $response->dto()[0]; | ||
|
||
$mockClient->assertSent(AssignProductsToRelationshipRequest::class); | ||
$this->assertEquals('5d8a50b547397aea2a603079', $relationshipInformation->relationshipId); | ||
$this->assertEquals('contains', $relationshipInformation->relationshipLabel); | ||
$this->assertIsArray($relationshipInformation->relatedProducts); | ||
$this->assertCount(4, $relationshipInformation->relatedProducts); | ||
$this->assertEquals(9, $relationshipInformation->relatedProducts[1]->quantity); | ||
} | ||
} |
Oops, something went wrong.