diff --git a/src/GraphQL/Mutations/RemoveTokensBeamPackMutation.php b/src/GraphQL/Mutations/RemoveTokensBeamPackMutation.php index de4febd..f3d7206 100644 --- a/src/GraphQL/Mutations/RemoveTokensBeamPackMutation.php +++ b/src/GraphQL/Mutations/RemoveTokensBeamPackMutation.php @@ -45,7 +45,7 @@ public function args(): array ], 'packs' => [ 'type' => GraphQL::type('[RemoveBeamPack!]!'), - 'description' => __('enjin-platform-beam::mutation.remove_beam_pack.description'), + 'description' => __('enjin-platform-beam::input_type.remove_beam_pack.description'), ], ]; } @@ -71,6 +71,7 @@ protected function rules(array $args = []): array { return [ 'code' => [ + 'bail', 'filled', 'max:1024', new BeamExists(), diff --git a/tests/Feature/GraphQL/Mutations/ExpireSingleUseCodesTest.php b/tests/Feature/GraphQL/Mutations/ExpireSingleUseCodesTest.php index 613ce83..743aab5 100644 --- a/tests/Feature/GraphQL/Mutations/ExpireSingleUseCodesTest.php +++ b/tests/Feature/GraphQL/Mutations/ExpireSingleUseCodesTest.php @@ -6,6 +6,7 @@ use Enjin\Platform\Beam\Tests\Feature\GraphQL\TestCaseGraphQL; use Enjin\Platform\Beam\Tests\Feature\Traits\CreateBeamData; use Enjin\Platform\Beam\Tests\Feature\Traits\SeedBeamData; +use Faker\Generator; use Illuminate\Support\Arr; class ExpireSingleUseCodesTest extends TestCaseGraphQL @@ -42,6 +43,54 @@ public function test_it_can_expire_single_use_codes(): void $this->assertTrue($response); } + public function test_it_can_expire_single_use_codes_beam_pack(): void + { + $this->truncateBeamTables(); + + $code = $this->graphql('CreateBeamPack', $this->generateBeamPackData( + BeamType::MINT_ON_DEMAND, + 1, + [], + [['flag' => 'SINGLE_USE']], + )); + $this->assertNotEmpty($code); + + $singleUseCodes = $this->graphql('GetSingleUseCodes', ['code' => $code]); + $this->assertNotEmpty($singleUseCodes['totalCount']); + + $response = $this->graphql($this->method, [ + 'codes' => [Arr::get($singleUseCodes, 'edges.0.node.code')], + ]); + $this->assertTrue($response); + } + + public function test_it_cannot_claim_expire_single_use_codes_beam_pack(): void + { + $this->truncateBeamTables(); + + $code = $this->graphql('CreateBeamPack', $this->generateBeamPackData( + BeamType::MINT_ON_DEMAND, + 1, + [], + [['flag' => 'SINGLE_USE']], + )); + $this->assertNotEmpty($code); + + $singleUseCodes = $this->graphql('GetSingleUseCodes', ['code' => $code]); + $this->assertNotEmpty($singleUseCodes['totalCount']); + + $response = $this->graphql($this->method, [ + 'codes' => [Arr::get($singleUseCodes, 'edges.0.node.code')], + ]); + $this->assertTrue($response); + + $response = $this->graphql('ClaimBeam', [ + 'code' => Arr::get($singleUseCodes, 'edges.0.node.code'), + 'account' => app(Generator::class)->public_key() + ], true); + + } + /** * Test get single use beam with invalid claims. */ diff --git a/tests/Feature/Traits/CreateBeamData.php b/tests/Feature/Traits/CreateBeamData.php index acb5615..3ab9470 100644 --- a/tests/Feature/Traits/CreateBeamData.php +++ b/tests/Feature/Traits/CreateBeamData.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Enjin\Platform\Beam\Enums\BeamType; +use Illuminate\Support\Collection; trait CreateBeamData { @@ -31,4 +32,30 @@ protected function generateBeamData(BeamType $type = BeamType::TRANSFER_TOKEN, i ]], ]; } + + /** + * Generate beam pack data. + */ + protected function generateBeamPackData(BeamType $type = BeamType::TRANSFER_TOKEN, int $count = 1, array $attributes = [], array $flags = []): array + { + $data = [ + 'name' => fake()->name(), + 'description' => fake()->word(), + 'image' => fake()->url(), + 'start' => Carbon::now()->toDateTimeString(), + 'end' => Carbon::now()->addDays(random_int(1, 1000))->toDateTimeString(), + 'collectionId' => $this->collection->collection_chain_id, + 'flags' => $flags, + 'packs' => Collection::times($count, fn () => ['tokens' => [[ + 'type' => $type->name, + 'tokenIds' => $type == BeamType::TRANSFER_TOKEN + ? [(string) $this->token->token_chain_id] + : [(string) fake()->numberBetween(100, 1000), fake()->numberBetween(0, 10) . '..' . fake()->numberBetween(11, 20)], + 'tokenQuantityPerClaim' => random_int(1, $count), + 'attributes' => $attributes ?: null, + ]]])->all(), + ]; + + return $data; + } }