akaunting/tests/Feature/Commands/BillReminderTest.php
2020-12-24 01:28:38 +03:00

49 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature\Commands;
use App\Jobs\Document\CreateDocument;
use App\Models\Document\Document;
use App\Notifications\Purchase\Bill as BillNotification;
use App\Utilities\Date;
use Illuminate\Support\Facades\Notification as Notification;
use Tests\Feature\FeatureTestCase;
class BillReminderTest extends FeatureTestCase
{
public $add_days;
protected function setUp(): void
{
parent::setUp();
$this->add_days = 3;
}
public function testBillReminderByDueDate()
{
Notification::fake();
$bill = $this->dispatch(new CreateDocument($this->getRequest()));
Date::setTestNow(Date::now()->subDays($this->add_days));
$this->artisan('reminder:bill');
Notification::assertSentTo(
$this->user,
BillNotification::class,
function ($notification, $channels) use ($bill) {
return $notification->bill->id === $bill->id;
}
);
}
public function getRequest()
{
return Document::factory()->bill()->items()->received()->raw([
'due_at' => Date::now()->subDays($this->add_days - 1),
]);
}
}