1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/tests/Feature/Scheduler/ScheduleEntityTest.php

121 lines
2.9 KiB
PHP
Raw Normal View History

2023-03-18 10:18:11 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Feature\Scheduler;
use App\Models\RecurringInvoice;
2023-11-26 08:41:42 +01:00
use App\Utils\Traits\MakesHash;
2023-03-18 10:18:11 +01:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Routing\Middleware\ThrottleRequests;
2023-11-26 08:41:42 +01:00
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
use Tests\TestCase;
2023-03-18 10:18:11 +01:00
/**
* @test
2023-03-21 22:00:20 +01:00
* @covers App\Services\Scheduler\EmailRecord
2023-03-18 10:18:11 +01:00
*/
class ScheduleEntityTest extends TestCase
{
use MakesHash;
use MockAccountData;
2023-12-16 07:34:32 +01:00
2023-12-16 06:30:33 +01:00
public $faker;
2023-03-18 10:18:11 +01:00
protected function setUp(): void
{
parent::setUp();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testSchedulerStore()
{
$data = [
'name' => 'A test entity email scheduler',
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
'next_run' => now()->format('Y-m-d'),
2023-03-21 22:00:20 +01:00
'template' => 'email_record',
2023-03-18 10:18:11 +01:00
'parameters' => [
'entity' => 'invoice',
'entity_id' => $this->invoice->hashed_id,
],
];
$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 testSchedulerStore2()
{
$data = [
'name' => 'A test entity email scheduler',
'frequency_id' => 0,
'next_run' => now()->format('Y-m-d'),
2023-03-21 22:00:20 +01:00
'template' => 'email_record',
2023-03-18 10:18:11 +01:00
'parameters' => [
'entity' => 'invoice',
'entity_id' => $this->invoice->hashed_id,
],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/task_schedulers', $data);
$response->assertStatus(200);
}
2023-11-26 08:41:42 +01:00
public function testSchedulerStore4()
2023-03-18 10:18:11 +01:00
{
$data = [
'name' => 'A test entity email scheduler',
'next_run' => now()->format('Y-m-d'),
2023-03-21 22:00:20 +01:00
'template' => 'email_record',
2023-03-18 10:18:11 +01:00
'parameters' => [
'entity' => 'invoice',
'entity_id' => $this->invoice->hashed_id,
],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/task_schedulers', $data);
$response->assertStatus(200);
}
2023-11-26 08:41:42 +01:00
}