fix: ensure MailJet exclusion flag is revoked for new subscriptions
This commit is contained in:
@@ -105,7 +105,7 @@ class NewsletterManager
|
|||||||
$missingListIds = array_values(array_diff($normalizedListIds, $confirmedListIds));
|
$missingListIds = array_values(array_diff($normalizedListIds, $confirmedListIds));
|
||||||
|
|
||||||
if ([] === $missingListIds) {
|
if ([] === $missingListIds) {
|
||||||
$this->recordSubscription($normalizedEmail, $normalizedListIds, [], $normalizedFirstName, $normalizedLastName);
|
$this->recordSubscription($normalizedEmail, $normalizedListIds, $normalizedFirstName, $normalizedLastName);
|
||||||
|
|
||||||
return new NewsletterSubscriptionRequestResult(
|
return new NewsletterSubscriptionRequestResult(
|
||||||
$normalizedEmail,
|
$normalizedEmail,
|
||||||
@@ -116,7 +116,7 @@ class NewsletterManager
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->recordSubscription($normalizedEmail, $normalizedListIds, $missingListIds, $normalizedFirstName, $normalizedLastName);
|
$this->recordSubscription($normalizedEmail, $normalizedListIds, $normalizedFirstName, $normalizedLastName);
|
||||||
|
|
||||||
return new NewsletterSubscriptionRequestResult(
|
return new NewsletterSubscriptionRequestResult(
|
||||||
$normalizedEmail,
|
$normalizedEmail,
|
||||||
@@ -408,13 +408,12 @@ class NewsletterManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<int> $mailjetListIds
|
* @param list<int> $mailjetListIds
|
||||||
* @param list<int> $missingListIds
|
|
||||||
*/
|
*/
|
||||||
private function recordSubscription(string $email, array $mailjetListIds, array $missingListIds, ?string $firstName, ?string $lastName): void
|
private function recordSubscription(string $email, array $mailjetListIds, ?string $firstName, ?string $lastName): void
|
||||||
{
|
{
|
||||||
$this->syncMailjetContact($email, $firstName, $lastName);
|
$this->syncMailjetContact($email, $firstName, $lastName);
|
||||||
|
|
||||||
foreach ($missingListIds as $mailjetListId) {
|
foreach ($mailjetListIds as $mailjetListId) {
|
||||||
$this->newsletterService->ensureSubscribed($email, $mailjetListId);
|
$this->newsletterService->ensureSubscribed($email, $mailjetListId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,8 +151,11 @@ class NewsletterManagerTest extends TestCase
|
|||||||
$mailer = $this->createMock(Mailer::class);
|
$mailer = $this->createMock(Mailer::class);
|
||||||
|
|
||||||
$mailjet->expects(self::never())->method('isSubscribed');
|
$mailjet->expects(self::never())->method('isSubscribed');
|
||||||
$mailjet->expects(self::never())->method('ensureSubscribed');
|
|
||||||
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
|
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
|
||||||
|
$mailjet
|
||||||
|
->expects(self::exactly(2))
|
||||||
|
->method('ensureSubscribed')
|
||||||
|
->withConsecutive(['[email protected]', 1], ['[email protected]', 2]);
|
||||||
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn($existingConsent);
|
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn($existingConsent);
|
||||||
$consents
|
$consents
|
||||||
->method('findOneByEmailAndListId')
|
->method('findOneByEmailAndListId')
|
||||||
@@ -270,6 +273,7 @@ class NewsletterManagerTest extends TestCase
|
|||||||
$mailjet = $this->createMock(MailjetApiClient::class);
|
$mailjet = $this->createMock(MailjetApiClient::class);
|
||||||
$mailer = $this->createMock(Mailer::class);
|
$mailer = $this->createMock(Mailer::class);
|
||||||
|
|
||||||
|
$mailjet->expects(self::never())->method('ensureSubscribed');
|
||||||
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
|
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
|
||||||
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
|
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
|
||||||
$entityManager
|
$entityManager
|
||||||
@@ -296,6 +300,7 @@ class NewsletterManagerTest extends TestCase
|
|||||||
$mailjet = $this->createMock(MailjetApiClient::class);
|
$mailjet = $this->createMock(MailjetApiClient::class);
|
||||||
$mailer = $this->createMock(Mailer::class);
|
$mailer = $this->createMock(Mailer::class);
|
||||||
|
|
||||||
|
$mailjet->expects(self::never())->method('ensureSubscribed');
|
||||||
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
|
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
|
||||||
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
|
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
|
||||||
$entityManager
|
$entityManager
|
||||||
|
|||||||
Reference in New Issue
Block a user