1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Invoice List Tests

This commit is contained in:
David Bomba 2019-04-17 10:58:23 +10:00
parent 82d573d759
commit 2de838cb62
4 changed files with 79 additions and 19 deletions

View File

@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Builder;
/**
* ProductFilters
*/
class Invoiceilters extends QueryFilters
class InvoiceFilters extends QueryFilters
{

View File

@ -3,12 +3,14 @@
namespace App\Http\Controllers;
use App\Factory\InvoiceFactory;
use App\Filters\InvoiceFilters;
use App\Http\Requests\Invoice\CreateInvoiceRequest;
use App\Http\Requests\Invoice\EditInvoiceRequest;
use App\Http\Requests\Invoice\ShowInvoiceRequest;
use App\Http\Requests\Invoice\StoreInvoiceRequest;
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
use App\Models\Invoice;
use App\Repositories\InvoiceRepository;
use App\Transformers\InvoiceTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
@ -37,7 +39,7 @@ class InvoiceController extends BaseController
* ClientController constructor.
* @param ClientRepository $clientRepo
*/
public function __construct(InvoiceRespository $invoice_repo)
public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct();
@ -48,7 +50,7 @@ class InvoiceController extends BaseController
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
*/
public function index()
public function index(InvoiceFilters $filters)
{
$invoices = Invoice::filter($filters);
@ -103,7 +105,7 @@ class InvoiceController extends BaseController
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit(EditInvoiceRequest, Invoice $invoice)
public function edit(EditInvoiceRequest $request, Invoice $invoice)
{
return $this->itemResponse($invoice);

View File

@ -1,8 +1,9 @@
<?php
namespace App\Transformers;
use App\Models\Client;
use App\Models\Invoice;
use App\Utils\Traits\MakesHash;
/**
* @SWG\Definition(definition="Invoice", required={"invoice_number"}, @SWG\Xml(name="Invoice"))
@ -67,20 +68,14 @@ class InvoiceTransformer extends EntityTransformer
// 'documents',
];
public function __construct($client = null)
{
parent::__construct($serializer);
$this->client = $client;
}
/*
public function includeInvoiceItems(Invoice $invoice)
{
$transformer = new InvoiceItemTransformer($this->serializer);
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEM);
}
/*
public function includeInvitations(Invoice $invoice)
{
$transformer = new InvitationTransformer($this->account, $this->serializer);
@ -126,7 +121,7 @@ class InvoiceTransformer extends EntityTransformer
'id' => $this->encodePrimaryKey($invoice->id),
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
'client_id' => (int) ($this->client ? $this->client->public_id : $invoice->client->public_id),
'client_id' => (int) $invoice->client_id,
'invoice_status_id' => (int) ($invoice->invoice_status_id ?: 1),
'updated_at' => $invoice->updated_at,
'archived_at' => $invoice->deleted_at,
@ -164,10 +159,7 @@ class InvoiceTransformer extends EntityTransformer
'quote_invoice_id' => (int) ($invoice->quote_invoice_id ?: 0),
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
'is_quote' => (bool) $invoice->isType(INVOICE_TYPE_QUOTE), // Temp to support mobile app
'is_public' => (bool) $invoice->is_public,
'filename' => $invoice->getFileName(),
'options' => $invoice->options ?: '',
'backup' => $invoice->backup ?: '',
];
}

View File

@ -2,6 +2,8 @@
namespace Tests\Feature;
use App\Models\Account;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\RefreshDatabase;
@ -25,6 +27,70 @@ class InvoiceTest extends TestCase
Model::reguard();
}
public function testInvoiceList()
{
$data = [
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->unique()->safeEmail,
'password' => 'ALongAndBrilliantPassword123',
'_token' => csrf_token(),
'privacy_policy' => 1,
'terms_of_service' => 1
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
])->post('/api/v1/signup', $data);
$acc = $response->json();
$account = Account::find($acc['id']);
$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);
$this->assertNotNull($user->tokens->first()->company);
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();
factory(\App\Models\Invoice::class, 5)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token,
])->get('/api/v1/invoices');
$response->assertStatus(200);
}
}