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\Sale\Invoice as InvoiceNotification;
|
2020-03-25 20:21:42 +03:00
|
|
|
use App\Utilities\Date;
|
2018-12-05 14:50:36 +03:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
class InvoiceReminderTest 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 testInvoiceReminderByDueDate()
|
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
$invoice = $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()->addDay($this->add_days));
|
2018-12-05 14:50:36 +03: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 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()->invoice()->items()->sent()->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
|
|
|
}
|
|
|
|
}
|