akaunting/tests/Feature/Commands/InvoiceReminderTest.php

49 lines
1.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\Sale\CreateInvoice;
2020-01-13 17:37:59 +03:00
use App\Models\Sale\Invoice;
2019-12-31 15:49:09 +03:00
use App\Notifications\Sale\Invoice as InvoiceNotification;
2018-12-05 14:50:36 +03:00
use Illuminate\Support\Facades\Notification;
use Jenssegers\Date\Date;
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-01-13 17:37:59 +03:00
$invoice = $this->dispatch(new CreateInvoice($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-01-14 10:01:00 +03:00
return factory(Invoice::class)->states('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
}
}