added test for recurring
This commit is contained in:
parent
771ae64f0e
commit
a2c44a5d2a
@ -112,11 +112,6 @@ class RecurringCheck extends Command
|
|||||||
foreach ($schedules as $schedule) {
|
foreach ($schedules as $schedule) {
|
||||||
$schedule_date = Date::parse($schedule->getStart()->format('Y-m-d'));
|
$schedule_date = Date::parse($schedule->getStart()->format('Y-m-d'));
|
||||||
|
|
||||||
// Don't recur the future
|
|
||||||
if ($schedule_date->greaterThan($today)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->recur($model, $recur->recurable_type, $schedule_date);
|
$this->recur($model, $recur->recurable_type, $schedule_date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class SendDocumentRecurringNotification
|
|||||||
|
|
||||||
// Notify all users assigned to this company
|
// Notify all users assigned to this company
|
||||||
foreach ($document->company->users as $user) {
|
foreach ($document->company->users as $user) {
|
||||||
if (!$user->can('read-notifications')) {
|
if ($user->cannot('read-notifications')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,15 +87,15 @@ trait Recurring
|
|||||||
->setFreq($this->getRecurringRuleFrequency())
|
->setFreq($this->getRecurringRuleFrequency())
|
||||||
->setInterval($this->getRecurringRuleInterval());
|
->setInterval($this->getRecurringRuleInterval());
|
||||||
|
|
||||||
if ($set_until_date) {
|
|
||||||
$rule->setUntil($this->getRecurringRuleUntilDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0 means infinite
|
// 0 means infinite
|
||||||
if ($this->count != 0) {
|
if ($this->count != 0) {
|
||||||
$rule->setCount($this->getRecurringRuleCount());
|
$rule->setCount($this->getRecurringRuleCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($set_until_date) {
|
||||||
|
$rule->setUntil($this->getRecurringRuleUntilDate());
|
||||||
|
}
|
||||||
|
|
||||||
return $rule;
|
return $rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,10 +203,9 @@ class Document extends AbstractFactory
|
|||||||
public function recurring()
|
public function recurring()
|
||||||
{
|
{
|
||||||
return $this->state([
|
return $this->state([
|
||||||
'recurring_frequency' => 'yes',
|
'recurring_frequency' => 'daily',
|
||||||
'recurring_interval' => '1',
|
'recurring_interval' => '1',
|
||||||
'recurring_custom_frequency' => $this->faker->randomElement(['monthly', 'weekly']),
|
'recurring_count' => '7',
|
||||||
'recurring_count' => '1',
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
tests/Feature/Commands/RecurringCheckTest.php
Normal file
60
tests/Feature/Commands/RecurringCheckTest.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Commands;
|
||||||
|
|
||||||
|
use App\Jobs\Document\CreateDocument;
|
||||||
|
use App\Models\Document\Document;
|
||||||
|
use App\Notifications\Sale\Invoice as InvoiceNotification;
|
||||||
|
use App\Utilities\Date;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
|
class RecurringCheckTest extends FeatureTestCase
|
||||||
|
{
|
||||||
|
public $recurring_count;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->recurring_count = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldCreateCorrectNumberOfRecurringInvoices(): void
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->dispatch(new CreateDocument($this->getRequest()));
|
||||||
|
|
||||||
|
Date::setTestNow(Date::now());
|
||||||
|
|
||||||
|
$this->artisan('recurring:check');
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('documents', $this->recurring_count + 1);
|
||||||
|
|
||||||
|
Notification::assertSentToTimes($this->user, InvoiceNotification::class, $this->recurring_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldNotCreateAnyRecurringInvoice(): void
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->dispatch(new CreateDocument($this->getRequest()));
|
||||||
|
|
||||||
|
Date::setTestNow(Date::now()->subDays($this->recurring_count + 1));
|
||||||
|
|
||||||
|
$this->artisan('recurring:check');
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('documents', 1);
|
||||||
|
|
||||||
|
Notification::assertNotSentTo($this->user, InvoiceNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequest(): array
|
||||||
|
{
|
||||||
|
return Document::factory()->invoice()->items()->recurring()->sent()->raw([
|
||||||
|
'issued_at' => Date::now()->subDays($this->recurring_count + 1),
|
||||||
|
'recurring_count' => '20',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user