2018-12-05 14:50:36 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Commands;
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
use App\Jobs\Document\CreateDocument;
|
|
|
|
use App\Models\Document\Document;
|
2019-12-31 15:49:09 +03:00
|
|
|
use App\Notifications\Purchase\Bill as BillNotification;
|
2020-03-25 20:21:42 +03:00
|
|
|
use App\Utilities\Date;
|
2019-11-18 10:54:26 +03:00
|
|
|
use Illuminate\Support\Facades\Notification as Notification;
|
2018-12-05 14:50:36 +03:00
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
class BillReminderTest extends FeatureTestCase
|
|
|
|
{
|
2020-01-13 17:37:59 +03:00
|
|
|
public $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();
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
$bill = $this->dispatch(new CreateDocument($this->getRequest()));
|
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;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-13 17:37:59 +03:00
|
|
|
public function getRequest()
|
2018-12-05 14:50:36 +03:00
|
|
|
{
|
2020-12-24 01:28:38 +03:00
|
|
|
return Document::factory()->bill()->items()->received()->raw([
|
2019-11-18 10:54:26 +03:00
|
|
|
'due_at' => Date::now()->subDays($this->add_days - 1),
|
2020-01-13 17:37:59 +03:00
|
|
|
]);
|
2018-12-05 14:50:36 +03:00
|
|
|
}
|
|
|
|
}
|