Akaunting/tests/Feature/Purchases/BillsTest.php

116 lines
3.0 KiB
PHP
Raw Normal View History

2018-10-26 14:27:48 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace Tests\Feature\Purchases;
2018-10-26 14:27:48 +00:00
2020-12-23 22:28:38 +00:00
use App\Jobs\Document\CreateDocument;
use App\Models\Document\Document;
2018-10-26 14:27:48 +00:00
use Tests\Feature\FeatureTestCase;
class BillsTest extends FeatureTestCase
{
public function testItShouldSeeBillListPage()
{
$this->loginAs()
->get(route('bills.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.bills', 2));
}
public function testItShouldSeeBillCreatePage()
{
$this->loginAs()
->get(route('bills.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.bills', 1)]));
}
public function testItShouldCreateBill()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
2018-10-26 14:27:48 +00:00
$this->loginAs()
2020-07-25 14:22:50 +00:00
->post(route('bills.store'), $request)
2019-11-16 07:21:14 +00:00
->assertStatus(200);
2018-10-26 14:27:48 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
2020-12-23 22:28:38 +00:00
$this->assertDatabaseHas('documents', [
'document_number' => $request['document_number'],
2020-07-25 14:22:50 +00:00
]);
2018-10-26 14:27:48 +00:00
}
public function testItShouldCreateBillWithRecurring()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest(true);
2018-10-26 14:27:48 +00:00
$this->loginAs()
2020-07-25 14:22:50 +00:00
->post(route('bills.store'), $request)
2019-11-16 07:21:14 +00:00
->assertStatus(200);
2018-10-26 14:27:48 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
2020-12-23 22:28:38 +00:00
$this->assertDatabaseHas('documents', [
'document_number' => $request['document_number'],
2020-07-25 14:22:50 +00:00
]);
2018-10-26 14:27:48 +00:00
}
public function testItShouldSeeBillUpdatePage()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
2020-12-23 22:28:38 +00:00
$bill = $this->dispatch(new CreateDocument($request));
2019-11-16 07:21:14 +00:00
2018-10-26 14:27:48 +00:00
$this->loginAs()
2020-01-13 07:55:19 +00:00
->get(route('bills.edit', $bill->id))
2018-10-26 14:27:48 +00:00
->assertStatus(200)
2019-11-16 07:21:14 +00:00
->assertSee($bill->contact_email);
2018-10-26 14:27:48 +00:00
}
public function testItShouldUpdateBill()
{
2020-01-13 14:22:31 +00:00
$request = $this->getRequest();
2019-11-17 12:06:00 +00:00
2020-12-23 22:28:38 +00:00
$bill = $this->dispatch(new CreateDocument($request));
2018-10-26 14:27:48 +00:00
2020-03-19 16:00:18 +00:00
$request['contact_email'] = $this->faker->safeEmail;
2018-10-26 14:27:48 +00:00
$this->loginAs()
->patch(route('bills.update', $bill->id), $request)
2020-01-13 14:22:31 +00:00
->assertStatus(200)
2020-03-19 16:00:18 +00:00
->assertSee($request['contact_email']);
2018-10-26 14:27:48 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
2020-12-23 22:28:38 +00:00
$this->assertDatabaseHas('documents', [
'document_number' => $request['document_number'],
2020-07-25 14:22:50 +00:00
'contact_email' => $request['contact_email'],
]);
2018-10-26 14:27:48 +00:00
}
public function testItShouldDeleteBill()
{
2020-07-25 14:22:50 +00:00
$request = $this->getRequest();
2020-12-23 22:28:38 +00:00
$bill = $this->dispatch(new CreateDocument($request));
2018-10-26 14:27:48 +00:00
$this->loginAs()
->delete(route('bills.destroy', $bill->id))
2019-11-17 12:06:00 +00:00
->assertStatus(200);
2018-10-26 14:27:48 +00:00
$this->assertFlashLevel('success');
2020-07-25 14:22:50 +00:00
2020-12-23 22:28:38 +00:00
$this->assertSoftDeleted('documents', [
'document_number' => $request['document_number'],
2020-07-25 14:22:50 +00:00
]);
2018-10-26 14:27:48 +00:00
}
2020-01-13 14:22:31 +00:00
public function getRequest($recurring = false)
2018-10-26 14:27:48 +00:00
{
2020-12-23 22:28:38 +00:00
$factory = Document::factory();
2020-01-13 14:22:31 +00:00
2020-12-23 22:28:38 +00:00
$factory = $recurring ? $factory->bill()->items()->recurring() : $factory->bill()->items();
2020-01-13 14:22:31 +00:00
return $factory->raw();
2018-10-26 14:27:48 +00:00
}
2019-04-02 15:51:06 +00:00
}