2022-01-06 03:31:44 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
2022-06-08 06:25:44 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2022-01-06 03:31:44 +01:00
|
|
|
*/
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Controllers\InvoiceController
|
|
|
|
*/
|
|
|
|
class ClientDeletedInvoiceCreationTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientedDeletedAttemptingToCreateInvoice()
|
|
|
|
{
|
|
|
|
/* Test fire new invoice */
|
|
|
|
$data = [
|
|
|
|
'client_id' => $this->client->hashed_id,
|
|
|
|
'number' => 'dude',
|
|
|
|
];
|
|
|
|
|
2022-01-06 04:53:03 +01:00
|
|
|
$this->withHeaders([
|
2022-01-06 03:31:44 +01:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/invoices/', $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$this->client->is_deleted = true;
|
|
|
|
$this->client->save();
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'client_id' => $this->client->hashed_id,
|
|
|
|
'number' => 'dude2',
|
|
|
|
];
|
|
|
|
|
2022-01-06 04:53:03 +01:00
|
|
|
$this->withHeaders([
|
2022-01-06 03:31:44 +01:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/invoices/', $data)
|
|
|
|
->assertStatus(302);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|