2022-05-29 05:22:37 +02: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
|
|
|
|
*/
|
|
|
|
|
2022-07-20 08:18:21 +02:00
|
|
|
namespace Tests\Feature;
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
use App\Models\PurchaseOrder;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2022-06-07 12:36:47 +02:00
|
|
|
use Illuminate\Support\Str;
|
2022-07-20 08:18:21 +02:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
class PurchaseOrderTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp(): void
|
2022-05-29 05:22:37 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
2023-02-09 03:30:39 +01:00
|
|
|
public function testPurchaseOrderBulkActions()
|
|
|
|
{
|
|
|
|
$i = $this->purchase_order->invitations->first();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => 'archive',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => 'restore',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => 'delete',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => 'restore',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
2023-02-09 03:51:03 +01:00
|
|
|
'action' => 'download',
|
2023-02-09 03:30:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[],
|
|
|
|
'action' => 'archive',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(302);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(302);
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' =>[$this->purchase_order->hashed_id],
|
|
|
|
'action' => 'molly',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post("/api/v1/purchase_orders/bulk", $data)
|
|
|
|
->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
2023-02-01 10:00:55 +01:00
|
|
|
public function testPurchaseOrderDownloadPDF()
|
|
|
|
{
|
|
|
|
$i = $this->purchase_order->invitations->first();
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get("/api/v1/purchase_order/{$i->key}/download");
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$this->assertTrue($response->headers->get('content-type') == 'application/pdf');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-19 00:23:42 +01:00
|
|
|
public function testPurchaseOrderGetWithClientStatus()
|
|
|
|
{
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/purchase_orders?client_status=sent'.$this->encodePrimaryKey($this->purchase_order->id));
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:27:17 +02:00
|
|
|
public function testPostNewPurchaseOrderPdf()
|
|
|
|
{
|
|
|
|
$purchase_order = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
2022-06-07 12:36:47 +02:00
|
|
|
'number' => Str::random(10),
|
|
|
|
'po_number' => Str::random(5),
|
|
|
|
'due_date' => '2022-01-01',
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'balance' => 100,
|
|
|
|
'amount' => 100,
|
2022-06-06 14:27:17 +02:00
|
|
|
'public_notes' => 'notes',
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'custom_value1' => 0,
|
|
|
|
'custom_value2' => 0,
|
|
|
|
'custom_value3' => 0,
|
|
|
|
'custom_value4' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'vendor_id' => $this->encodePrimaryKey($this->vendor->id),
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/purchase_orders/', $purchase_order)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$purchase_order = PurchaseOrder::find($this->decodePrimaryKey($arr['data']['id']));
|
|
|
|
|
|
|
|
$this->assertNotNull($purchase_order);
|
|
|
|
|
2022-06-07 12:36:47 +02:00
|
|
|
$x = $purchase_order->service()->markSent()->getPurchaseOrderPdf();
|
2022-06-06 14:27:17 +02:00
|
|
|
|
2022-06-07 12:36:47 +02:00
|
|
|
nlog($x);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-06-06 14:27:17 +02:00
|
|
|
|
2022-05-29 05:22:37 +02:00
|
|
|
public function testPurchaseOrderRest()
|
|
|
|
{
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->get('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id));
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->get('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id).'/edit');
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2022-06-05 05:57:57 +02:00
|
|
|
$purchase_order_update = [
|
2022-05-29 05:22:37 +02:00
|
|
|
'tax_name1' => 'dippy',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertNotNull($this->purchase_order);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $purchase_order_update)
|
2022-05-29 05:22:37 +02:00
|
|
|
->assertStatus(200);
|
|
|
|
}
|
2022-06-05 05:57:57 +02:00
|
|
|
|
2022-05-29 05:22:37 +02:00
|
|
|
public function testPostNewPurchaseOrder()
|
|
|
|
{
|
|
|
|
$purchase_order = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
|
|
|
'number' => '34343xx43',
|
|
|
|
'public_notes' => 'notes',
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'custom_value1' => 0,
|
|
|
|
'custom_value2' => 0,
|
|
|
|
'custom_value3' => 0,
|
|
|
|
'custom_value4' => 0,
|
|
|
|
'status' => 1,
|
2022-06-05 11:41:19 +02:00
|
|
|
'vendor_id' => $this->encodePrimaryKey($this->vendor->id),
|
2022-05-29 05:22:37 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/purchase_orders/', $purchase_order)
|
|
|
|
->assertStatus(200);
|
|
|
|
}
|
2022-06-05 05:57:57 +02:00
|
|
|
|
2022-05-29 05:22:37 +02:00
|
|
|
public function testPurchaseOrderDelete()
|
|
|
|
{
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->delete('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id));
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
2022-06-05 05:57:57 +02:00
|
|
|
|
2022-05-29 05:22:37 +02:00
|
|
|
public function testPurchaseOrderUpdate()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
|
|
|
'number' => '3434343',
|
|
|
|
'public_notes' => 'notes',
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'custom_value1' => 0,
|
|
|
|
'custom_value2' => 0,
|
|
|
|
'custom_value3' => 0,
|
|
|
|
'custom_value4' => 0,
|
|
|
|
'status' => 1,
|
2022-06-05 11:41:19 +02:00
|
|
|
'vendor_id' => $this->encodePrimaryKey($this->vendor->id),
|
2022-05-29 05:22:37 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $data);
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-21 11:57:17 +02:00
|
|
|
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $data);
|
2022-05-29 05:22:37 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/purchase_orders/', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
}
|