Skip to content

Commit

Permalink
add some tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Aug 2, 2023
1 parent 95e6608 commit 624476d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 90 deletions.
73 changes: 73 additions & 0 deletions tests/Feature/GraphQL/Mutations/FreezeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Enjin\Platform\Enums\Global\TransactionState;
use Enjin\Platform\Enums\Substrate\FreezeStateType;
use Enjin\Platform\Enums\Substrate\FreezeType;
use Enjin\Platform\Events\Global\TransactionCreated;
use Enjin\Platform\Models\Collection;
Expand Down Expand Up @@ -286,6 +287,45 @@ public function test_can_freeze_a_token(): void
Event::assertDispatched(TransactionCreated::class);
}

public function test_can_freeze_a_token_with_freeze_state(): void
{
$encodedData = $this->codec->encode()->freeze(
$collectionId = $this->collection->collection_chain_id,
new FreezeTypeParams(
type: $freezeType = FreezeType::TOKEN,
token: $this->tokenIdEncoder->encode(),
freezeState: $freezeState = FreezeStateType::TEMPORARY,
),
);

$response = $this->graphql($this->method, [
'freezeType' => $freezeType->name,
'collectionId' => $collectionId,
'tokenId' => $this->tokenIdEncoder->toEncodable(),
'freezeState' => $freezeState->name,
]);

$this->assertArraySubset([
'method' => $this->method,
'state' => TransactionState::PENDING->name,
'encodedData' => $encodedData,
'wallet' => [
'account' => [
'publicKey' => $this->defaultAccount,
],
],
], $response);

$this->assertDatabaseHas('transactions', [
'id' => $response['id'],
'method' => $this->method,
'state' => TransactionState::PENDING->name,
'encoded_data' => $encodedData,
]);

Event::assertDispatched(TransactionCreated::class);
}

public function test_can_freeze_a_big_int_token(): void
{
$collection = Collection::factory()->create();
Expand Down Expand Up @@ -500,6 +540,39 @@ public function test_it_will_fail_with_invalid_token_id(): void
Event::assertNotDispatched(TransactionCreated::class);
}

public function test_it_will_fail_with_invalid_freeze_state(): void
{
$response = $this->graphql($this->method, [
'freezeType' => FreezeType::TOKEN->name,
'collectionId' => $this->collection->collection_chain_id,
'tokenId' => $this->tokenIdEncoder->toEncodable('invalid'),
'freezeState' => 'invalid',
], true);

$this->assertStringContainsString(
'value "invalid" at "tokenId.integer"; Cannot represent following value as uint256: "invalid"',
$response['error']
);

Event::assertNotDispatched(TransactionCreated::class);
}

public function test_it_will_fail_with_freeze_state_in_other_type(): void
{
$response = $this->graphql($this->method, [
'freezeType' => FreezeType::COLLECTION->name,
'collectionId' => $this->collection->collection_chain_id,
'freezeState' => FreezeStateType::TEMPORARY->name,
], true);

$this->assertArraySubset(
['freezeState' => ['The freeze state field is prohibited.']],
$response['error']
);

Event::assertNotDispatched(TransactionCreated::class);
}

public function test_it_will_fail_with_token_id_non_existent(): void
{
Token::where('token_chain_id', '=', $tokenId = fake()->numberBetween())?->delete();
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/GraphQL/Resources/Freeze.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mutation Freeze(
$freezeType: FreezeType!
$collectionId: BigInt!
$tokenId: EncodableTokenIdInput
$freezeState: FreezeStateType
$collectionAccount: String
$tokenAccount: String
$skipValidation: Boolean
Expand All @@ -10,6 +11,7 @@ mutation Freeze(
freezeType: $freezeType
collectionId: $collectionId
tokenId: $tokenId
freezeState: $freezeState
collectionAccount: $collectionAccount
tokenAccount: $tokenAccount
skipValidation: $skipValidation
Expand Down
Loading

0 comments on commit 624476d

Please sign in to comment.