Skip to content

Commit 0180afc

Browse files
authored
[PLA-2125] Refactor expandRanges function (#313)
1 parent 24df8a9 commit 0180afc

File tree

9 files changed

+20
-22
lines changed

9 files changed

+20
-22
lines changed

src/GraphQL/Types/Scalars/Traits/HasIntegerRanges.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ public function isIntegerRange(string $value): bool
1111
return preg_match('/-?[0-9]+(\.\.)-?[0-9]+/', $value);
1212
}
1313

14-
public static function expandRanges($values): array
14+
public function expandRanges($values): array
1515
{
16-
$self = new self();
17-
1816
return collect($values)
1917
->flatten()
20-
->map(function ($range) use ($self) {
21-
if ($self->isIntegerRange($range)) {
18+
->map(function ($range) {
19+
if ($this->isIntegerRange($range)) {
2220
[$start, $end] = explode('..', $range, 2);
2321
$range = [];
2422
while ($start <= $end) {

tests/Feature/Controllers/QrControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function test_it_can_get_a_qr_image(): void
1414

1515
$this->assertTrue($response->isOk());
1616
$this->assertSame(
17-
'ccac6fd60b4f2e46cb00563d01b2e94ef8760e6a',
17+
'1af55b28efc63dbf39aa6f892c832b1113483dc5',
1818
sha1($response->content())
1919
);
2020
}

tests/Feature/GraphQL/Mutations/ApproveTokenTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,20 @@ public function test_it_can_approve_a_token_with_ss58_signing_account(): void
237237
$newOwner = Wallet::factory()->create([
238238
'public_key' => $signingAccount = app(Generator::class)->public_key(),
239239
]);
240-
Token::factory([
240+
$newToken = Token::factory([
241241
'collection_id' => $collection = Collection::factory(['owner_wallet_id' => $newOwner])->create(),
242242
])->create();
243243
$encodedData = TransactionSerializer::encode($this->method, ApproveTokenMutation::getEncodableParams(
244244
collectionId: $collectionId = $collection->collection_chain_id,
245-
tokenId: $this->tokenIdEncoder->encode(),
245+
tokenId: $this->tokenIdEncoder->encode($newToken->token_chain_id),
246246
operator: $operator = app(Generator::class)->public_key(),
247247
amount: $amount = $this->tokenAccount->balance,
248248
currentAmount: $currentAmount = $this->tokenAccount->balance,
249249
));
250250

251251
$response = $this->graphql($this->method, [
252252
'collectionId' => $collectionId,
253-
'tokenId' => $this->tokenIdEncoder->toEncodable(),
253+
'tokenId' => $this->tokenIdEncoder->toEncodable($newToken->token_chain_id),
254254
'amount' => $amount,
255255
'currentAmount' => $currentAmount,
256256
'operator' => SS58Address::encode($operator),
@@ -283,12 +283,12 @@ public function test_it_can_approve_a_token_with_public_key_signing_account(): v
283283
$newOwner = Wallet::factory()->create([
284284
'public_key' => $signingAccount = app(Generator::class)->public_key(),
285285
]);
286-
Token::factory([
286+
$newToken = Token::factory([
287287
'collection_id' => $collection = Collection::factory(['owner_wallet_id' => $newOwner])->create(),
288288
])->create();
289289
$encodedData = TransactionSerializer::encode($this->method, ApproveTokenMutation::getEncodableParams(
290290
collectionId: $collectionId = $collection->collection_chain_id,
291-
tokenId: $this->tokenIdEncoder->encode(),
291+
tokenId: $this->tokenIdEncoder->encode($newToken->token_chain_id),
292292
operator: $operator = app(Generator::class)->public_key(),
293293
amount: $amount = $this->tokenAccount->balance,
294294
currentAmount: $currentAmount = $this->tokenAccount->balance,
@@ -297,7 +297,7 @@ public function test_it_can_approve_a_token_with_public_key_signing_account(): v
297297

298298
$response = $this->graphql($this->method, [
299299
'collectionId' => $collectionId,
300-
'tokenId' => $this->tokenIdEncoder->toEncodable(),
300+
'tokenId' => $this->tokenIdEncoder->toEncodable($newToken->token_chain_id),
301301
'amount' => $amount,
302302
'currentAmount' => $currentAmount,
303303
'operator' => SS58Address::encode($operator),

tests/Feature/GraphQL/Mutations/BatchTransferTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function test_it_can_skip_validation(): void
7373
'managed' => false,
7474
])->create();
7575

76-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
76+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
7777

7878
$collection = Collection::factory([
7979
'collection_chain_id' => Hex::MAX_UINT128,
@@ -321,7 +321,7 @@ public function test_it_can_batch_simple_single_transfer_with_public_key_signing
321321
'public_key' => $signingAccount = app(Generator::class)->public_key,
322322
])->create();
323323

324-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
324+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
325325

326326
$collection = Collection::factory([
327327
'collection_chain_id' => Hex::MAX_UINT128,
@@ -858,7 +858,7 @@ public function test_it_can_batch_transfer_with_signing_wallet_simple_transfer()
858858
'managed' => true,
859859
])->create();
860860

861-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
861+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
862862

863863
$collection = Collection::factory([
864864
'collection_chain_id' => Hex::MAX_UINT128,
@@ -932,7 +932,7 @@ public function test_it_can_batch_transfer_with_signing_wallet_operator_transfer
932932
'managed' => true,
933933
])->create();
934934

935-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
935+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
936936
$collection = Collection::factory([
937937
'collection_chain_id' => Hex::MAX_UINT128,
938938
'owner_wallet_id' => $signingWallet,
@@ -1062,7 +1062,7 @@ public function test_it_can_batch_transfer_with_null_signing_wallet(): void
10621062

10631063
public function test_it_can_batch_transfer_with_big_int_collection_id(): void
10641064
{
1065-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
1065+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
10661066
$collection = Collection::factory([
10671067
'collection_chain_id' => Hex::MAX_UINT128,
10681068
'owner_wallet_id' => $this->wallet,

tests/Feature/GraphQL/Mutations/OperatorTransferTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public function test_it_can_transfer_token_with_recipient_that_doesnt_exists():
620620

621621
public function test_it_can_transfer_token_with_bigint_collection_id(): void
622622
{
623-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
623+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
624624
$collection = Collection::factory([
625625
'collection_chain_id' => Hex::MAX_UINT128,
626626
'owner_wallet_id' => $this->wallet,

tests/Feature/GraphQL/Mutations/RemoveAllAttributesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function test_it_can_remove_an_attribute_with_no_token_id(): void
339339

340340
public function test_it_can_remove_an_attribute_with_bigint_collection_id(): void
341341
{
342-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
342+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
343343
$collection = Collection::factory(['collection_chain_id' => Hex::MAX_UINT128, 'owner_wallet_id' => $this->wallet->id])->create();
344344
$collectionId = $collection->collection_chain_id;
345345

tests/Feature/GraphQL/Mutations/RemoveTokenAttributeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function test_it_can_remove_an_attribute_with_public_key_signing_account(
276276

277277
public function test_it_can_remove_an_attribute_with_bigint_collection_id(): void
278278
{
279-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
279+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
280280
$collection = Collection::factory([
281281
'collection_chain_id' => Hex::MAX_UINT128,
282282
'owner_wallet_id' => $this->wallet,

tests/Feature/GraphQL/Mutations/SimpleTransferTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ public function test_it_can_transfer_token_with_recipient_that_doesnt_exists():
542542

543543
public function test_it_can_transfer_token_with_bigint_collection_id(): void
544544
{
545-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
545+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
546546
$collection = Collection::factory([
547547
'collection_chain_id' => Hex::MAX_UINT128,
548548
'owner_wallet_id' => $this->wallet,

tests/Feature/GraphQL/Mutations/UnapproveTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function test_it_can_unapprove_a_token_with_signing_account_public_key():
284284

285285
public function test_it_can_unapprove_a_token_with_big_int_collection_id(): void
286286
{
287-
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => random_int(1, 1000)]);
287+
Collection::where('collection_chain_id', Hex::MAX_UINT128)->update(['collection_chain_id' => fake()->numberBetween()]);
288288
$collection = Collection::factory([
289289
'collection_chain_id' => Hex::MAX_UINT128,
290290
'owner_wallet_id' => $this->wallet,

0 commit comments

Comments
 (0)