2019-05-05 02:49:01 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-05-05 02:49:01 +02:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\RecurringQuote;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2020-02-26 04:26:07 +01:00
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
2019-05-05 02:49:01 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-05-19 00:22:18 +02:00
|
|
|
use Tests\MockAccountData;
|
2019-05-05 02:49:01 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Controllers\RecurringQuoteController
|
|
|
|
*/
|
|
|
|
class RecurringQuoteTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
2020-05-19 00:22:18 +02:00
|
|
|
use MockAccountData;
|
2019-05-05 02:49:01 +02:00
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
2020-02-26 04:26:07 +01:00
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->makeTestData();
|
2019-05-05 02:49:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecurringQuoteList()
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
RecurringQuote::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
2019-05-05 02:49:01 +02:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-19 00:22:18 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-05-05 02:49:01 +02:00
|
|
|
])->get('/api/v1/recurring_quotes');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecurringQuoteRESTEndPoints()
|
|
|
|
{
|
2020-10-01 13:34:05 +02:00
|
|
|
RecurringQuote::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
2019-05-05 02:49:01 +02:00
|
|
|
|
2020-05-19 00:22:18 +02:00
|
|
|
$RecurringQuote = RecurringQuote::where('user_id', $this->user->id)->first();
|
2019-05-05 02:49:01 +02:00
|
|
|
$RecurringQuote->save();
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-19 00:22:18 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-05-05 02:49:01 +02:00
|
|
|
])->get('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id));
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-19 00:22:18 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-05-05 02:49:01 +02:00
|
|
|
])->get('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id).'/edit');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$RecurringQuote_update = [
|
2019-07-05 00:36:40 +02:00
|
|
|
'status_id' => RecurringQuote::STATUS_DRAFT,
|
|
|
|
'client_id' => $RecurringQuote->client_id,
|
2019-05-05 02:49:01 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertNotNull($RecurringQuote);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-19 00:22:18 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-05-05 02:49:01 +02:00
|
|
|
])->put('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id), $RecurringQuote_update)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-19 00:22:18 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-05-05 02:49:01 +02:00
|
|
|
])->delete('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id));
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
}
|