2020-01-30 04:02:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
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-05-14 11:08:49 +02:00
|
|
|
|
2020-05-16 04:04:24 +02:00
|
|
|
factory(Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
2020-01-30 04:02:25 +01:00
|
|
|
factory(\App\Models\ClientContact::class, 1)->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-01-30 04:02:25 +01:00
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class, 1)->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-01-30 04:02:25 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$client = Client::all()->first();
|
|
|
|
|
2020-05-14 13:33:29 +02:00
|
|
|
factory(Credit::class, 1)->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,
|
|
|
|
])->get('/api/v1/credits/' . $this->encodePrimaryKey($this->credit->id));
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/credits/' . $this->encodePrimaryKey($this->credit->id) . '/edit');
|
|
|
|
|
|
|
|
$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,
|
|
|
|
])->put('/api/v1/credits/' . $this->encodePrimaryKey($this->credit->id), $credit_update)
|
|
|
|
->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);
|
|
|
|
}
|
|
|
|
}
|