1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/tests/Feature/CreditTest.php
David Bomba d05bd7d2c1
Test for Gmail (#3706)
* Fixes for null values in custom values

* Refactor mailing

* Working on send emails from GMail API

* Fixes for tests

* Test for GMail
2020-05-16 12:04:24 +10:00

129 lines
3.7 KiB
PHP

<?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()
{
factory(Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
'client_id' => $c->id,
'company_id' => $this->company->id,
'is_primary' => 1
]);
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $this->user->id,
'client_id' => $c->id,
'company_id' => $this->company->id
]);
});
$client = Client::all()->first();
factory(Credit::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->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()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->delete('/api/v1/credits/'.$this->encodePrimaryKey($this->credit->id));
$response->assertStatus(200);
}
}