Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Apr 27, 2024
1 parent 67d8bd9 commit 4debd2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/GraphQL/Mutations/DispatchMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ protected function rulesWithValidation(array $args): array
new MaxBigInt(Hex::MAX_UINT32),
new RuleSetExists(),
],
'dispatch' => [
new CanDispatch(),
],
'dispatch.query' => [
'filled',
new ValidMutation(),
new CanDispatch($args['ruleSetId']),
],
];
}
Expand Down
8 changes: 2 additions & 6 deletions src/Rules/CanDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ class CanDispatch implements DataAwareRule, ValidationRule
{
use HasDataAwareRule;

public function __construct(protected int $ruleSetId)
{
}

/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$fuelTank = FuelTank::where('public_key', SS58Address::getPublicKey($value))
$fuelTank = FuelTank::where('public_key', SS58Address::getPublicKey(Arr::get($this->data, 'tankId')))
->with('owner')
->first();

Expand All @@ -47,7 +43,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}

$caller = SS58Address::getPublicKey(Arr::get($this->data, 'signingAccount') ?? Account::daemonPublicKey());
$ruleSetRules = $fuelTank->dispatchRules()->where('rule_set_id', $this->ruleSetId)->get();
$ruleSetRules = $fuelTank->dispatchRules()->where('rule_set_id', Arr::get($this->data, 'ruleSetId'))->get();

if ($ruleSetRules->isEmpty()) {
$fail(__('enjin-platform-fuel-tanks::validation.dispatch_rule_not_found'))->translate();
Expand Down
7 changes: 5 additions & 2 deletions tests/Feature/GraphQL/Mutations/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ public function test_it_will_fail_with_invalid_parameter_rule_set_id(): void
array_merge($data, ['ruleSetId' => Hex::MAX_UINT128]),
true
);
$this->assertEquals(
ray($response['error']);

$this->assertArraySubset(
['ruleSetId' => ['The rule set id is too large, the maximum value it can be is 4294967295.']],
$response['error']
);

$response = $this->graphql(
$this->method,
array_merge($data, ['ruleSetId' => fake()->numberBetween(5000, 10000)]),
Expand Down Expand Up @@ -244,6 +245,8 @@ public function test_it_will_fail_with_invalid_parameter_dispatch(): void

Arr::set($invalidData, 'dispatch.variables', null);
$response = $this->graphql($this->method, $invalidData, true);
ray($response);

$this->assertEquals(
"There's an error with the query. Please check the query and try again.",
$response['error']
Expand Down

0 comments on commit 4debd2e

Please sign in to comment.