akaunting/tests/Feature/Sales/InvoicesTest.php

116 lines
3.0 KiB
PHP
Raw Normal View History

2018-10-30 15:55:41 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace Tests\Feature\Sales;
2018-10-30 15:55:41 +03:00
2019-12-31 15:49:09 +03:00
use App\Jobs\Sale\CreateInvoice;
2020-01-13 15:16:35 +03:00
use App\Models\Sale\Invoice;
2018-10-30 15:55:41 +03:00
use Tests\Feature\FeatureTestCase;
class InvoicesTest extends FeatureTestCase
{
public function testItShouldSeeInvoiceListPage()
{
$this->loginAs()
2019-11-16 10:21:14 +03:00
->get(route('invoices.index'))
2018-10-30 15:55:41 +03:00
->assertStatus(200)
->assertSeeText(trans_choice('general.invoices', 2));
}
public function testItShouldSeeInvoiceCreatePage()
{
$this->loginAs()
2019-11-16 10:21:14 +03:00
->get(route('invoices.create'))
2018-10-30 15:55:41 +03:00
->assertStatus(200)
2019-11-17 15:06:00 +03:00
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.invoices', 1)]));
2018-10-30 15:55:41 +03:00
}
public function testItShouldCreateInvoice()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
2018-10-30 15:55:41 +03:00
$this->loginAs()
2020-07-25 17:22:50 +03:00
->post(route('invoices.store'), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertDatabaseHas('invoices', [
'invoice_number' => $request['invoice_number'],
]);
2018-10-30 15:55:41 +03:00
}
public function testItShouldCreateInvoiceWithRecurring()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest(true);
2018-10-30 15:55:41 +03:00
$this->loginAs()
2020-07-25 17:22:50 +03:00
->post(route('invoices.store'), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertDatabaseHas('invoices', [
'invoice_number' => $request['invoice_number'],
]);
2018-10-30 15:55:41 +03:00
}
2019-11-16 10:21:14 +03:00
public function testItShouldSeeInvoiceUpdatePage()
2018-10-30 15:55:41 +03:00
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$invoice = $this->dispatch(new CreateInvoice($request));
2018-10-30 15:55:41 +03:00
2019-11-16 10:21:14 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->get(route('invoices.edit', $invoice->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200)
->assertSee($invoice->contact_email);
}
2018-10-30 15:55:41 +03:00
2019-11-16 10:21:14 +03:00
public function testItShouldUpdateInvoice()
{
2020-01-13 15:16:35 +03:00
$request = $this->getRequest();
2019-11-17 15:06:00 +03:00
$invoice = $this->dispatch(new CreateInvoice($request));
2019-11-16 10:21:14 +03:00
2020-03-19 19:00:18 +03:00
$request['contact_email'] = $this->faker->safeEmail;
2018-10-30 15:55:41 +03:00
$this->loginAs()
2019-11-16 10:21:14 +03:00
->patch(route('invoices.update', $invoice->id), $request)
2020-01-13 17:20:28 +03:00
->assertStatus(200)
2020-03-19 19:00:18 +03:00
->assertSee($request['contact_email']);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertDatabaseHas('invoices', [
'invoice_number' => $request['invoice_number'],
'contact_email' => $request['contact_email'],
]);
2018-10-30 15:55:41 +03:00
}
public function testItShouldDeleteInvoice()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$invoice = $this->dispatch(new CreateInvoice($request));
2018-10-30 15:55:41 +03:00
$this->loginAs()
2019-11-16 10:21:14 +03:00
->delete(route('invoices.destroy', $invoice->id))
->assertStatus(200);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
$this->assertSoftDeleted('invoices', [
'invoice_number' => $request['invoice_number'],
]);
2018-10-30 15:55:41 +03:00
}
2020-01-13 15:16:35 +03:00
public function getRequest($recurring = false)
2018-10-30 15:55:41 +03:00
{
2020-10-14 17:07:59 +03:00
$factory = Invoice::factory();
2020-01-13 15:16:35 +03:00
2020-10-14 17:07:59 +03:00
$recurring ? $factory->items()->recurring() : $factory->items();
2020-01-13 15:16:35 +03:00
return $factory->raw();
2018-10-30 15:55:41 +03:00
}
2019-04-02 18:51:06 +03:00
}