91 lines
2.3 KiB
PHP
Raw Normal View History

2018-10-26 17:27:48 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace Tests\Feature\Purchases;
2018-10-26 17:27:48 +03:00
2019-12-31 15:49:09 +03:00
use App\Jobs\Purchase\CreateBill;
2020-01-13 17:22:31 +03:00
use App\Models\Purchase\Bill;
2018-10-26 17:27:48 +03: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()
{
$this->loginAs()
2020-01-13 17:22:31 +03:00
->post(route('bills.store'), $this->getRequest())
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-26 17:27:48 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldCreateBillWithRecurring()
{
$this->loginAs()
2020-01-13 17:22:31 +03:00
->post(route('bills.store'), $this->getRequest(true))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-26 17:27:48 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldSeeBillUpdatePage()
{
2020-01-13 17:22:31 +03:00
$bill = $this->dispatch(new CreateBill($this->getRequest()));
2019-11-16 10:21:14 +03:00
2018-10-26 17:27:48 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->get(route('bills.edit', $bill->id))
2018-10-26 17:27:48 +03:00
->assertStatus(200)
2019-11-16 10:21:14 +03:00
->assertSee($bill->contact_email);
2018-10-26 17:27:48 +03:00
}
public function testItShouldUpdateBill()
{
2020-01-13 17:22:31 +03:00
$request = $this->getRequest();
2019-11-17 15:06:00 +03:00
$bill = $this->dispatch(new CreateBill($request));
2018-10-26 17:27:48 +03:00
2019-11-16 10:21:14 +03:00
$request['contact_name'] = $this->faker->name;
2018-10-26 17:27:48 +03:00
$this->loginAs()
->patch(route('bills.update', $bill->id), $request)
2020-01-13 17:22:31 +03:00
->assertStatus(200)
->assertSee($request['contact_name']);
2018-10-26 17:27:48 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldDeleteBill()
{
2020-01-13 17:22:31 +03:00
$bill = $this->dispatch(new CreateBill($this->getRequest()));
2018-10-26 17:27:48 +03:00
$this->loginAs()
->delete(route('bills.destroy', $bill->id))
2019-11-17 15:06:00 +03:00
->assertStatus(200);
2018-10-26 17:27:48 +03:00
$this->assertFlashLevel('success');
}
2020-01-13 17:22:31 +03:00
public function getRequest($recurring = false)
2018-10-26 17:27:48 +03:00
{
2020-01-13 17:22:31 +03:00
$factory = factory(Bill::class);
$recurring ? $factory->states('items', 'recurring') : $factory->states('items');
return $factory->raw();
2018-10-26 17:27:48 +03:00
}
2019-04-02 18:51:06 +03:00
}