diff --git a/StoreMessageContentActivity/__tests__/handler.test.ts b/StoreMessageContentActivity/__tests__/handler.test.ts index 499a0144..9a5b1ee1 100644 --- a/StoreMessageContentActivity/__tests__/handler.test.ts +++ b/StoreMessageContentActivity/__tests__/handler.test.ts @@ -75,7 +75,8 @@ describe("getStoreMessageContentActivityHandler", () => { messageModelMock as any, {} as any, // limit date is after profile timestamp - anOptOutEmailSwitchDate + anOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -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)) @@ -102,7 +128,8 @@ describe("getStoreMessageContentActivityHandler", () => { messageModelMock as any, {} as any, // limit date is before profile timestamp - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -122,7 +149,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -144,7 +172,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); await expect( @@ -160,7 +189,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -182,7 +212,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -209,7 +240,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); const result = await storeMessageContentActivityHandler( @@ -237,7 +269,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); await expect( @@ -253,7 +286,8 @@ describe("getStoreMessageContentActivityHandler", () => { profileModelMock as any, messageModelMock as any, {} as any, - aPastOptOutEmailSwitchDate + aPastOptOutEmailSwitchDate, + true ); await expect( diff --git a/StoreMessageContentActivity/handler.ts b/StoreMessageContentActivity/handler.ts index 4f1de35f..402fa231 100644 --- a/StoreMessageContentActivity/handler.ts +++ b/StoreMessageContentActivity/handler.ts @@ -60,7 +60,8 @@ export const getStoreMessageContentActivityHandler = ( lProfileModel: ProfileModel, lMessageModel: MessageModel, lBlobService: BlobService, - optOutEmailSwitchDate: UTCISODateFromString + optOutEmailSwitchDate: UTCISODateFromString, + isOptInEmailEnabled: boolean ) => async ( context: Context, input: unknown @@ -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 } }; }; diff --git a/StoreMessageContentActivity/index.ts b/StoreMessageContentActivity/index.ts index 38fd9b3a..9efc1a26 100644 --- a/StoreMessageContentActivity/index.ts +++ b/StoreMessageContentActivity/index.ts @@ -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; diff --git a/utils/config.ts b/utils/config.ts index 5fb9e5f1..425c7ab3 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -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 }), @@ -72,6 +73,9 @@ const errorOrConfig: t.Validation = 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 )