120 lines
3.6 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;
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()
->post(route('bills.store'), $this->getBillRequest())
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()
2019-11-17 15:06:00 +03:00
->post(route('bills.store'), $this->getBillRequest(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()
{
2019-11-17 15:06:00 +03:00
$bill = $this->dispatch(new CreateBill($this->getBillRequest()));
2019-11-16 10:21:14 +03:00
2018-10-26 17:27:48 +03:00
$this->loginAs()
->get(route('bills.edit', ['bill' => $bill->id]))
->assertStatus(200)
2019-11-16 10:21:14 +03:00
->assertSee($bill->contact_name)
->assertSee($bill->contact_email);
2018-10-26 17:27:48 +03:00
}
public function testItShouldUpdateBill()
{
2019-11-17 15:06:00 +03:00
$request = $this->getBillRequest();
$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)
2019-11-17 15:06:00 +03:00
->assertStatus(200);
2018-10-26 17:27:48 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldDeleteBill()
{
2019-11-17 15:06:00 +03:00
$bill = $this->dispatch(new CreateBill($this->getBillRequest()));
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');
}
2019-11-17 15:06:00 +03:00
private function getBillRequest($recurring = false)
2018-10-26 17:27:48 +03:00
{
$amount = $this->faker->randomFloat(2, 2);
2019-11-17 15:06:00 +03:00
$items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD', 'tax_id' => null]];
2018-10-26 17:27:48 +03:00
$data = [
2019-11-16 10:21:14 +03:00
'company_id' => $this->company->id,
2018-10-26 17:27:48 +03:00
'billed_at' => $this->faker->date(),
'due_at' => $this->faker->date(),
'bill_number' => '1',
'order_number' => '1',
2019-11-18 10:54:26 +03:00
'currency_code' => setting('default.currency', 'USD'),
2018-10-26 17:27:48 +03:00
'currency_rate' => '1',
2019-11-16 10:21:14 +03:00
'items' => $items,
2018-10-26 17:27:48 +03:00
'discount' => '0',
'notes' => $this->faker->text(5),
2019-11-17 15:06:00 +03:00
'category_id' => $this->company->categories()->type('expense')->pluck('id')->first(),
2018-10-26 17:27:48 +03:00
'recurring_frequency' => 'no',
2019-11-16 10:21:14 +03:00
'contact_id' => '0',
'contact_name' => $this->faker->name,
'contact_email' =>$this->faker->email,
'contact_tax_number' => null,
'contact_phone' => null,
'contact_address' => $this->faker->address,
2018-10-26 17:27:48 +03:00
'bill_status_code' => 'draft',
'amount' => $amount,
];
if ($recurring) {
$data['recurring_frequency'] = 'yes';
$data['recurring_interval'] = '1';
$data['recurring_custom_frequency'] = $this->faker->randomElement(['monthly', 'weekly']);
$data['recurring_count'] = '1';
}
return $data;
}
2019-04-02 18:51:06 +03:00
}