1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/tests/Feature/RecurringInvoiceTest.php

142 lines
4.6 KiB
PHP
Raw Normal View History

2019-05-03 00:29:04 +02:00
<?php
namespace Tests\Feature;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\RecurringInvoice;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Routing\Middleware\ThrottleRequests;
2019-05-03 00:29:04 +02:00
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
2019-05-03 00:29:04 +02:00
use Tests\TestCase;
/**
* @test
* @covers App\Http\Controllers\RecurringInvoiceController
*/
class RecurringInvoiceTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
use MockAccountData;
2019-05-03 00:29:04 +02:00
public function setUp() :void
{
parent::setUp();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->withoutMiddleware(
ThrottleRequests::class
);
$this->makeTestData();
2019-05-03 00:29:04 +02:00
}
public function testRecurringInvoiceList()
{
factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
2019-05-03 00:29:04 +02:00
'client_id' => $c->id,
'company_id' => $this->company->id,
2019-05-03 00:29:04 +02:00
'is_primary' => 1
]);
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
2019-05-03 00:29:04 +02:00
'client_id' => $c->id,
'company_id' => $this->company->id
2019-05-03 00:29:04 +02:00
]);
});
2019-05-03 00:29:04 +02:00
$client = Client::all()->first();
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
2019-05-03 00:29:04 +02:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2019-05-03 00:29:04 +02:00
])->get('/api/v1/recurring_invoices');
$response->assertStatus(200);
}
public function testRecurringInvoiceRESTEndPoints()
{
factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
2019-05-03 00:29:04 +02:00
'client_id' => $c->id,
'company_id' => $this->company->id,
2019-05-03 00:29:04 +02:00
'is_primary' => 1
]);
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
2019-05-03 00:29:04 +02:00
'client_id' => $c->id,
'company_id' => $this->company->id
2019-05-03 00:29:04 +02:00
]);
});
$client = Client::all()->first();
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
2019-05-03 00:29:04 +02:00
$RecurringInvoice = RecurringInvoice::where('user_id', $this->user->id)->first();
2019-05-03 00:29:04 +02:00
$RecurringInvoice->save();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2019-05-03 00:29:04 +02:00
])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id));
$response->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2019-05-03 00:29:04 +02:00
])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id).'/edit');
$response->assertStatus(200);
$RecurringInvoice_update = [
2019-07-05 00:36:40 +02:00
'status_id' => RecurringInvoice::STATUS_DRAFT,
2020-07-01 06:37:05 +02:00
'client_id' => $this->encodePrimaryKey($RecurringInvoice->client_id),
2019-05-03 00:29:04 +02:00
];
$this->assertNotNull($RecurringInvoice);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2019-05-03 00:29:04 +02:00
])->put('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id), $RecurringInvoice_update)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
2019-05-03 00:29:04 +02:00
])->delete('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id));
$response->assertStatus(200);
}
}