From c8a6cee0268594f14899deea1b5ea673fb85fb18 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 20 Feb 2023 15:30:09 +1100 Subject: [PATCH] Validation for custom date ranges --- .../TaskScheduler/StoreSchedulerRequest.php | 5 ++-- tests/Feature/Scheduler/SchedulerTest.php | 27 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php index e98b942831..e319c7825d 100644 --- a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php @@ -40,8 +40,9 @@ class StoreSchedulerRequest extends Request 'template' => 'bail|required|string', 'parameters' => 'bail|array', 'parameters.clients' => ['bail','sometimes', 'array', new ValidClientIds()], - 'parameters.start_date' => ['bail', 'sometimes', 'date'], - 'parameters.end_date' => ['bail', 'sometimes', 'date', 'after_or_equal:parameters.start_date'], + 'parameters.date_date' => 'bail, sometimes, string, in:last7_days,last30_days,last365_days,this_month,last_month,this_quarter,last_quarter,this_year,last_year,custom', + 'parameters.start_date' => ['bail', 'sometimes', 'date', 'required_if:parameters.date_rate,custom'], + 'parameters.end_date' => ['bail', 'sometimes', 'date', 'required_if:parameters.date_rate,custom', 'after_or_equal:parameters.start_date'], ]; return $rules; diff --git a/tests/Feature/Scheduler/SchedulerTest.php b/tests/Feature/Scheduler/SchedulerTest.php index ba6440cce1..055206f4c0 100644 --- a/tests/Feature/Scheduler/SchedulerTest.php +++ b/tests/Feature/Scheduler/SchedulerTest.php @@ -129,8 +129,6 @@ class SchedulerTest extends TestCase $response->assertStatus(422); - - $data = [ 'name' => 'A test statement scheduler', 'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY, @@ -154,6 +152,31 @@ class SchedulerTest extends TestCase $response->assertStatus(422); + + + $data = [ + 'name' => 'A test statement scheduler', + 'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY, + 'next_run' => now()->format('Y-m-d'), + 'template' => 'client_statement', + 'parameters' => [ + 'date_range' => EmailStatement::CUSTOM_RANGE, + 'show_payments_table' => true, + 'show_aging_table' => true, + 'status' => 'paid', + 'clients' => [], + 'start_date' => '', + 'end_date' => '' + ], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/task_schedulers', $data); + + $response->assertStatus(422); + } public function testClientCountResolution()