2019-04-16 07:28:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2019-04-24 12:01:40 +02:00
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
2019-10-24 06:46:24 +02:00
|
|
|
use App\Factory\InvoiceFactory;
|
2019-04-17 02:58:23 +02:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2019-04-17 08:20:32 +02:00
|
|
|
use App\Models\Invoice;
|
2019-04-16 07:28:30 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-04-24 12:01:40 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-04-16 07:28:30 +02:00
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
2019-04-24 12:01:40 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-04-16 07:28:30 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2019-10-10 12:43:50 +02:00
|
|
|
use Tests\MockAccountData;
|
2019-04-16 07:28:30 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2019-04-20 01:02:49 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Controllers\InvoiceController
|
2019-04-17 08:20:32 +02:00
|
|
|
*/
|
|
|
|
|
2019-04-16 07:28:30 +02:00
|
|
|
class InvoiceTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use MakesHash;
|
2019-04-24 12:01:40 +02:00
|
|
|
use DatabaseTransactions;
|
2019-10-10 12:43:50 +02:00
|
|
|
use MockAccountData;
|
2019-04-16 07:28:30 +02:00
|
|
|
|
2019-04-24 12:01:40 +02:00
|
|
|
public function setUp() :void
|
2019-04-16 07:28:30 +02:00
|
|
|
{
|
2019-04-17 02:58:23 +02:00
|
|
|
|
2019-04-16 07:28:30 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
2019-10-10 12:43:50 +02:00
|
|
|
$this->makeTestData();
|
2019-04-17 02:58:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceList()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'first_name' => $this->faker->firstName,
|
|
|
|
'last_name' => $this->faker->lastName,
|
2019-09-04 01:16:23 +02:00
|
|
|
'name' => $this->faker->company,
|
|
|
|
'email' => $this->faker->unique()->safeEmail,
|
2019-04-17 02:58:23 +02:00
|
|
|
'password' => 'ALongAndBrilliantPassword123',
|
|
|
|
'_token' => csrf_token(),
|
|
|
|
'privacy_policy' => 1,
|
|
|
|
'terms_of_service' => 1
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2019-11-04 01:22:59 +01:00
|
|
|
])->post('/api/v1/signup?include=account', $data);
|
2019-04-17 02:58:23 +02:00
|
|
|
|
|
|
|
$acc = $response->json();
|
|
|
|
|
2019-09-16 23:42:08 +02:00
|
|
|
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
2019-04-17 02:58:23 +02:00
|
|
|
|
|
|
|
$company_token = $account->default_company->tokens()->first();
|
|
|
|
$token = $company_token->token;
|
|
|
|
$company = $company_token->company;
|
|
|
|
|
|
|
|
$user = $company_token->user;
|
|
|
|
|
|
|
|
$this->assertNotNull($company_token);
|
|
|
|
$this->assertNotNull($token);
|
|
|
|
$this->assertNotNull($user);
|
|
|
|
$this->assertNotNull($company);
|
2019-06-25 07:14:28 +02:00
|
|
|
//$this->assertNotNull($user->token->company);
|
2019-04-17 02:58:23 +02:00
|
|
|
|
|
|
|
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
$client = Client::all()->first();
|
|
|
|
|
2019-04-17 08:20:32 +02:00
|
|
|
factory(\App\Models\Invoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
2019-04-17 02:58:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $token,
|
|
|
|
])->get('/api/v1/invoices');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2019-04-16 07:28:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 08:20:32 +02:00
|
|
|
public function testInvoiceRESTEndPoints()
|
|
|
|
{
|
2019-04-24 12:01:40 +02:00
|
|
|
|
2019-04-17 08:20:32 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2019-10-10 12:43:50 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id));
|
2019-04-17 08:20:32 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2019-10-10 12:43:50 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id).'/edit');
|
2019-04-17 08:20:32 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$invoice_update = [
|
2019-10-10 12:43:50 +02:00
|
|
|
'tax_name1' => 'dippy',
|
2019-04-17 08:20:32 +02:00
|
|
|
];
|
|
|
|
|
2019-10-10 12:43:50 +02:00
|
|
|
$this->assertNotNull($this->invoice);
|
2019-10-07 11:39:22 +02:00
|
|
|
|
2019-04-17 08:20:32 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2019-10-10 12:43:50 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $invoice_update)
|
2019-04-17 08:20:32 +02:00
|
|
|
->assertStatus(200);
|
|
|
|
|
2019-10-24 06:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostNewInvoice()
|
|
|
|
{
|
|
|
|
$invoice = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'invoice_number' => 'dfdfd',
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
|
|
|
'po_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/invoices/', $invoice)
|
|
|
|
->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteInvoice()
|
|
|
|
{
|
|
|
|
$response = $this->withHeaders([
|
2019-04-17 08:20:32 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2019-10-10 12:43:50 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->delete('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id));
|
2019-04-17 08:20:32 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2019-09-11 05:46:23 +02:00
|
|
|
}
|