akaunting/tests/Feature/Commands/BillReminderTest.php

78 lines
2.2 KiB
PHP
Raw Normal View History

2018-12-05 14:50:36 +03:00
<?php
namespace Tests\Feature\Commands;
2019-12-31 15:49:09 +03:00
use App\Jobs\Purchase\CreateBill;
use App\Notifications\Purchase\Bill as BillNotification;
2019-11-18 10:54:26 +03:00
use Illuminate\Support\Facades\Notification as Notification;
2018-12-05 14:50:36 +03:00
use Jenssegers\Date\Date;
use Tests\Feature\FeatureTestCase;
class BillReminderTest extends FeatureTestCase
{
2019-11-18 10:54:26 +03:00
private $add_days;
2018-12-05 14:50:36 +03:00
2019-11-16 10:21:14 +03:00
protected function setUp(): void
2018-12-05 14:50:36 +03:00
{
parent::setUp();
2019-11-18 10:54:26 +03:00
$this->add_days = 3;
2018-12-05 14:50:36 +03:00
}
public function testBillReminderByDueDate()
{
Notification::fake();
2019-11-17 15:06:00 +03:00
$bill = $this->dispatch(new CreateBill($this->getBillRequest()));
2018-12-05 14:50:36 +03:00
2019-11-18 10:54:26 +03:00
Date::setTestNow(Date::now()->subDays($this->add_days));
2018-12-05 14:50:36 +03:00
$this->artisan('reminder:bill');
Notification::assertSentTo(
$this->user,
BillNotification::class,
function ($notification, $channels) use ($bill) {
return $notification->bill->id === $bill->id;
}
);
}
/**
2019-11-17 15:06:00 +03:00
* Bill request
2018-12-05 14:50:36 +03:00
*
* @return array
*/
private function getBillRequest()
{
$amount = $this->faker->randomFloat(2, 2);
$items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD']];
2019-11-18 10:54:26 +03:00
$data = [
'company_id' => $this->company->id,
2018-12-05 14:50:36 +03:00
'billed_at' => $this->faker->date(),
2019-11-18 10:54:26 +03:00
'due_at' => Date::now()->subDays($this->add_days - 1),
2018-12-05 14:50:36 +03:00
'bill_number' => '1',
'order_number' => '1',
2019-11-18 10:54:26 +03:00
'currency_code' => setting('default.currency', 'USD'),
2018-12-05 14:50:36 +03:00
'currency_rate' => '1',
2019-11-17 15:06:00 +03:00
'items' => $items,
2018-12-05 14:50:36 +03:00
'discount' => '0',
'notes' => $this->faker->text(5),
2019-11-18 10:54:26 +03:00
'category_id' => $this->company->categories()->type('expense')->pluck('id')->first(),
2018-12-05 14:50:36 +03:00
'recurring_frequency' => 'no',
2019-11-18 10:54:26 +03:00
'contact_id' => '0',
'contact_name' => $this->faker->name,
'contact_email' =>$this->faker->email,
2019-11-16 10:21:14 +03:00
'contact_tax_number' => null,
2019-11-18 10:54:26 +03:00
'contact_phone' => null,
'contact_address' => $this->faker->address,
2020-01-11 16:57:32 +03:00
'status' => 'received',
2018-12-05 14:50:36 +03:00
'amount' => $amount,
];
return $data;
}
}