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

Add FF_OPT_IN_EMAIL_ENABLED Feature Flag #138

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 43 additions & 9 deletions StoreMessageContentActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ describe("getStoreMessageContentActivityHandler", () => {
messageModelMock as any,
{} as any,
// limit date is after profile timestamp
anOptOutEmailSwitchDate
anOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand All @@ -93,6 +94,31 @@ describe("getStoreMessageContentActivityHandler", () => {
}
});

it("should respond success with a retrieved profile mantaining its original isEmailEnabled property with Feature flag disabled", async () => {
findLastVersionByModelIdMock.mockImplementationOnce(() =>
taskEither.of(some(aRetrievedProfileWithAValidTimestamp))
);
const storeMessageContentActivityHandler = getStoreMessageContentActivityHandler(
profileModelMock as any,
messageModelMock as any,
{} as any,
// limit date is before profile timestamp
anOptOutEmailSwitchDate,
false
);

const result = await storeMessageContentActivityHandler(
mockContext,
aCreatedMessageEvent
);

expect(result.kind).toBe("SUCCESS");
if (result.kind === "SUCCESS") {
expect(result.blockedInboxOrChannels).toEqual([]);
expect(result.profile).toEqual(aRetrievedProfileWithAValidTimestamp);
}
});

it("should respond success with a retrieved profile mantaining its original isEmailEnabled property", async () => {
findLastVersionByModelIdMock.mockImplementationOnce(() =>
taskEither.of(some(aRetrievedProfileWithAValidTimestamp))
Expand All @@ -102,7 +128,8 @@ describe("getStoreMessageContentActivityHandler", () => {
messageModelMock as any,
{} as any,
// limit date is before profile timestamp
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand All @@ -122,7 +149,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand All @@ -144,7 +172,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

await expect(
Expand All @@ -160,7 +189,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand All @@ -182,7 +212,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand All @@ -209,7 +240,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

const result = await storeMessageContentActivityHandler(
Expand Down Expand Up @@ -237,7 +269,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

await expect(
Expand All @@ -253,7 +286,8 @@ describe("getStoreMessageContentActivityHandler", () => {
profileModelMock as any,
messageModelMock as any,
{} as any,
aPastOptOutEmailSwitchDate
aPastOptOutEmailSwitchDate,
true
);

await expect(
Expand Down
12 changes: 7 additions & 5 deletions StoreMessageContentActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const getStoreMessageContentActivityHandler = (
lProfileModel: ProfileModel,
lMessageModel: MessageModel,
lBlobService: BlobService,
optOutEmailSwitchDate: UTCISODateFromString
optOutEmailSwitchDate: UTCISODateFromString,
isOptInEmailEnabled: boolean
) => async (
context: Context,
input: unknown
Expand Down Expand Up @@ -187,10 +188,11 @@ export const getStoreMessageContentActivityHandler = (
profile: {
...profile,
// if profile's timestamp is before email opt out switch limit date we must force isEmailEnabled to false
// eslint-disable-next-line no-underscore-dangle
isEmailEnabled: isBefore(profile._ts, optOutEmailSwitchDate)
? false
: profile.isEmailEnabled
isEmailEnabled:
// eslint-disable-next-line no-underscore-dangle
isOptInEmailEnabled && isBefore(profile._ts, optOutEmailSwitchDate)
? false
: profile.isEmailEnabled
}
};
};
3 changes: 2 additions & 1 deletion StoreMessageContentActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const activityFunctionHandler: AzureFunction = getStoreMessageContentActivityHan
profileModel,
messageModel,
blobService,
config.OPT_OUT_EMAIL_SWITCH_DATE
config.OPT_OUT_EMAIL_SWITCH_DATE,
config.FF_OPT_IN_EMAIL_ENABLED
);

export default activityFunctionHandler;
4 changes: 4 additions & 0 deletions utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const IConfig = t.intersection([
FF_DISABLE_INCOMPLETE_SERVICES: t.boolean,
FF_DISABLE_WEBHOOK_MESSAGE_CONTENT: t.boolean,
FF_INCOMPLETE_SERVICE_WHITELIST: CommaSeparatedListOf(ServiceId),
FF_OPT_IN_EMAIL_ENABLED: t.boolean,

isProduction: t.boolean
}),
Expand All @@ -72,6 +73,9 @@ const errorOrConfig: t.Validation<IConfig> = IConfig.decode({
)
.map(_ => _.toLowerCase() === "true")
.getOrElse(false),
FF_OPT_IN_EMAIL_ENABLED: fromNullable(process.env.FF_OPT_IN_EMAIL_ENABLED)
.map(_ => _.toLocaleLowerCase() === "true")
.getOrElse(false),
OPT_OUT_EMAIL_SWITCH_DATE: fromNullableE(DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE)(
process.env.OPT_OUT_EMAIL_SWITCH_DATE
)
Expand Down