Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPF-53 Added activation requested and integration deleted mail #1391

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function withUrls(IntegrationUrl ...$urls): self
return $clone;
}

public function withreminderEmailSent(DateTimeInterface $reminderEmailSent): self
public function withReminderEmailSent(DateTimeInterface $reminderEmailSent): self
{
$clone = clone $this;
$clone->reminderEmailSent = $reminderEmailSent;
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Models/IntegrationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function toDomain(): Integration
);

if ($this->reminder_email_sent) {
$integration = $integration->withreminderEmailSent(Carbon::parse($this->reminder_email_sent));
$integration = $integration->withReminderEmailSent(Carbon::parse($this->reminder_email_sent));
}

if ($this->keyVisibilityUpgrade) {
Expand Down
16 changes: 16 additions & 0 deletions app/Domain/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use App\Domain\Contacts\ContactType;
use App\Domain\Integrations\Events\ActivationExpired;
use App\Domain\Integrations\Events\IntegrationActivated;
use App\Domain\Integrations\Events\IntegrationActivationRequested;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreatedWithContacts;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Integration;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Mails\Template\Template;
Expand Down Expand Up @@ -52,6 +54,20 @@ public function sendIntegrationBlockedMail(IntegrationBlocked $event): void
$this->sendMail($integration, $this->templates->getOrFail(TemplateName::INTEGRATION_BLOCKED->value));
}

public function sendIntegrationActivationRequestMail(IntegrationActivationRequested $event): void
LucWollants marked this conversation as resolved.
Show resolved Hide resolved
{
$integration = $this->integrationRepository->getById($event->id);

$this->sendMail($integration, $this->templates->getOrFail(TemplateName::INTEGRATION_ACTIVATION_REQUEST->value));
}

public function sendIntegrationDeletedMail(IntegrationDeleted $event): void
{
$integration = $this->integrationRepository->getByIdWithTrashed($event->id);

$this->sendMail($integration, $this->templates->getOrFail(TemplateName::INTEGRATION_DELETED->value));
}

public function sendActivationReminderEmail(ActivationExpired $event): void
{
$integration = $this->integrationRepository->getById($event->id);
Expand Down
4 changes: 4 additions & 0 deletions app/Mails/MailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use App\Domain\Integrations\Events\ActivationExpired;
use App\Domain\Integrations\Events\IntegrationActivated;
use App\Domain\Integrations\Events\IntegrationActivationRequested;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreatedWithContacts;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Mail\Mailer;
use App\Domain\Mail\MailManager;
Expand Down Expand Up @@ -54,5 +56,7 @@ public function register(): void
Event::listen(IntegrationActivated::class, [MailManager::class, 'sendIntegrationActivatedMail']);
Event::listen(IntegrationBlocked::class, [MailManager::class, 'sendIntegrationBlockedMail']);
Event::listen(ActivationExpired::class, [MailManager::class, 'sendActivationReminderEmail']);
Event::listen(IntegrationActivationRequested::class, [MailManager::class, 'sendIntegrationActivationRequestMail']);
Event::listen(IntegrationDeleted::class, [MailManager::class, 'sendIntegrationDeletedMail']);
}
}
2 changes: 2 additions & 0 deletions app/Mails/Template/TemplateName.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ enum TemplateName: string
case INTEGRATION_ACTIVATION_REMINDER = 'integration_activation_reminder';
case INTEGRATION_BLOCKED = 'integration_blocked';
case INTEGRATION_ACTIVATED = 'integration_activated';
case INTEGRATION_ACTIVATION_REQUEST = 'integration_activation_request';
case INTEGRATION_DELETED = 'integration_deleted';
}
5 changes: 0 additions & 5 deletions app/Mails/Template/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
*/
final class Templates extends Collection
{
public const INTEGRATION_CREATED = 'integration_created';
public const INTEGRATION_ACTIVATION_REMINDER = 'integration_activation_reminder';
public const INTEGRATION_BLOCKED = 'integration_blocked';
public const INTEGRATION_ACTIVATED = 'integration_activated';

public static function build(array $mails): self
{
$collection = new self();
Expand Down
10 changes: 10 additions & 0 deletions config/mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@
'enabled' => true,
'subject' => 'Publiq platform - Can we help you to activate your integration?',
],
TemplateName::INTEGRATION_ACTIVATION_REQUEST->value => [
'id' => env('MAILJET_TEMPLATE_INTEGRATION_ACTIVATION_REQUEST'),
'enabled' => true,
'subject' => 'Publiq platform - Request for activating integration',
],
TemplateName::INTEGRATION_DELETED->value => [
'id' => env('MAILJET_TEMPLATE_INTEGRATION_DELETED'),
'enabled' => true,
'subject' => 'Publiq platform - Integration deleted',
],
],
];
41 changes: 35 additions & 6 deletions tests/Domain/Mail/MailManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use App\Domain\Contacts\ContactType;
use App\Domain\Integrations\Events\ActivationExpired;
use App\Domain\Integrations\Events\IntegrationActivated;
use App\Domain\Integrations\Events\IntegrationActivationRequested;
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreatedWithContacts;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationPartnerStatus;
use App\Domain\Integrations\IntegrationStatus;
Expand All @@ -33,6 +35,9 @@ final class MailManagerTest extends TestCase
private const TEMPLATE_ACTIVATED_ID = 2;
private const TEMPLATE_CREATED_ID = 3;
private const TEMPLATE_INTEGRATION_ACTIVATION_REMINDER = 4;
private const TEMPLATE_ACTIVATION_REQUESTED_ID = 5;
private const TEMPLATE_DELETED_ID = 6;

private MailManager $mailManager;
private Mailer&MockObject $mailer;

Expand Down Expand Up @@ -119,18 +124,19 @@ public function testSendMail(
int $templateId,
string $subject,
bool $checkReminderEmailSent = false,
bool $useGetByIdWithTrashed = false,
): void {
$now = Carbon::now();
Carbon::setTestNow($now);

$this->integrationRepository
->expects($this->once())
->method('getById')
->method($useGetByIdWithTrashed ? 'getByIdWithTrashed' : 'getById')
->with(self::INTEGRATION_ID)
->willReturn($this->integration);

if ($checkReminderEmailSent) {
$integrationWithReminderEmailSent = $this->integration->withreminderEmailSent(Carbon::now());
$integrationWithReminderEmailSent = $this->integration->withReminderEmailSent(Carbon::now());
$this->integrationRepository
->expects($this->once())
->method('update')
Expand Down Expand Up @@ -201,6 +207,19 @@ public static function mailDataProvider(): array
'templateId' => self::TEMPLATE_BLOCKED_ID,
'subject' => 'Publiq platform - Integration blocked',
],
TemplateName::INTEGRATION_ACTIVATION_REQUEST->value => [
'event' => new IntegrationActivationRequested(Uuid::fromString(self::INTEGRATION_ID)),
'method' => 'sendIntegrationActivationRequestMail',
'templateId' => self::TEMPLATE_ACTIVATION_REQUESTED_ID,
'subject' => 'Publiq platform - Request for activating integration',
],
TemplateName::INTEGRATION_DELETED->value => [
'event' => new IntegrationDeleted(Uuid::fromString(self::INTEGRATION_ID)),
'method' => 'sendIntegrationDeletedMail',
'templateId' => self::TEMPLATE_DELETED_ID,
'subject' => 'Publiq platform - Integration deleted',
'useGetByIdWithTrashed' => true,
],
TemplateName::INTEGRATION_ACTIVATION_REMINDER->value => [
'event' => new ActivationExpired(Uuid::fromString(self::INTEGRATION_ID)),
'method' => 'sendActivationReminderEmail',
Expand All @@ -214,26 +233,36 @@ public static function mailDataProvider(): array
private function getTemplateConfig(): array
{
return [
'integration_created' => [
TemplateName::INTEGRATION_CREATED->value => [
'id' => self::TEMPLATE_CREATED_ID,
'enabled' => true,
'subject' => 'Welcome to Publiq platform - Let\'s get you started!',
],
'integration_blocked' => [
TemplateName::INTEGRATION_BLOCKED->value => [
'id' => self::TEMPLATE_BLOCKED_ID,
'enabled' => true,
'subject' => 'Publiq platform - Integration blocked',
],
'integration_activated' => [
TemplateName::INTEGRATION_ACTIVATED->value => [
'id' => self::TEMPLATE_ACTIVATED_ID,
'enabled' => true,
'subject' => 'Publiq platform - Integration activated',
],
'integration_activation_reminder' => [
TemplateName::INTEGRATION_ACTIVATION_REMINDER->value => [
'id' => self::TEMPLATE_INTEGRATION_ACTIVATION_REMINDER,
'enabled' => true,
'subject' => 'Publiq platform - Can we help you to activate your integration?',
],
TemplateName::INTEGRATION_ACTIVATION_REQUEST->value => [
'id' => self::TEMPLATE_ACTIVATION_REQUESTED_ID,
'enabled' => true,
'subject' => 'Publiq platform - Request for activating integration',
],
TemplateName::INTEGRATION_DELETED->value => [
'id' => self::TEMPLATE_DELETED_ID,
'enabled' => true,
'subject' => 'Publiq platform - Integration deleted',
],
];
}
}
Loading