From 83467443ef787afaaf37f920c483a2e470d7a893 Mon Sep 17 00:00:00 2001 From: Leonardo Custodio Date: Tue, 15 Oct 2024 10:42:54 -0300 Subject: [PATCH] Fixes listingData --- src/GraphQL/Mutations/CreateListingMutation.php | 3 ++- .../GraphQL/Mutations/CreateListingTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/Mutations/CreateListingMutation.php b/src/GraphQL/Mutations/CreateListingMutation.php index 440f798..40ae4cc 100644 --- a/src/GraphQL/Mutations/CreateListingMutation.php +++ b/src/GraphQL/Mutations/CreateListingMutation.php @@ -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, @@ -210,6 +210,7 @@ protected function rulesCommon(array $args): array new MaxBigInt(), ], 'salt' => ['bail', 'filled', 'max:255'], + 'listingData' => ['required'], 'listingData.type' => ['required'], ]; } diff --git a/tests/Feature/GraphQL/Mutations/CreateListingTest.php b/tests/Feature/GraphQL/Mutations/CreateListingTest.php index bcd6a01..fa270bd 100644 --- a/tests/Feature/GraphQL/Mutations/CreateListingTest.php +++ b/tests/Feature/GraphQL/Mutations/CreateListingTest.php @@ -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();