Skip to content

Commit

Permalink
Change reminder execute at datetime range (#93)
Browse files Browse the repository at this point in the history
* Change reminder execute at datetime range

* Fix style
  • Loading branch information
daVitekPL authored Jan 25, 2023
1 parent bf35c88 commit b73c839
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Services/ConsultationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,16 @@ public function filterProposedTerms(int $consultationId, Collection $proposedTer

private function getReminderData(string $reminderStatus): Collection
{
$now = now();
$reminderDate = now()->modify(config('escolalms_consultations.modifier_date.' . $reminderStatus, '+1 hour'));
$dateTimeFrom = now()
->modify(config('escolalms_consultations.modifier_date.' . $reminderStatus, '+1 hour'))
->subMinutes(30);
$dateTimeTo = now()
->modify(config('escolalms_consultations.modifier_date.' . $reminderStatus, '+1 hour'))
->addMinutes(30);
$exclusionStatuses = config('escolalms_consultations.exclusion_reminder_status.' . $reminderStatus, []);
$data = [
'date_time_to' => $reminderDate,
'date_time_from' => $now,
'date_time_to' => $dateTimeTo,
'date_time_from' => $dateTimeFrom,
'reminder_status' => $exclusionStatuses,
'status' => [ConsultationTermStatusEnum::APPROVED]
];
Expand Down
24 changes: 24 additions & 0 deletions tests/APIs/ConsultationScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,28 @@ public function testFailReminderAboutConsultationBeforeHourWhenConsultationTermR
$this->consultationUserPivot->reminder_status === ConsultationTermReminderStatusEnum::REMINDED_HOUR_BEFORE
);
}

public function testFailReminderAboutConsultationBeforeDayWhenLessThanDay()
{
Event::fake();
$this->initVariable();
$this->consultationUserPivot = ConsultationUserPivot::factory([
'consultation_id' => $this->consultation->getKey(),
'user_id' => $this->user->getKey(),
'executed_at' => now()->modify(
config('escolalms_consultations.modifier_date.' .
ConsultationTermReminderStatusEnum::REMINDED_DAY_BEFORE, '+1 day')
)->subHour()->format('Y-m-d H:i:s'),
'executed_status' => ConsultationTermStatusEnum::APPROVED,
])->create();
$this->assertTrue($this->consultationUserPivot->reminder_status === null);
$job = new ReminderAboutConsultationJob(ConsultationTermReminderStatusEnum::REMINDED_DAY_BEFORE);
$job->handle();
$this->consultationUserPivot->refresh();
Event::assertNotDispatched(ReminderAboutTerm::class);
Event::assertNotDispatched(ReminderTrainerAboutTerm::class);
$this->assertTrue(
$this->consultationUserPivot->reminder_status === null
);
}
}

0 comments on commit b73c839

Please sign in to comment.