akaunting/tests/Feature/Sales/InvoicesTest.php

91 lines
2.4 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()
{
$this->loginAs()
2020-01-13 15:16:35 +03:00
->post(route('invoices.store'), $this->getRequest())
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldCreateInvoiceWithRecurring()
{
$this->loginAs()
2020-01-13 15:16:35 +03:00
->post(route('invoices.store'), $this->getRequest(true))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-30 15:55:41 +03:00
$this->assertFlashLevel('success');
}
2019-11-16 10:21:14 +03:00
public function testItShouldSeeInvoiceUpdatePage()
2018-10-30 15:55:41 +03:00
{
2020-01-13 15:16:35 +03:00
$invoice = $this->dispatch(new CreateInvoice($this->getRequest()));
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');
}
public function testItShouldDeleteInvoice()
{
2020-01-13 15:16:35 +03:00
$invoice = $this->dispatch(new CreateInvoice($this->getRequest()));
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-01-13 15:16:35 +03:00
public function getRequest($recurring = false)
2018-10-30 15:55:41 +03:00
{
2020-01-13 15:16:35 +03:00
$factory = factory(Invoice::class);
$recurring ? $factory->states('items', 'recurring') : $factory->states('items');
return $factory->raw();
2018-10-30 15:55:41 +03:00
}
2019-04-02 18:51:06 +03:00
}