2020-01-30 04:02:25 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-01-30 04:02:25 +01:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2020-10-01 12:49:47 +02:00
|
|
|
use App\Models\ClientContact;
|
2020-01-30 04:02:25 +01:00
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-09-06 11:38:10 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-01-30 04:02:25 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2020-09-06 11:38:10 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-01-30 04:02:25 +01:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class CreditTest 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 testCreditsList()
|
|
|
|
{
|
2020-10-01 12:49:47 +02:00
|
|
|
Client::factory()->count(3)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
|
|
|
ClientContact::factory()->create([
|
2020-05-14 13:33:29 +02:00
|
|
|
'user_id' => $this->user->id,
|
2020-01-30 04:02:25 +01:00
|
|
|
'client_id' => $c->id,
|
2020-05-14 13:33:29 +02:00
|
|
|
'company_id' => $this->company->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'is_primary' => 1,
|
2020-01-30 04:02:25 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
ClientContact::factory()->create([
|
2020-05-14 13:33:29 +02:00
|
|
|
'user_id' => $this->user->id,
|
2020-01-30 04:02:25 +01:00
|
|
|
'client_id' => $c->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $this->company->id,
|
2020-01-30 04:02:25 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$client = Client::all()->first();
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
Credit::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
2020-01-30 04:02:25 +01:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 13:33:29 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-01-30 04:02:25 +01:00
|
|
|
])->get('/api/v1/credits');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreditRESTEndPoints()
|
|
|
|
{
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-09-06 11:38:10 +02:00
|
|
|
])->get('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id));
|
2020-01-30 04:02:25 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-09-06 11:38:10 +02:00
|
|
|
])->get('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id).'/edit');
|
2020-01-30 04:02:25 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$credit_update = [
|
|
|
|
'tax_name1' => 'dippy',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertNotNull($this->credit);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2020-09-06 11:38:10 +02:00
|
|
|
])->put('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id), $credit_update)
|
2020-01-30 04:02:25 +01:00
|
|
|
->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostNewCredit()
|
|
|
|
{
|
|
|
|
$credit = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'number' => 'dfdfd',
|
|
|
|
'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,
|
|
|
|
'client_id' => $this->encodePrimaryKey($this->client->id),
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/credits/', $credit)
|
|
|
|
->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteCredit()
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = $this->withHeaders([
|
2020-01-30 04:02:25 +01:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->delete('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id));
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
}
|