2020-07-22 01:54:39 +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
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-07-22 01:54:39 +02:00
|
|
|
namespace Tests\Integration;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use JsonSchema\Exception\ValidationException;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* @test
|
2020-07-22 01:54:39 +02:00
|
|
|
* @covers App\Http\ValidationRules\Invoice\LockedInvoiceRule
|
|
|
|
*/
|
|
|
|
class CheckLockedInvoiceValidationTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2020-07-22 01:54:39 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidationWorksForLockedInvoiceWhenOff()
|
|
|
|
{
|
|
|
|
$invoice_update = [
|
|
|
|
'po_number' => 'test',
|
|
|
|
];
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
try {
|
2020-07-22 01:54:39 +02:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $invoice_update)
|
2020-07-22 01:54:39 +02:00
|
|
|
->assertStatus(200);
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
\Log::error($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-16 21:06:19 +01:00
|
|
|
// public function testValidationFailsForLockedInvoiceWhenSent()
|
|
|
|
// {
|
|
|
|
// $this->company->settings->lock_invoices = 'when_sent';
|
|
|
|
// $this->company->save();
|
|
|
|
|
|
|
|
// $settings = $this->client->settings;
|
|
|
|
// $settings->lock_invoices = 'when_sent';
|
|
|
|
// $this->client->settings = $settings;
|
|
|
|
// $this->client->save();
|
|
|
|
|
|
|
|
// $this->invoice = $this->invoice->service()->markSent()->save();
|
|
|
|
|
|
|
|
// $invoice_update = [
|
|
|
|
// 'po_number' => 'test',
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// $this->assertEquals($this->invoice->status_id, \App\Models\Invoice::STATUS_SENT);
|
|
|
|
|
|
|
|
// try {
|
|
|
|
// $response = $this->withHeaders([
|
|
|
|
// 'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
// 'X-API-TOKEN' => $this->token,
|
|
|
|
// ])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $invoice_update);
|
|
|
|
// } catch (ValidationException $e) {
|
|
|
|
// $message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
|
|
|
|
// $this->assertNotNull($message);
|
|
|
|
// \Log::error($message);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ($response) {
|
|
|
|
// $response->assertStatus(302);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// public function testValidationFailsForLockedInvoiceWhenPaid()
|
|
|
|
// {
|
|
|
|
// $this->company->settings->lock_invoices = 'when_paid';
|
|
|
|
// $this->company->save();
|
|
|
|
|
|
|
|
// $settings = $this->client->settings;
|
|
|
|
// $settings->lock_invoices = 'when_paid';
|
|
|
|
// $this->client->settings = $settings;
|
|
|
|
// $this->client->save();
|
|
|
|
|
|
|
|
// $this->invoice = $this->invoice->service()->markPaid()->save();
|
|
|
|
|
|
|
|
// $invoice_update = [
|
|
|
|
// 'po_number' => 'test',
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// $this->assertEquals($this->invoice->status_id, \App\Models\Invoice::STATUS_PAID);
|
|
|
|
|
|
|
|
// try {
|
|
|
|
// $response = $this->withHeaders([
|
|
|
|
// 'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
// 'X-API-TOKEN' => $this->token,
|
|
|
|
// ])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $invoice_update);
|
|
|
|
// } catch (ValidationException $e) {
|
|
|
|
// $message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
|
|
|
|
// $this->assertNotNull($message);
|
|
|
|
// \Log::error($message);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ($response) {
|
|
|
|
// $response->assertStatus(302);
|
|
|
|
// }
|
|
|
|
// }
|
2020-07-22 01:54:39 +02:00
|
|
|
}
|