akaunting/tests/Feature/Commands/InvoiceReminderTest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2018-12-05 11:50:36 +00:00
<?php
namespace Tests\Feature\Commands;
2020-12-23 22:28:38 +00:00
use App\Jobs\Document\CreateDocument;
use App\Models\Document\Document;
2019-12-31 12:49:09 +00:00
use App\Notifications\Sale\Invoice as InvoiceNotification;
2020-03-25 17:21:42 +00:00
use App\Utilities\Date;
2018-12-05 11:50:36 +00:00
use Illuminate\Support\Facades\Notification;
use Tests\Feature\FeatureTestCase;
class InvoiceReminderTest extends FeatureTestCase
{
2020-01-13 14:37:59 +00:00
public $add_days;
2018-12-05 11:50:36 +00:00
2019-11-16 07:21:14 +00:00
protected function setUp(): void
2018-12-05 11:50:36 +00:00
{
parent::setUp();
2019-11-18 07:54:26 +00:00
$this->add_days = 3;
2018-12-05 11:50:36 +00:00
}
public function testInvoiceReminderByDueDate()
{
Notification::fake();
2020-12-23 22:28:38 +00:00
$invoice = $this->dispatch(new CreateDocument($this->getRequest()));
2018-12-05 11:50:36 +00:00
2019-11-18 07:54:26 +00:00
Date::setTestNow(Date::now()->addDay($this->add_days));
2018-12-05 11:50:36 +00:00
$this->artisan('reminder:invoice');
Notification::assertSentTo(
$this->user,
InvoiceNotification::class,
function ($notification, $channels) use ($invoice) {
return $notification->invoice->id === $invoice->id;
}
);
}
2020-01-13 14:37:59 +00:00
public function getRequest()
2018-12-05 11:50:36 +00:00
{
2020-12-23 22:28:38 +00:00
return Document::factory()->invoice()->items()->sent()->raw([
2019-11-18 07:54:26 +00:00
'due_at' => Date::now()->subDays($this->add_days - 1),
2020-01-13 14:37:59 +00:00
]);
2018-12-05 11:50:36 +00:00
}
}