bill factory
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\Purchases;
|
||||
|
||||
use App\Jobs\Purchase\CreateBill;
|
||||
use App\Models\Purchase\Bill;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class BillsTest extends FeatureTestCase
|
||||
@ -26,7 +27,7 @@ class BillsTest extends FeatureTestCase
|
||||
public function testItShouldCreateBill()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('bills.store'), $this->getBillRequest())
|
||||
->post(route('bills.store'), $this->getRequest())
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
@ -35,7 +36,7 @@ class BillsTest extends FeatureTestCase
|
||||
public function testItShouldCreateBillWithRecurring()
|
||||
{
|
||||
$this->loginAs()
|
||||
->post(route('bills.store'), $this->getBillRequest(true))
|
||||
->post(route('bills.store'), $this->getRequest(true))
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
@ -43,7 +44,7 @@ class BillsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldSeeBillUpdatePage()
|
||||
{
|
||||
$bill = $this->dispatch(new CreateBill($this->getBillRequest()));
|
||||
$bill = $this->dispatch(new CreateBill($this->getRequest()));
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('bills.edit', $bill->id))
|
||||
@ -53,7 +54,7 @@ class BillsTest extends FeatureTestCase
|
||||
|
||||
public function testItShouldUpdateBill()
|
||||
{
|
||||
$request = $this->getBillRequest();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$bill = $this->dispatch(new CreateBill($request));
|
||||
|
||||
@ -61,14 +62,15 @@ class BillsTest extends FeatureTestCase
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('bills.update', $bill->id), $request)
|
||||
->assertStatus(200);
|
||||
->assertStatus(200)
|
||||
->assertSee($request['contact_name']);
|
||||
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
public function testItShouldDeleteBill()
|
||||
{
|
||||
$bill = $this->dispatch(new CreateBill($this->getBillRequest()));
|
||||
$bill = $this->dispatch(new CreateBill($this->getRequest()));
|
||||
|
||||
$this->loginAs()
|
||||
->delete(route('bills.destroy', $bill->id))
|
||||
@ -77,42 +79,12 @@ class BillsTest extends FeatureTestCase
|
||||
$this->assertFlashLevel('success');
|
||||
}
|
||||
|
||||
private function getBillRequest($recurring = false)
|
||||
public function getRequest($recurring = false)
|
||||
{
|
||||
$amount = $this->faker->randomFloat(2, 2);
|
||||
$factory = factory(Bill::class);
|
||||
|
||||
$items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD', 'tax_id' => null]];
|
||||
$recurring ? $factory->states('items', 'recurring') : $factory->states('items');
|
||||
|
||||
$data = [
|
||||
'company_id' => $this->company->id,
|
||||
'billed_at' => $this->faker->date(),
|
||||
'due_at' => $this->faker->date(),
|
||||
'bill_number' => '1',
|
||||
'order_number' => '1',
|
||||
'currency_code' => setting('default.currency', 'USD'),
|
||||
'currency_rate' => '1',
|
||||
'items' => $items,
|
||||
'discount' => '0',
|
||||
'notes' => $this->faker->text(5),
|
||||
'category_id' => $this->company->categories()->type('expense')->pluck('id')->first(),
|
||||
'recurring_frequency' => 'no',
|
||||
'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,
|
||||
'status' => '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;
|
||||
return $factory->raw();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user