Skip to content

Commit

Permalink
Feature/star 40 (#41)
Browse files Browse the repository at this point in the history
* Add Temp consutation and webnar to mail

* Add templates for events approved and reject

* Add variables to register temp

* Add setTimezone for datetimes

* Repair tests

* add assert to test

* add assert to test

* add assert to test

* add assert to test

Co-authored-by: Hubert Krzysztofiak <[email protected]>
  • Loading branch information
HerbertIV and Hubert Krzysztofiak authored May 6, 2022
1 parent 92f9454 commit 2186666
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 16 deletions.
20 changes: 20 additions & 0 deletions src/Consultations/ApprovedTermWithTrainerVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace EscolaLms\TemplatesEmail\Consultations;

class ApprovedTermWithTrainerVariables extends CommonConsultationVariables
{
public static function defaultSectionsContent(): array
{
return [
'title' => __('Approved term ":consultation"', [
'consultation' => self::VAR_CONSULTATION_TITLE,
]),
'content' => self::wrapWithMjml(__('<h1>Hello :user_name!</h1><p>You approved term :proposed_term for consultation ":consultation".</p>', [
'user_name' => self::VAR_USER_NAME,
'consultation' => self::VAR_CONSULTATION_TITLE,
'proposed_term' => self::VAR_CONSULTATION_PROPOSED_TERM
])),
];
}
}
5 changes: 4 additions & 1 deletion src/Consultations/CommonConsultationVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use EscolaLms\Core\Models\User;
use EscolaLms\Templates\Events\EventWrapper;
use EscolaLms\TemplatesEmail\Core\EmailVariables;
use Illuminate\Support\Carbon;

abstract class CommonConsultationVariables extends EmailVariables
{
Expand All @@ -28,7 +29,9 @@ public static function variablesFromEvent(EventWrapper $event): array
return array_merge(parent::variablesFromEvent($event), [
self::VAR_USER_NAME => $event->getUser()->name,
self::VAR_CONSULTATION_TITLE => $event->getConsultationTerm()->consultation->name,
self::VAR_CONSULTATION_PROPOSED_TERM => $event->getConsultationTerm()->executed_at,
self::VAR_CONSULTATION_PROPOSED_TERM => Carbon::make($event->getConsultationTerm()->executed_at)
->setTimezone($event->getUser()->current_timezone)
->format('Y-m-d H:i:s'),
]);
}

Expand Down
20 changes: 20 additions & 0 deletions src/Consultations/RejectTermWithTrainerVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace EscolaLms\TemplatesEmail\Consultations;

class RejectTermWithTrainerVariables extends CommonConsultationVariables
{
public static function defaultSectionsContent(): array
{
return [
'title' => __('Reject term ":consultation"', [
'consultation' => self::VAR_CONSULTATION_TITLE,
]),
'content' => self::wrapWithMjml(__('<h1>Hello :user_name!</h1><p>You rejected term :proposed_term for consultation ":consultation".</p>', [
'user_name' => self::VAR_USER_NAME,
'consultation' => self::VAR_CONSULTATION_TITLE,
'proposed_term' => self::VAR_CONSULTATION_PROPOSED_TERM
]),),
];
}
}
29 changes: 29 additions & 0 deletions src/Consultations/ReminderAboutTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,36 @@

namespace EscolaLms\TemplatesEmail\Consultations;

use EscolaLms\Templates\Events\EventWrapper;

class ReminderAboutTermVariables extends CommonConsultationVariables
{
const VAR_CONSULTATION_TERM_ID = '@VarConsultationTermId';

public static function requiredVariables(): array
{
return array_merge(parent::requiredVariables(), [
self::VAR_CONSULTATION_TERM_ID,
]);
}

public static function requiredVariablesInSection(string $sectionKey): array
{
if ($sectionKey === 'content') {
return array_merge(parent::requiredVariablesInSection($sectionKey), [
self::VAR_CONSULTATION_TERM_ID,
]);
}
return [];
}

public static function variablesFromEvent(EventWrapper $event): array
{
return array_merge(parent::variablesFromEvent($event), [
self::VAR_CONSULTATION_TERM_ID => $event->getConsultationTerm()->user->name,
]);
}

public static function defaultSectionsContent(): array
{
return [
Expand All @@ -13,6 +41,7 @@ public static function defaultSectionsContent(): array
'content' => self::wrapWithMjml(__('<h1>Hello :user_name!</h1><p>I would like to remind you about the upcoming consultation :consultation, which will take place :proposed_term.</p>', [
'user_name' => self::VAR_USER_NAME,
'consultation' => self::VAR_CONSULTATION_TITLE,
'consultation_term_id' => self::VAR_CONSULTATION_TERM_ID,
'proposed_term' => self::VAR_CONSULTATION_PROPOSED_TERM
]),),
];
Expand Down
49 changes: 49 additions & 0 deletions src/Consultations/ReminderTrainerAboutTermVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace EscolaLms\TemplatesEmail\Consultations;

use EscolaLms\Templates\Events\EventWrapper;

class ReminderTrainerAboutTermVariables extends CommonConsultationVariables
{
const VAR_CONSULTATION_USER_NAME = '@VarConsultationUserName';

public static function requiredVariables(): array
{
return array_merge(parent::requiredVariables(), [
self::VAR_CONSULTATION_USER_NAME,
]);
}

public static function requiredVariablesInSection(string $sectionKey): array
{
if ($sectionKey === 'content') {
return array_merge(parent::requiredVariablesInSection($sectionKey), [
self::VAR_CONSULTATION_USER_NAME,
]);
}
return [];
}

public static function variablesFromEvent(EventWrapper $event): array
{
return array_merge(parent::variablesFromEvent($event), [
self::VAR_CONSULTATION_USER_NAME => $event->getConsultationTerm()->user->name,
]);
}

public static function defaultSectionsContent(): array
{
return [
'title' => __('Remind term ":consultation"', [
'consultation' => self::VAR_CONSULTATION_TITLE,
]),
'content' => self::wrapWithMjml(__('<h1>Hello :user_name!</h1><p>I would like to remind you about the upcoming consultation :consultation with :consultation_user_name, which will take place :proposed_term.</p>', [
'user_name' => self::VAR_USER_NAME,
'consultation_user_name' => self::VAR_CONSULTATION_USER_NAME,
'consultation' => self::VAR_CONSULTATION_TITLE,
'proposed_term' => self::VAR_CONSULTATION_PROPOSED_TERM
]),),
];
}
}
5 changes: 4 additions & 1 deletion src/Courses/DeadlineIncomingVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EscolaLms\Core\Models\User;
use EscolaLms\Courses\ValueObjects\CourseProgressCollection;
use EscolaLms\Templates\Events\EventWrapper;
use Illuminate\Support\Carbon;

class DeadlineIncomingVariables extends CommonUserAndCourseVariables
{
Expand All @@ -22,7 +23,9 @@ public static function variablesFromEvent(EventWrapper $event): array
{
$progress = CourseProgressCollection::make($event->getUser(), $event->getCourse());
return array_merge(parent::variablesFromEvent($event), [
self::VAR_COURSE_DEADLINE => $progress->getDeadline()
self::VAR_COURSE_DEADLINE => Carbon::make($progress->getDeadline())
->setTimezone($event->getUser()->current_timezone)
->format('Y-m-d H:i:s')
]);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Providers/ConsultationTemplatesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
namespace EscolaLms\TemplatesEmail\Providers;

use EscolaLms\Consultations\Events\ApprovedTerm;
use EscolaLms\Consultations\Events\ApprovedTermWithTrainer;
use EscolaLms\Consultations\Events\RejectTerm;
use EscolaLms\Consultations\Events\RejectTermWithTrainer;
use EscolaLms\Consultations\Events\ReminderAboutTerm;
use EscolaLms\Consultations\Events\ReportTerm;
use EscolaLms\TemplatesEmail\Consultations\ApprovedTermVariables;
use EscolaLms\TemplatesEmail\Consultations\ApprovedTermWithTrainerVariables;
use EscolaLms\TemplatesEmail\Consultations\RejectTermVariables;
use EscolaLms\TemplatesEmail\Consultations\RejectTermWithTrainerVariables;
use EscolaLms\TemplatesEmail\Consultations\ReminderAboutTermVariables;
use EscolaLms\TemplatesEmail\Consultations\ReminderTrainerAboutTermVariables;
use EscolaLms\TemplatesEmail\Consultations\ReminderTrainerAboutTerm;
use EscolaLms\TemplatesEmail\Consultations\ReportTermVariables;
use EscolaLms\TemplatesEmail\Core\EmailChannel;
use Illuminate\Support\ServiceProvider;
Expand All @@ -18,9 +24,12 @@ class ConsultationTemplatesServiceProvider extends ServiceProvider
{
public function boot()
{
Template::register(ApprovedTermWithTrainer::class, EmailChannel::class, ApprovedTermWithTrainerVariables::class);
Template::register(ApprovedTerm::class, EmailChannel::class, ApprovedTermVariables::class);
Template::register(RejectTermWithTrainer::class, EmailChannel::class, RejectTermWithTrainerVariables::class);
Template::register(RejectTerm::class, EmailChannel::class, RejectTermVariables::class);
Template::register(ReportTerm::class, EmailChannel::class, ReportTermVariables::class);
Template::register(ReminderAboutTerm::class, EmailChannel::class, ReminderAboutTermVariables::class);
Template::register(ReminderTrainerAboutTerm::class, EmailChannel::class, ReminderTrainerAboutTermVariables::class);
}
}
5 changes: 4 additions & 1 deletion src/Webinar/CommonWebinarVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EscolaLms\TemplatesEmail\Webinar;

use Carbon\Carbon;
use EscolaLms\Core\Models\User;
use EscolaLms\Templates\Events\EventWrapper;
use EscolaLms\TemplatesEmail\Core\EmailVariables;
Expand All @@ -28,7 +29,9 @@ public static function variablesFromEvent(EventWrapper $event): array
return array_merge(parent::variablesFromEvent($event), [
self::VAR_USER_NAME => $event->getUser()->name,
self::VAR_WEBINAR_TITLE => $event->getConsultationTerm()->consultation->name,
self::VAR_WEBINAR_PROPOSED_TERM => $event->getConsultationTerm()->executed_at,
self::VAR_WEBINAR_PROPOSED_TERM => Carbon::make($event->getConsultationTerm()->executed_at)
->setTimezone($event->getUser()->current_timezone)
->format('Y-m-d H:i:s'),
]);
}

Expand Down
7 changes: 0 additions & 7 deletions src/routes.php
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
<?php

use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'api'], function () {
Route::middleware('auth:api')->prefix('admin')->group(function () {
});
});
16 changes: 10 additions & 6 deletions tests/Api/Admin/UserTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EscolaLms\Auth\Database\Seeders\AuthPermissionSeeder;
use EscolaLms\Auth\Events\AccountBlocked;
use EscolaLms\Auth\Events\AccountDeleted;
use EscolaLms\Auth\Models\User;
use EscolaLms\Core\Tests\ApiTestTrait;
use EscolaLms\Core\Tests\CreatesUsers;
use EscolaLms\Templates\Listeners\TemplateEventListener;
Expand Down Expand Up @@ -37,13 +38,16 @@ public function testAccountDeletedNotification(): void

$admin = $this->makeAdmin();
$student = $this->makeStudent();

$this->response = $this->actingAs($admin, 'api')->deleteJson("/api/admin/users/{$student->getKey()}");

$id = $student->getKey();
$this->response = $this->actingAs($admin, 'api')->deleteJson("/api/admin/users/{$id}");
$user = User::where('email', '=', $student->email)->first();
if ($user) {
$this->assertTrue($user->trashed());
} else {
$this->assertTrue(is_null($user));
}
$this->assertApiSuccess();
$this->assertDatabaseMissing('users', [
'email' => $student->email,
]);


Event::assertDispatched(AccountDeleted::class);

Expand Down

0 comments on commit 2186666

Please sign in to comment.