Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dyfero committed Mar 4, 2024
1 parent d778b62 commit 74bb20f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Http/Requests/Admin/ProductCreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function rules(): array
'recursive' => ['required_if:type,' . ProductType::SUBSCRIPTION, 'boolean'],
// trial
'has_trial' => ['required_if:type,' . ProductType::SUBSCRIPTION, 'boolean'],
'trial_period' => ['required_if:type,' . ProductType::SUBSCRIPTION. ',has_trial,true', Rule::in(PeriodEnum::getValues())],
'trial_duration' => ['required_if:type,' . ProductType::SUBSCRIPTION. ',has_trial,true', 'integer', 'gt:0'],
'trial_period' => ['nullable', 'required_if:has_trial,true', Rule::in(PeriodEnum::getValues())],
'trial_duration' => ['nullable', 'required_if:has_trial,true', 'integer', 'gt:0'],
];
}
}
4 changes: 2 additions & 2 deletions src/Http/Requests/Admin/ProductUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function rules(): array
'recursive' => ['required_if:type,' . ProductType::SUBSCRIPTION, 'boolean'],
// trial
'has_trial' => ['required_if:type,' . ProductType::SUBSCRIPTION, 'boolean'],
'trial_period' => ['required_if:type,' . ProductType::SUBSCRIPTION . ',has_trial,true', Rule::in(PeriodEnum::getValues())],
'trial_duration' => ['required_if:type,' . ProductType::SUBSCRIPTION . ',has_trial,true', 'integer', 'gt:0'],
'trial_period' => ['nullable', 'required_if:has_trial,true', Rule::in(PeriodEnum::getValues())],
'trial_duration' => ['nullable', 'required_if:has_trial,true', 'integer', 'gt:0'],
];
}

Expand Down
10 changes: 5 additions & 5 deletions tests/API/AdminProductApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function test_create_product_subscription_type_validation(array $data, ar
$productable = ExampleProductable::factory()->create();

$productData = Product::factory()
->subscription()
->subscriptionWithTrial()
->make([
...$data,
'productables' => [[
Expand Down Expand Up @@ -480,10 +480,10 @@ public function test_update_product_subscription_type_validation(array $data, ar
/** @var ExampleProductable $productable */
$productable = ExampleProductable::factory()->create();
/** @var Product $product */
$product = Product::factory()->subscription()->create();
$product = Product::factory()->subscriptionWithTrial()->create();

$productData = Product::factory()
->subscription()
->subscriptionWithTrial()
->make([
...$data,
'productables' => [[
Expand Down Expand Up @@ -827,9 +827,9 @@ private function invalidSubscriptionDataProvider(): array
['data' => ['subscription_duration' => null], 'errors' => ['subscription_duration' => 'The subscription duration field is required when type is subscription.']],
['data' => ['recursive' => null], 'errors' => ['recursive' => 'The recursive field is required when type is subscription.']],
['data' => ['has_trial' => null], 'errors' => ['has_trial' => 'The has trial field is required when type is subscription.']],
['data' => ['trial_period' => null], 'errors' => ['trial_period' => 'The trial period field is required when type is subscription.']],
['data' => ['trial_period' => null], 'errors' => ['trial_period' => 'The trial period field is required when has trial is true.']],
['data' => ['trial_period' => 'invalid_period'], 'errors' => ['trial_period' => 'The selected trial period is invalid.']],
['data' => ['trial_duration' => null], 'errors' => ['trial_duration' => 'The trial duration field is required when type is subscription.']],
['data' => ['trial_duration' => null], 'errors' => ['trial_duration' => 'The trial duration field is required when has trial is true.']],
['data' => ['trial_duration' => -1], 'errors' => ['trial_duration' => 'The trial duration must be greater than 0.']],
['data' => ['trial_duration' => 0], 'errors' => ['trial_duration' => 'The trial duration must be greater than 0.']],
];
Expand Down

0 comments on commit 74bb20f

Please sign in to comment.