mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Validate custom date ranges
This commit is contained in:
parent
4a462177ef
commit
70248be9ad
@ -40,6 +40,8 @@ class StoreSchedulerRequest extends Request
|
|||||||
'template' => 'bail|required|string',
|
'template' => 'bail|required|string',
|
||||||
'parameters' => 'bail|array',
|
'parameters' => 'bail|array',
|
||||||
'parameters.clients' => ['bail','sometimes', 'array', new ValidClientIds()],
|
'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'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
|
@ -54,6 +54,108 @@ class SchedulerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCustomDateRanges()
|
||||||
|
{
|
||||||
|
$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' => now()->format('Y-m-d'),
|
||||||
|
'end_date' => now()->addDays(4)->format('Y-m-d')
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/task_schedulers', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomDateRangesFails()
|
||||||
|
{
|
||||||
|
$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' => now()->format('Y-m-d'),
|
||||||
|
'end_date' => now()->subDays(4)->format('Y-m-d')
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/task_schedulers', $data);
|
||||||
|
|
||||||
|
$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' => now()->format('Y-m-d'),
|
||||||
|
'end_date' => null
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson('/api/v1/task_schedulers', $data);
|
||||||
|
|
||||||
|
$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' => null,
|
||||||
|
'end_date' => now()->format('Y-m-d')
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$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()
|
public function testClientCountResolution()
|
||||||
{
|
{
|
||||||
$c = Client::factory()->create([
|
$c = Client::factory()->create([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user