diff --git a/src/Providers/TaskTemplatesServiceProvider.php b/src/Providers/TaskTemplatesServiceProvider.php index 0dea00c..8769e04 100644 --- a/src/Providers/TaskTemplatesServiceProvider.php +++ b/src/Providers/TaskTemplatesServiceProvider.php @@ -5,12 +5,14 @@ use EscolaLms\Tasks\Events\TaskAssignedEvent; use EscolaLms\Tasks\Events\TaskCompleteRequestEvent; use EscolaLms\Tasks\Events\TaskCompleteUserConfirmationEvent; +use EscolaLms\Tasks\Events\TaskIncompleteEvent; use EscolaLms\Tasks\Events\TaskOverdueEvent; use EscolaLms\Templates\Facades\Template; use EscolaLms\TemplatesEmail\Core\EmailChannel; use EscolaLms\TemplatesEmail\Tasks\TaskAssignedVariables; use EscolaLms\TemplatesEmail\Tasks\TaskCompleteRequestVariables; use EscolaLms\TemplatesEmail\Tasks\TaskCompleteUserConfirmationVariables; +use EscolaLms\TemplatesEmail\Tasks\TaskIncompleteVariables; use EscolaLms\TemplatesEmail\Tasks\TaskOverdueVariables; use Illuminate\Support\ServiceProvider; @@ -41,5 +43,11 @@ public function boot(): void EmailChannel::class, TaskOverdueVariables::class ); + + Template::register( + TaskIncompleteEvent::class, + EmailChannel::class, + TaskIncompleteVariables::class + ); } } diff --git a/src/Tasks/TaskIncompleteVariables.php b/src/Tasks/TaskIncompleteVariables.php new file mode 100644 index 0000000..649bced --- /dev/null +++ b/src/Tasks/TaskIncompleteVariables.php @@ -0,0 +1,19 @@ + __('Incomplete task ":task"', [ + 'task' => self::VAR_TASK_TITLE, + ]), + 'content' => self::wrapWithMjml(__('

Hello :user_name!

Task ":task" has been marked as incomplete.

', [ + 'user_name' => self::VAR_USER_NAME, + 'task' => self::VAR_TASK_TITLE, + ])), + ]; + } +} diff --git a/tests/Api/TaskTest.php b/tests/Api/TaskTest.php index c77142d..f5ccd6e 100644 --- a/tests/Api/TaskTest.php +++ b/tests/Api/TaskTest.php @@ -6,6 +6,7 @@ use EscolaLms\Tasks\Events\TaskAssignedEvent; use EscolaLms\Tasks\Events\TaskCompleteRequestEvent; use EscolaLms\Tasks\Events\TaskCompleteUserConfirmationEvent; +use EscolaLms\Tasks\Events\TaskIncompleteEvent; use EscolaLms\Tasks\Models\Task; use EscolaLms\Tasks\Tests\CreatesUsers; use EscolaLms\Templates\Listeners\TemplateEventListener; @@ -128,4 +129,33 @@ public function testNotificationSentToCreatorWhenStudentCompletesTask(): void return true; }); } + + public function testNotificationOnTaskMarkedIncomplete(): void + { + Event::fake([TaskIncompleteEvent::class]); + + $student = $this->makeStudent(); + + /** @var Task $task */ + $task = Task::factory() + ->state(['user_id' => $student->getKey()]) + ->create(); + + $this->actingAs($this->makeAdmin(), 'api') + ->postJson('api/admin/tasks/incomplete/' . $task->getKey()) + ->assertOk(); + + Event::assertDispatched(function (TaskIncompleteEvent $event) use ($task) { + return $event->getUser()->getKey() === $task->user_id && $event->getTask()->getKey() === $task->getKey(); + }); + + $listener = app(TemplateEventListener::class); + $listener->handle(new TaskIncompleteEvent($task->user, $task)); + + Mail::assertSent(EmailMailable::class, function (EmailMailable $mailable) use ($student, $task) { + $this->assertEquals(__('Incomplete task ":task"', ['task' => $task->title]), $mailable->subject); + $this->assertTrue($mailable->hasTo($student->email)); + return true; + }); + } }