-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag to Subscribe APIs to prevent default variant subscribe behavior
This flag complements the change in variant subscription behavior introduced in v2.2. Some clients need to have an option to subscribe multi-variant newsletter list without actually subscribing any variants (either default or all of them) automatically. If the flag is set, variant subscription is suppressed and client needs to subscribe the variants separately without use of the flag. remp/remp#1279
- Loading branch information
Showing
10 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,4 +286,77 @@ public function testFailingSubscribeWithInvalidVariantCode() | |
])->count('*'); | ||
$this->assertFalse($isSubscribed); | ||
} | ||
|
||
/** | ||
* @dataProvider forceNoVariantSubscriptionDataProvider | ||
*/ | ||
public function testUseOfForceNoVariantSubscriptionFlag(bool $multi, bool $default) | ||
{ | ||
$mailType = $this->createMailTypeWithCategory( | ||
categoryName: "category1", | ||
typeCode: "code1", | ||
typeName: "name1", | ||
isMultiVariant: $multi, | ||
); | ||
$variant = $this->createMailTypeVariant($mailType, 'Foo', 'foo'); | ||
|
||
if ($default) { | ||
$defaultVariant = $this->createMailTypeVariant($mailType, 'Bar', 'bar'); | ||
$this->listsRepository->update($mailType, [ | ||
'default_variant_id' => $defaultVariant->id, | ||
]); | ||
} | ||
|
||
$payload = [ | ||
'user_id' => 123, | ||
'email' => '[email protected]', | ||
'list_code' => $mailType->code, | ||
'variant_code' => $variant->code, | ||
'force_no_variant_subscription' => true, | ||
]; | ||
|
||
$params = [ | ||
'raw' => Json::encode($payload) | ||
]; | ||
|
||
/** @var JsonApiResponse $response */ | ||
$response = $this->handler->handle($params); | ||
$this->assertInstanceOf(JsonApiResponse::class, $response); | ||
$this->assertEquals(IResponse::S200_OK, $response->getCode()); | ||
|
||
$userSubscription = $this->userSubscriptionsRepository->getUserSubscription( | ||
mailType: $mailType, | ||
userId: $payload['user_id'], | ||
email: $payload['email'] | ||
); | ||
$this->assertTrue((bool) $userSubscription->subscribed); | ||
|
||
$isVariantSubscribed = (bool) $this->userSubscriptionVariantsRepository->getTable()->where([ | ||
'mail_user_subscription.user_id' => $payload['user_id'], | ||
'mail_user_subscription.user_email' => $payload['email'], | ||
])->count('*'); | ||
$this->assertFalse($isVariantSubscribed); | ||
} | ||
|
||
public function forceNoVariantSubscriptionDataProvider() | ||
{ | ||
return [ | ||
'NoMultiVariant_NoDefaultVariant' => [ | ||
'multi' => false, | ||
'default' => false, | ||
], | ||
'WithMultiVariant_NoDefaultVariant' => [ | ||
'multi' => true, | ||
'default' => false, | ||
], | ||
'NoMultiVariant_WithDefaultVariant' => [ | ||
'multi' => false, | ||
'default' => true, | ||
], | ||
'WithMultiVariant_WithDefaultVariant' => [ | ||
'multi' => true, | ||
'default' => true, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters