Skip to content

Commit

Permalink
Add expire tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner committed Jul 30, 2024
1 parent 9811b15 commit 32e6a50
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/GraphQL/Mutations/RemoveTokensBeamPackMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
];
}
Expand All @@ -71,6 +71,7 @@ protected function rules(array $args = []): array
{
return [
'code' => [
'bail',
'filled',
'max:1024',
new BeamExists(),
Expand Down
49 changes: 49 additions & 0 deletions tests/Feature/GraphQL/Mutations/ExpireSingleUseCodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/Feature/Traits/CreateBeamData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Enjin\Platform\Beam\Enums\BeamType;
use Illuminate\Support\Collection;

trait CreateBeamData
{
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 32e6a50

Please sign in to comment.