Skip to content

Commit

Permalink
[PLA-2033] Add validation rule to listingData (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio authored Oct 16, 2024
1 parent 9a9033f commit a8e68e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/GraphQL/Mutations/CreateListingMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static function getEncodableParams(...$params): array
$amount = Arr::get($params, 'amount', 0);
$price = Arr::get($params, 'price', 0);
$salt = Arr::get($params, 'salt', Str::random(10));
$listingType = ListingType::getEnumCase(Arr::get($params, 'listingData.type'));
$listingType = is_string($type = Arr::get($params, 'listingData.type')) ? ListingType::getEnumCase($type) : $type;
$listingData = match ($listingType) {
ListingType::AUCTION => new ListingDataParams(
ListingType::AUCTION,
Expand Down Expand Up @@ -210,6 +210,7 @@ protected function rulesCommon(array $args): array
new MaxBigInt(),
],
'salt' => ['bail', 'filled', 'max:255'],
'listingData' => ['required'],
'listingData.type' => ['required'],
];
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/GraphQL/Mutations/CreateListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ public function test_it_can_create_listing_with_signing_account(): void
);
}

public function test_it_will_fail_without_listing_data(): void
{
$data = $this->generateParams();
unset($data['listingData']);

$response = $this->graphql(
$this->method,
$data,
true
);

$this->assertEquals(
'Variable "$listingData" of required type "ListingDataInput!" was not provided.',
$response['error']
);
}

public function test_it_will_fail_with_invalid_parameter_make_asset_id(): void
{
$data = $this->generateParams();
Expand Down

0 comments on commit a8e68e0

Please sign in to comment.