From 9eaa5ccc85f5a1ab8e6f27d14b1cde76e33421e8 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 28 Jan 2024 09:33:56 -0800 Subject: [PATCH 01/19] extract message content with Platform-Specific Overrides --- packages/core/src/libraryUtils.ts | 2 +- .../providers/pinpoint/utils/helpers.test.ts | 49 ++ .../utils/processInAppMessages.test.ts | 6 +- .../notifications/__tests__/testUtils/data.ts | 465 ++++++++++++++++++ .../providers/pinpoint/utils/helpers.ts | 40 +- .../utils/messageProcessingHelpers.ts | 8 +- .../src/inAppMessaging/types/message.ts | 2 + 7 files changed, 565 insertions(+), 7 deletions(-) diff --git a/packages/core/src/libraryUtils.ts b/packages/core/src/libraryUtils.ts index 6d8a552ed3c..876854a0809 100644 --- a/packages/core/src/libraryUtils.ts +++ b/packages/core/src/libraryUtils.ts @@ -24,7 +24,7 @@ export { LegacyConfig } from './singleton/types'; export { ADD_OAUTH_LISTENER } from './singleton/constants'; export { amplifyUuid } from './utils/amplifyUuid'; export { AmplifyUrl, AmplifyUrlSearchParams } from './utils/amplifyUrl'; - +export { getClientInfo } from './utils'; // Auth utilities export { decodeJWT, diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 33b7bfd1b6d..a9a1c94eec8 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -10,6 +10,7 @@ import { extractMetadata, getStartOfDay, isBeforeEndDate, + mapOSPlatform, matchesAttributes, matchesEventType, matchesMetrics, @@ -19,6 +20,9 @@ import { extractedContent, extractedMetadata, pinpointInAppMessage, + pinpointInAppMessagesWithOverrides, + browserConfigTestCases, + nonBrowserConfigTestCases } from '../../../../testUtils/data'; import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types'; @@ -271,4 +275,49 @@ describe('InAppMessaging Provider Utils', () => { expect(extractMetadata(message)).toStrictEqual(extractedMetadata); }); + + describe('extractContent with overrides', () => { + pinpointInAppMessagesWithOverrides.forEach(({ message, expectedContent, configPlatform }) => { + test(`correctly extracts content for ${configPlatform}`, () => { + const { InAppMessage } = cloneDeep(message); + const content = extractContent({ InAppMessage, configPlatform }); + expect(content[0].primaryButton).toStrictEqual(expectedContent[0].primaryButton); + expect(content[0].secondaryButton).toStrictEqual(expectedContent[0].secondaryButton); + }); + }); + }); + + + describe('mapOSPlatform method', () => { + describe('when running in a browser', () => { + browserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); + }); + }); + }); + + describe('when running natively', () => { + let originalWindow = window; + + beforeEach(() => { + //remove window object to mock behavior outside a browser + Object.defineProperty(global, 'window', {}); + }); + + afterEach(() => { + //remove window object to mock behavior outside a browser + Object.defineProperty(global, 'window', originalWindow); + }); + nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); + }); + }); + }); + }); + + }); diff --git a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts index ef764ec2d77..aee36230318 100644 --- a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts @@ -19,7 +19,11 @@ import { import { initializeInAppMessaging } from '../../../src/inAppMessaging/providers/pinpoint/apis'; jest.mock('@aws-amplify/core'); -jest.mock('@aws-amplify/core/internals/utils'); +jest.mock('@aws-amplify/core/internals/utils', () => ({ + getClientInfo: jest.fn().mockImplementation(() => ({ + platform: 'android', + })), +})); jest.mock('../../../src/inAppMessaging/providers/pinpoint/utils/helpers'); const mockIsBeforeEndDate = isBeforeEndDate as jest.Mock; diff --git a/packages/notifications/__tests__/testUtils/data.ts b/packages/notifications/__tests__/testUtils/data.ts index c9986055675..abb59e6df65 100644 --- a/packages/notifications/__tests__/testUtils/data.ts +++ b/packages/notifications/__tests__/testUtils/data.ts @@ -5,9 +5,11 @@ import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pi import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { InAppMessage, + InAppMessageContent, InAppMessagingEvent, } from '../../src/inAppMessaging/types'; import { PushNotificationMessage } from '../../src/pushNotifications'; +import { ConfigPlatformType } from '../../src/inAppMessaging/types/message'; export const credentials = { credentials: { @@ -183,6 +185,449 @@ export const pinpointInAppMessage: PinpointInAppMessage = { TreatmentId: 'T1', }; +export const pinpointInAppMessagesWithOverrides: { + message: PinpointInAppMessage; + expectedContent: InAppMessageContent[]; + configPlatform: ConfigPlatformType; +}[] = [ + { + configPlatform: 'Android', + expectedContent: [ + { + body: { + content: 'Body content', + style: { color: '#FF8888', textAlign: 'left' }, + }, + container: { style: { backgroundColor: '#FFFF88' } }, + header: { + content: 'Header content', + style: { color: '#88FF88', textAlign: 'center' }, + }, + image: { src: imageUrl }, + primaryButton: { + action: 'DEEP_LINK', + style: { + backgroundColor: '#8888FF', + borderRadius: 4, + color: '#FF88FF', + }, + title: 'Close button', + url: 'android-app://primaryButtonLink', + }, + secondaryButton: { + action: 'DEEP_LINK', + style: { + backgroundColor: '#88FFFF', + borderRadius: 4, + color: '#FFFFFF', + }, + title: 'Link button', + url: 'android-app://secondaryButtonLink', + }, + }, + ], + message: { + CampaignId: 'uuid-1', + InAppMessage: { + Content: [ + { + BackgroundColor: '#FFFF88', + BodyConfig: { + Alignment: 'LEFT', + Body: 'Body content', + TextColor: '#FF8888', + }, + HeaderConfig: { + Alignment: 'CENTER', + Header: 'Header content', + TextColor: '#88FF88', + }, + ImageUrl: imageUrl, + PrimaryBtn: { + DefaultConfig: { + BackgroundColor: '#8888FF', + BorderRadius: 4, + ButtonAction: 'CLOSE', + Link: undefined, + Text: 'Close button', + TextColor: '#FF88FF', + }, + Android: { + ButtonAction: 'DEEP_LINK', + Link: 'android-app://primaryButtonLink', + }, + }, + SecondaryBtn: { + DefaultConfig: { + BackgroundColor: '#88FFFF', + BorderRadius: 4, + ButtonAction: 'LINK', + Link: 'http://link.fakeurl', + Text: 'Link button', + TextColor: '#FFFFFF', + }, + Android: { + ButtonAction: 'DEEP_LINK', + Link: 'android-app://secondaryButtonLink', + }, + }, + }, + ], + Layout: 'TOP_BANNER', + CustomConfig: { foo: 'bar' }, + }, + Priority: 3, + Schedule: { + EndDate: '2021-01-01T00:00:00Z', + EventFilter: { + FilterType: 'SYSTEM', + Dimensions: { + Attributes: {}, + EventType: { + DimensionType: 'INCLUSIVE', + Values: ['clicked', 'swiped'], + }, + Metrics: {}, + }, + }, + QuietTime: { + End: undefined, + Start: undefined, + }, + }, + SessionCap: 0, + DailyCap: 0, + TotalCap: 0, + TreatmentId: 'T1', + }, + }, + { + configPlatform: 'IOS', + expectedContent: [ + { + body: { + content: 'Body content', + style: { color: '#FF8888', textAlign: 'left' }, + }, + container: { style: { backgroundColor: '#FFFF88' } }, + header: { + content: 'Header content', + style: { color: '#88FF88', textAlign: 'center' }, + }, + image: { src: imageUrl }, + primaryButton: { + action: 'DEEP_LINK', + style: { + backgroundColor: '#8888FF', + borderRadius: 4, + color: '#FF88FF', + }, + title: 'Close button', + url: 'ios-app://primaryButtonLink', + }, + secondaryButton: { + action: 'DEEP_LINK', + style: { + backgroundColor: '#88FFFF', + borderRadius: 4, + color: '#FFFFFF', + }, + title: 'Link button', + url: 'ios-app://secondaryButtonLink', + }, + }, + ], + message: { + CampaignId: 'uuid-2', + InAppMessage: { + Content: [ + { + BackgroundColor: '#FFFF88', + BodyConfig: { + Alignment: 'LEFT', + Body: 'Body content', + TextColor: '#FF8888', + }, + HeaderConfig: { + Alignment: 'CENTER', + Header: 'Header content', + TextColor: '#88FF88', + }, + ImageUrl: imageUrl, + PrimaryBtn: { + DefaultConfig: { + BackgroundColor: '#8888FF', + BorderRadius: 4, + ButtonAction: 'CLOSE', + Link: undefined, + Text: 'Close button', + TextColor: '#FF88FF', + }, + IOS: { + ButtonAction: 'DEEP_LINK', + Link: 'ios-app://primaryButtonLink', + }, + }, + SecondaryBtn: { + DefaultConfig: { + BackgroundColor: '#88FFFF', + BorderRadius: 4, + ButtonAction: 'LINK', + Link: 'http://link.fakeurl', + Text: 'Link button', + TextColor: '#FFFFFF', + }, + IOS: { + ButtonAction: 'DEEP_LINK', + Link: 'ios-app://secondaryButtonLink', + }, + }, + }, + ], + Layout: 'TOP_BANNER', + CustomConfig: { foo: 'bar' }, + }, + Priority: 3, + Schedule: { + EndDate: '2021-01-01T00:00:00Z', + EventFilter: { + FilterType: 'SYSTEM', + Dimensions: { + Attributes: {}, + EventType: { + DimensionType: 'INCLUSIVE', + Values: ['clicked', 'swiped'], + }, + Metrics: {}, + }, + }, + QuietTime: { + End: undefined, + Start: undefined, + }, + }, + SessionCap: 0, + DailyCap: 0, + TotalCap: 0, + TreatmentId: 'T1', + }, + }, + { + configPlatform: 'Web', + expectedContent: [ + { + body: { + content: 'Body content', + style: { color: '#FF8888', textAlign: 'left' }, + }, + container: { style: { backgroundColor: '#FFFF88' } }, + header: { + content: 'Header content', + style: { color: '#88FF88', textAlign: 'center' }, + }, + image: { src: imageUrl }, + primaryButton: { + action: 'LINK', + style: { + backgroundColor: '#8888FF', + borderRadius: 4, + color: '#FF88FF', + }, + title: 'Close button', + url: 'https://webPrimaryButtonLink.com', + }, + secondaryButton: { + action: 'LINK', + style: { + backgroundColor: '#88FFFF', + borderRadius: 4, + color: '#FFFFFF', + }, + title: 'Link button', + url: 'https://webSecondaryButtonLink.com', + }, + }, + ], + message: { + CampaignId: 'uuid-3', + InAppMessage: { + Content: [ + { + BackgroundColor: '#FFFF88', + BodyConfig: { + Alignment: 'LEFT', + Body: 'Body content', + TextColor: '#FF8888', + }, + HeaderConfig: { + Alignment: 'CENTER', + Header: 'Header content', + TextColor: '#88FF88', + }, + ImageUrl: imageUrl, + PrimaryBtn: { + DefaultConfig: { + BackgroundColor: '#8888FF', + BorderRadius: 4, + ButtonAction: 'CLOSE', + Link: undefined, + Text: 'Close button', + TextColor: '#FF88FF', + }, + Web: { + ButtonAction: 'LINK', + Link: 'https://webPrimaryButtonLink.com', + }, + }, + SecondaryBtn: { + DefaultConfig: { + BackgroundColor: '#88FFFF', + BorderRadius: 4, + ButtonAction: 'LINK', + Link: 'http://link.fakeurl', + Text: 'Link button', + TextColor: '#FFFFFF', + }, + Web: { + ButtonAction: 'LINK', + Link: 'https://webSecondaryButtonLink.com', + }, + }, + }, + ], + Layout: 'TOP_BANNER', + CustomConfig: { foo: 'bar' }, + }, + Priority: 3, + Schedule: { + EndDate: '2021-01-01T00:00:00Z', + EventFilter: { + FilterType: 'SYSTEM', + Dimensions: { + Attributes: {}, + EventType: { + DimensionType: 'INCLUSIVE', + Values: ['clicked', 'swiped'], + }, + Metrics: {}, + }, + }, + QuietTime: { + End: undefined, + Start: undefined, + }, + }, + SessionCap: 0, + DailyCap: 0, + TotalCap: 0, + TreatmentId: 'T1', + }, + }, + { + configPlatform: 'DefaultConfig', + expectedContent: [ + { + body: { + content: 'Body content', + style: { color: '#FF8888', textAlign: 'left' }, + }, + container: { style: { backgroundColor: '#FFFF88' } }, + header: { + content: 'Header content', + style: { color: '#88FF88', textAlign: 'center' }, + }, + image: { src: imageUrl }, + primaryButton: { + action: 'CLOSE', + style: { + backgroundColor: '#8888FF', + borderRadius: 4, + color: '#FF88FF', + }, + title: 'Close button', + url: undefined, + }, + secondaryButton: { + action: 'LINK', + style: { + backgroundColor: '#88FFFF', + borderRadius: 4, + color: '#FFFFFF', + }, + title: 'Link button', + url: 'http://link.fakeurl', + }, + }, + ], + message: { + CampaignId: 'uuid-4', + InAppMessage: { + Content: [ + { + BackgroundColor: '#FFFF88', + BodyConfig: { + Alignment: 'LEFT', + Body: 'Body content', + TextColor: '#FF8888', + }, + HeaderConfig: { + Alignment: 'CENTER', + Header: 'Header content', + TextColor: '#88FF88', + }, + ImageUrl: imageUrl, + PrimaryBtn: { + DefaultConfig: { + BackgroundColor: '#8888FF', + BorderRadius: 4, + ButtonAction: 'CLOSE', + Link: undefined, + Text: 'Close button', + TextColor: '#FF88FF', + }, + }, + SecondaryBtn: { + DefaultConfig: { + BackgroundColor: '#88FFFF', + BorderRadius: 4, + ButtonAction: 'LINK', + Link: 'http://link.fakeurl', + Text: 'Link button', + TextColor: '#FFFFFF', + }, + }, + }, + ], + Layout: 'TOP_BANNER', + CustomConfig: { foo: 'bar' }, + }, + Priority: 3, + Schedule: { + EndDate: '2021-01-01T00:00:00Z', + EventFilter: { + FilterType: 'SYSTEM', + Dimensions: { + Attributes: {}, + EventType: { + DimensionType: 'INCLUSIVE', + Values: ['clicked', 'swiped'], + }, + Metrics: {}, + }, + }, + QuietTime: { + End: undefined, + Start: undefined, + }, + }, + SessionCap: 0, + DailyCap: 0, + TotalCap: 0, + TreatmentId: 'T1', + }, + }, +]; + export const extractedContent = [ { body: { @@ -295,3 +740,23 @@ export const completionHandlerId = 'completion-handler-id'; export const userAgentValue = 'user-agent-value'; export const channelType = 'APNS_SANDBOX'; + +export const browserConfigTestCases = [ + { os: 'android', expectedPlatform: 'Web' }, + { os: 'ios', expectedPlatform: 'Web' }, + { os: 'windows', expectedPlatform: 'Web' }, + { os: 'macos', expectedPlatform: 'Web' }, + { os: 'linux', expectedPlatform: 'Web' }, + { os: 'unix', expectedPlatform: 'Web' }, + { os: 'unknown', expectedPlatform: 'Web' }, +]; + +export const nonBrowserConfigTestCases = [ + { os: 'android', expectedPlatform: 'Android' }, + { os: 'ios', expectedPlatform: 'IOS' }, + { os: 'windows', expectedPlatform: 'DefaultConfig' }, + { os: 'macos', expectedPlatform: 'DefaultConfig' }, + { os: 'linux', expectedPlatform: 'DefaultConfig' }, + { os: 'unix', expectedPlatform: 'DefaultConfig' }, + { os: 'unknown', expectedPlatform: 'DefaultConfig' }, +]; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index be0a1bb5b24..4916efbb9de 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -19,6 +19,7 @@ import { resolveConfig } from './resolveConfig'; import { resolveCredentials } from './resolveCredentials'; import { CATEGORY } from './constants'; import { getInAppMessagingUserAgentString } from './userAgent'; +import { ConfigPlatformType } from '../../../types/message'; const DELIVERY_TYPE = 'IN_APP_MESSAGE'; @@ -241,7 +242,10 @@ export const interpretLayout = ( export const extractContent = ({ InAppMessage: message, -}: PinpointInAppMessage): InAppMessageContent[] => { + configPlatform, +}: PinpointInAppMessage & { + configPlatform?: ConfigPlatformType; +}): InAppMessageContent[] => { return ( message?.Content?.map(content => { const { @@ -252,8 +256,22 @@ export const extractContent = ({ PrimaryBtn, SecondaryBtn, } = content; - const defaultPrimaryButton = PrimaryBtn?.DefaultConfig; - const defaultSecondaryButton = SecondaryBtn?.DefaultConfig; + // Determine the button configuration based on the platform config or use default + const getButtonConfig = (button: any, defaultConfig: any) => { + return configPlatform && button && button[configPlatform] + ? { ...defaultConfig, ...button[configPlatform] } + : defaultConfig; + }; + + const defaultPrimaryButton = getButtonConfig( + PrimaryBtn, + PrimaryBtn?.DefaultConfig + ); + const defaultSecondaryButton = getButtonConfig( + SecondaryBtn, + SecondaryBtn?.DefaultConfig + ); + const extractedContent: InAppMessageContent = {}; if (BackgroundColor) { extractedContent.container = { @@ -331,3 +349,19 @@ export const extractMetadata = ({ priority: Priority, treatmentId: TreatmentId, }); + +export const mapOSPlatform = (os): ConfigPlatformType => { + // Check if running in a web browser + if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { + return 'Web'; + } + // Native environment checks + switch (os) { + case 'android': + return 'Android'; + case 'ios': + return 'IOS'; + default: + return 'DefaultConfig'; + } +}; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts index fe22b139b87..bb8b5f87fd6 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts @@ -12,13 +12,14 @@ import { extractMetadata, interpretLayout, isBeforeEndDate, + mapOSPlatform, matchesAttributes, matchesEventType, matchesMetrics, } from './helpers'; import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { defaultStorage, ConsoleLogger } from '@aws-amplify/core'; -import { SessionState } from '@aws-amplify/core/internals/utils'; +import { SessionState, getClientInfo } from '@aws-amplify/core/internals/utils'; const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount'; const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount'; @@ -86,10 +87,13 @@ export async function incrementMessageCounts(messageId: string): Promise { function normalizeMessages(messages: PinpointInAppMessage[]): InAppMessage[] { return messages.map(message => { const { CampaignId, InAppMessage } = message; + // const configPlatform = mapOSPlatform(Platform.OS); + const clientInfo = getClientInfo(); + const configPlatform = mapOSPlatform(clientInfo.platform); return { // Default to empty string in rare cases we don't have a campaignId id: CampaignId ?? '', - content: extractContent(message), + content: extractContent({ InAppMessage, configPlatform }), // Default to TOP_BANNER layout in rare cases we don't have a Layout layout: InAppMessage?.Layout ? interpretLayout(InAppMessage.Layout) diff --git a/packages/notifications/src/inAppMessaging/types/message.ts b/packages/notifications/src/inAppMessaging/types/message.ts index 0e84cacf9f9..10c3674a4a6 100644 --- a/packages/notifications/src/inAppMessaging/types/message.ts +++ b/packages/notifications/src/inAppMessaging/types/message.ts @@ -13,6 +13,8 @@ export type InAppMessageAction = 'CLOSE' | 'DEEP_LINK' | 'LINK'; export type InAppMessageTextAlign = 'center' | 'left' | 'right'; +export type ConfigPlatformType = 'Android' | 'IOS' | 'Web' | 'DefaultConfig'; + interface InAppMessageContainer { style?: InAppMessageStyle; } From 37eb6e5748bbabc648ad65f0dd37b7fa2e563287 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 28 Jan 2024 14:03:48 -0800 Subject: [PATCH 02/19] added default platform when getClientInfo returns an undefined platform --- .../src/inAppMessaging/providers/pinpoint/utils/helpers.ts | 2 +- .../providers/pinpoint/utils/messageProcessingHelpers.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index 4916efbb9de..7c5c00e3f5d 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -350,7 +350,7 @@ export const extractMetadata = ({ treatmentId: TreatmentId, }); -export const mapOSPlatform = (os): ConfigPlatformType => { +export const mapOSPlatform = (os: string): ConfigPlatformType => { // Check if running in a web browser if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return 'Web'; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts index bb8b5f87fd6..69126d27553 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts @@ -87,9 +87,8 @@ export async function incrementMessageCounts(messageId: string): Promise { function normalizeMessages(messages: PinpointInAppMessage[]): InAppMessage[] { return messages.map(message => { const { CampaignId, InAppMessage } = message; - // const configPlatform = mapOSPlatform(Platform.OS); - const clientInfo = getClientInfo(); - const configPlatform = mapOSPlatform(clientInfo.platform); + const { platform } = getClientInfo(); + const configPlatform = mapOSPlatform(platform || 'DefaultPlatform'); return { // Default to empty string in rare cases we don't have a campaignId id: CampaignId ?? '', From 965f58f261d5158fca9f65a516abf1ae8b6fc1ad Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 28 Jan 2024 15:16:49 -0800 Subject: [PATCH 03/19] mocking getClientInfo shouldn't override mock utils --- .../utils/processInAppMessages.test.ts | 16 +++++++++++----- .../pinpoint/utils/messageProcessingHelpers.ts | 7 +++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts index aee36230318..41c2c8c5bb1 100644 --- a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts @@ -19,11 +19,17 @@ import { import { initializeInAppMessaging } from '../../../src/inAppMessaging/providers/pinpoint/apis'; jest.mock('@aws-amplify/core'); -jest.mock('@aws-amplify/core/internals/utils', () => ({ - getClientInfo: jest.fn().mockImplementation(() => ({ - platform: 'android', - })), -})); +jest.mock('@aws-amplify/core/internals/utils', () => { + const originalModule = jest.requireActual( + '@aws-amplify/core/internals/utils' + ); + return { + ...originalModule, + getClientInfo: jest.fn().mockImplementation(() => ({ + platform: 'android', + })), + }; +}); jest.mock('../../../src/inAppMessaging/providers/pinpoint/utils/helpers'); const mockIsBeforeEndDate = isBeforeEndDate as jest.Mock; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts index 69126d27553..46a17683276 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts @@ -87,8 +87,11 @@ export async function incrementMessageCounts(messageId: string): Promise { function normalizeMessages(messages: PinpointInAppMessage[]): InAppMessage[] { return messages.map(message => { const { CampaignId, InAppMessage } = message; - const { platform } = getClientInfo(); - const configPlatform = mapOSPlatform(platform || 'DefaultPlatform'); + const clientInfo = getClientInfo(); + // DefaultPlatform will map to DefaultConfig. + const configPlatform = mapOSPlatform( + clientInfo?.platform || 'DefaultPlatform' + ); return { // Default to empty string in rare cases we don't have a campaignId id: CampaignId ?? '', From 7594f269049abdf2abe8acc268828618e80c6b68 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sat, 3 Feb 2024 21:08:38 -0800 Subject: [PATCH 04/19] moved logic to extractContent fn, updated tests --- .../pinpoint/utils/helpers.native.test.ts | 67 +++++++ .../providers/pinpoint/utils/helpers.test.ts | 64 +++---- .../utils/processInAppMessages.test.ts | 12 +- .../notifications/__tests__/testUtils/data.ts | 179 ++++-------------- .../providers/pinpoint/utils/helpers.ts | 37 ++-- .../utils/messageProcessingHelpers.ts | 10 +- .../src/inAppMessaging/types/message.ts | 2 +- 7 files changed, 160 insertions(+), 211 deletions(-) create mode 100644 packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts new file mode 100644 index 00000000000..08c20c7eb8c --- /dev/null +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -0,0 +1,67 @@ +/** + * @jest-environment node + */ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import cloneDeep from 'lodash/cloneDeep'; + +import { + extractContent, + mapOSPlatform, +} from '../../../../../src/inAppMessaging/providers/pinpoint/utils/helpers'; + +import { + nonBrowserConfigTestCases, + nativePinpointInAppMessagesWithOverrides, +} from '../../../../testUtils/data'; + +jest.mock('@aws-amplify/core'); + +jest.mock('@aws-amplify/core/internals/utils', () => { + const originalModule = jest.requireActual( + '@aws-amplify/core/internals/utils' + ); + return { + ...originalModule, + getClientInfo: jest.fn(), // Setup as a Jest mock function without implementation + }; +}); + +describe('InAppMessaging Provider Utils', () => { + describe('extractContent with overrides', () => { + describe('when running natively', () => { + nativePinpointInAppMessagesWithOverrides.forEach( + ({ message, expectedContent, configPlatform }) => { + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const pinpointInAppMessage = cloneDeep(message); + const content = extractContent(pinpointInAppMessage); + expect(content[0].primaryButton).toStrictEqual( + expectedContent[0].primaryButton + ); + expect(content[0].secondaryButton).toStrictEqual( + expectedContent[0].secondaryButton + ); + }); + } + ); + }); + }); + + describe('mapOSPlatform method', () => { + describe('when running natively', () => { + nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); + }); + }); + }); + }); +}); diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index a9a1c94eec8..97925b567a0 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -20,9 +20,8 @@ import { extractedContent, extractedMetadata, pinpointInAppMessage, - pinpointInAppMessagesWithOverrides, browserConfigTestCases, - nonBrowserConfigTestCases + browserPinpointInAppMessagesWithOverrides, } from '../../../../testUtils/data'; import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types'; @@ -30,6 +29,16 @@ jest.mock('@aws-amplify/core'); jest.mock('@aws-amplify/core/internals/providers/pinpoint'); jest.mock('../../../../../src/inAppMessaging/providers/pinpoint/utils'); +jest.mock('@aws-amplify/core/internals/utils', () => { + const originalModule = jest.requireActual( + '@aws-amplify/core/internals/utils' + ); + return { + ...originalModule, + getClientInfo: jest.fn(), // Setup as a Jest mock function without implementation + }; +}); + const HOUR_IN_MS = 1000 * 60 * 60; describe('InAppMessaging Provider Utils', () => { @@ -277,16 +286,29 @@ describe('InAppMessaging Provider Utils', () => { }); describe('extractContent with overrides', () => { - pinpointInAppMessagesWithOverrides.forEach(({ message, expectedContent, configPlatform }) => { - test(`correctly extracts content for ${configPlatform}`, () => { - const { InAppMessage } = cloneDeep(message); - const content = extractContent({ InAppMessage, configPlatform }); - expect(content[0].primaryButton).toStrictEqual(expectedContent[0].primaryButton); - expect(content[0].secondaryButton).toStrictEqual(expectedContent[0].secondaryButton); - }); + describe('when running in a browser', () => { + browserPinpointInAppMessagesWithOverrides.forEach( + ({ message, expectedContent, configPlatform }) => { + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const pinpointInAppMessage = cloneDeep(message); + const content = extractContent(pinpointInAppMessage); + expect(content[0].primaryButton).toStrictEqual( + expectedContent[0].primaryButton + ); + expect(content[0].secondaryButton).toStrictEqual( + expectedContent[0].secondaryButton + ); + }); + } + ); }); }); - describe('mapOSPlatform method', () => { describe('when running in a browser', () => { @@ -297,27 +319,5 @@ describe('InAppMessaging Provider Utils', () => { }); }); }); - - describe('when running natively', () => { - let originalWindow = window; - - beforeEach(() => { - //remove window object to mock behavior outside a browser - Object.defineProperty(global, 'window', {}); - }); - - afterEach(() => { - //remove window object to mock behavior outside a browser - Object.defineProperty(global, 'window', originalWindow); - }); - nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { - test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { - const result = mapOSPlatform(os); - expect(result).toBe(expectedPlatform); - }); - }); - }); }); - - }); diff --git a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts index 41c2c8c5bb1..ef764ec2d77 100644 --- a/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/utils/processInAppMessages.test.ts @@ -19,17 +19,7 @@ import { import { initializeInAppMessaging } from '../../../src/inAppMessaging/providers/pinpoint/apis'; jest.mock('@aws-amplify/core'); -jest.mock('@aws-amplify/core/internals/utils', () => { - const originalModule = jest.requireActual( - '@aws-amplify/core/internals/utils' - ); - return { - ...originalModule, - getClientInfo: jest.fn().mockImplementation(() => ({ - platform: 'android', - })), - }; -}); +jest.mock('@aws-amplify/core/internals/utils'); jest.mock('../../../src/inAppMessaging/providers/pinpoint/utils/helpers'); const mockIsBeforeEndDate = isBeforeEndDate as jest.Mock; diff --git a/packages/notifications/__tests__/testUtils/data.ts b/packages/notifications/__tests__/testUtils/data.ts index abb59e6df65..72c7e44e4d9 100644 --- a/packages/notifications/__tests__/testUtils/data.ts +++ b/packages/notifications/__tests__/testUtils/data.ts @@ -9,7 +9,6 @@ import { InAppMessagingEvent, } from '../../src/inAppMessaging/types'; import { PushNotificationMessage } from '../../src/pushNotifications'; -import { ConfigPlatformType } from '../../src/inAppMessaging/types/message'; export const credentials = { credentials: { @@ -185,13 +184,13 @@ export const pinpointInAppMessage: PinpointInAppMessage = { TreatmentId: 'T1', }; -export const pinpointInAppMessagesWithOverrides: { +export const browserPinpointInAppMessagesWithOverrides: { message: PinpointInAppMessage; expectedContent: InAppMessageContent[]; - configPlatform: ConfigPlatformType; + configPlatform?: string; // should match the }[] = [ { - configPlatform: 'Android', + configPlatform: 'web', expectedContent: [ { body: { @@ -205,29 +204,29 @@ export const pinpointInAppMessagesWithOverrides: { }, image: { src: imageUrl }, primaryButton: { - action: 'DEEP_LINK', + action: 'LINK', style: { backgroundColor: '#8888FF', borderRadius: 4, color: '#FF88FF', }, title: 'Close button', - url: 'android-app://primaryButtonLink', + url: 'https://webPrimaryButtonLink.com', }, secondaryButton: { - action: 'DEEP_LINK', + action: 'LINK', style: { backgroundColor: '#88FFFF', borderRadius: 4, color: '#FFFFFF', }, title: 'Link button', - url: 'android-app://secondaryButtonLink', + url: 'https://webSecondaryButtonLink.com', }, }, ], message: { - CampaignId: 'uuid-1', + CampaignId: 'uuid-3', InAppMessage: { Content: [ { @@ -252,9 +251,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Close button', TextColor: '#FF88FF', }, - Android: { - ButtonAction: 'DEEP_LINK', - Link: 'android-app://primaryButtonLink', + Web: { + ButtonAction: 'LINK', + Link: 'https://webPrimaryButtonLink.com', }, }, SecondaryBtn: { @@ -266,9 +265,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Link button', TextColor: '#FFFFFF', }, - Android: { - ButtonAction: 'DEEP_LINK', - Link: 'android-app://secondaryButtonLink', + Web: { + ButtonAction: 'LINK', + Link: 'https://webSecondaryButtonLink.com', }, }, }, @@ -301,8 +300,15 @@ export const pinpointInAppMessagesWithOverrides: { TreatmentId: 'T1', }, }, +]; + +export const nativePinpointInAppMessagesWithOverrides: { + message: PinpointInAppMessage; + expectedContent: InAppMessageContent[]; + configPlatform?: string; // should match the +}[] = [ { - configPlatform: 'IOS', + configPlatform: 'android', expectedContent: [ { body: { @@ -323,7 +329,7 @@ export const pinpointInAppMessagesWithOverrides: { color: '#FF88FF', }, title: 'Close button', - url: 'ios-app://primaryButtonLink', + url: 'android-app://primaryButtonLink', }, secondaryButton: { action: 'DEEP_LINK', @@ -333,12 +339,12 @@ export const pinpointInAppMessagesWithOverrides: { color: '#FFFFFF', }, title: 'Link button', - url: 'ios-app://secondaryButtonLink', + url: 'android-app://secondaryButtonLink', }, }, ], message: { - CampaignId: 'uuid-2', + CampaignId: 'uuid-1', InAppMessage: { Content: [ { @@ -363,9 +369,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Close button', TextColor: '#FF88FF', }, - IOS: { + Android: { ButtonAction: 'DEEP_LINK', - Link: 'ios-app://primaryButtonLink', + Link: 'android-app://primaryButtonLink', }, }, SecondaryBtn: { @@ -377,9 +383,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Link button', TextColor: '#FFFFFF', }, - IOS: { + Android: { ButtonAction: 'DEEP_LINK', - Link: 'ios-app://secondaryButtonLink', + Link: 'android-app://secondaryButtonLink', }, }, }, @@ -413,7 +419,7 @@ export const pinpointInAppMessagesWithOverrides: { }, }, { - configPlatform: 'Web', + configPlatform: 'ios', expectedContent: [ { body: { @@ -427,29 +433,29 @@ export const pinpointInAppMessagesWithOverrides: { }, image: { src: imageUrl }, primaryButton: { - action: 'LINK', + action: 'DEEP_LINK', style: { backgroundColor: '#8888FF', borderRadius: 4, color: '#FF88FF', }, title: 'Close button', - url: 'https://webPrimaryButtonLink.com', + url: 'ios-app://primaryButtonLink', }, secondaryButton: { - action: 'LINK', + action: 'DEEP_LINK', style: { backgroundColor: '#88FFFF', borderRadius: 4, color: '#FFFFFF', }, title: 'Link button', - url: 'https://webSecondaryButtonLink.com', + url: 'ios-app://secondaryButtonLink', }, }, ], message: { - CampaignId: 'uuid-3', + CampaignId: 'uuid-2', InAppMessage: { Content: [ { @@ -474,9 +480,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Close button', TextColor: '#FF88FF', }, - Web: { - ButtonAction: 'LINK', - Link: 'https://webPrimaryButtonLink.com', + IOS: { + ButtonAction: 'DEEP_LINK', + Link: 'ios-app://primaryButtonLink', }, }, SecondaryBtn: { @@ -488,112 +494,9 @@ export const pinpointInAppMessagesWithOverrides: { Text: 'Link button', TextColor: '#FFFFFF', }, - Web: { - ButtonAction: 'LINK', - Link: 'https://webSecondaryButtonLink.com', - }, - }, - }, - ], - Layout: 'TOP_BANNER', - CustomConfig: { foo: 'bar' }, - }, - Priority: 3, - Schedule: { - EndDate: '2021-01-01T00:00:00Z', - EventFilter: { - FilterType: 'SYSTEM', - Dimensions: { - Attributes: {}, - EventType: { - DimensionType: 'INCLUSIVE', - Values: ['clicked', 'swiped'], - }, - Metrics: {}, - }, - }, - QuietTime: { - End: undefined, - Start: undefined, - }, - }, - SessionCap: 0, - DailyCap: 0, - TotalCap: 0, - TreatmentId: 'T1', - }, - }, - { - configPlatform: 'DefaultConfig', - expectedContent: [ - { - body: { - content: 'Body content', - style: { color: '#FF8888', textAlign: 'left' }, - }, - container: { style: { backgroundColor: '#FFFF88' } }, - header: { - content: 'Header content', - style: { color: '#88FF88', textAlign: 'center' }, - }, - image: { src: imageUrl }, - primaryButton: { - action: 'CLOSE', - style: { - backgroundColor: '#8888FF', - borderRadius: 4, - color: '#FF88FF', - }, - title: 'Close button', - url: undefined, - }, - secondaryButton: { - action: 'LINK', - style: { - backgroundColor: '#88FFFF', - borderRadius: 4, - color: '#FFFFFF', - }, - title: 'Link button', - url: 'http://link.fakeurl', - }, - }, - ], - message: { - CampaignId: 'uuid-4', - InAppMessage: { - Content: [ - { - BackgroundColor: '#FFFF88', - BodyConfig: { - Alignment: 'LEFT', - Body: 'Body content', - TextColor: '#FF8888', - }, - HeaderConfig: { - Alignment: 'CENTER', - Header: 'Header content', - TextColor: '#88FF88', - }, - ImageUrl: imageUrl, - PrimaryBtn: { - DefaultConfig: { - BackgroundColor: '#8888FF', - BorderRadius: 4, - ButtonAction: 'CLOSE', - Link: undefined, - Text: 'Close button', - TextColor: '#FF88FF', - }, - }, - SecondaryBtn: { - DefaultConfig: { - BackgroundColor: '#88FFFF', - BorderRadius: 4, - ButtonAction: 'LINK', - Link: 'http://link.fakeurl', - Text: 'Link button', - TextColor: '#FFFFFF', + IOS: { + ButtonAction: 'DEEP_LINK', + Link: 'ios-app://secondaryButtonLink', }, }, }, diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index 7c5c00e3f5d..d817852ac01 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -2,7 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { ConsoleLogger } from '@aws-amplify/core'; -import { InAppMessagingAction } from '@aws-amplify/core/internals/utils'; +import { + InAppMessagingAction, + getClientInfo, +} from '@aws-amplify/core/internals/utils'; import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import isEmpty from 'lodash/isEmpty.js'; import { @@ -19,7 +22,7 @@ import { resolveConfig } from './resolveConfig'; import { resolveCredentials } from './resolveCredentials'; import { CATEGORY } from './constants'; import { getInAppMessagingUserAgentString } from './userAgent'; -import { ConfigPlatformType } from '../../../types/message'; +import { ButtonConfigPlatform } from '../../../types/message'; const DELIVERY_TYPE = 'IN_APP_MESSAGE'; @@ -242,10 +245,9 @@ export const interpretLayout = ( export const extractContent = ({ InAppMessage: message, - configPlatform, -}: PinpointInAppMessage & { - configPlatform?: ConfigPlatformType; -}): InAppMessageContent[] => { +}: PinpointInAppMessage): InAppMessageContent[] => { + const clientInfo = getClientInfo(); + const configPlatform = mapOSPlatform(clientInfo?.platform); return ( message?.Content?.map(content => { const { @@ -256,21 +258,14 @@ export const extractContent = ({ PrimaryBtn, SecondaryBtn, } = content; - // Determine the button configuration based on the platform config or use default - const getButtonConfig = (button: any, defaultConfig: any) => { - return configPlatform && button && button[configPlatform] - ? { ...defaultConfig, ...button[configPlatform] } - : defaultConfig; - }; - const defaultPrimaryButton = getButtonConfig( - PrimaryBtn, - PrimaryBtn?.DefaultConfig - ); - const defaultSecondaryButton = getButtonConfig( - SecondaryBtn, - SecondaryBtn?.DefaultConfig - ); + const getButtonConfig = (button: any) => ({ + ...button?.DefaultConfig, + ...button?.[configPlatform], + }); + + const defaultPrimaryButton = getButtonConfig(PrimaryBtn); + const defaultSecondaryButton = getButtonConfig(SecondaryBtn); const extractedContent: InAppMessageContent = {}; if (BackgroundColor) { @@ -350,7 +345,7 @@ export const extractMetadata = ({ treatmentId: TreatmentId, }); -export const mapOSPlatform = (os: string): ConfigPlatformType => { +export const mapOSPlatform = (os?: string): ButtonConfigPlatform => { // Check if running in a web browser if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return 'Web'; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts index 46a17683276..fe22b139b87 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts @@ -12,14 +12,13 @@ import { extractMetadata, interpretLayout, isBeforeEndDate, - mapOSPlatform, matchesAttributes, matchesEventType, matchesMetrics, } from './helpers'; import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { defaultStorage, ConsoleLogger } from '@aws-amplify/core'; -import { SessionState, getClientInfo } from '@aws-amplify/core/internals/utils'; +import { SessionState } from '@aws-amplify/core/internals/utils'; const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount'; const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount'; @@ -87,15 +86,10 @@ export async function incrementMessageCounts(messageId: string): Promise { function normalizeMessages(messages: PinpointInAppMessage[]): InAppMessage[] { return messages.map(message => { const { CampaignId, InAppMessage } = message; - const clientInfo = getClientInfo(); - // DefaultPlatform will map to DefaultConfig. - const configPlatform = mapOSPlatform( - clientInfo?.platform || 'DefaultPlatform' - ); return { // Default to empty string in rare cases we don't have a campaignId id: CampaignId ?? '', - content: extractContent({ InAppMessage, configPlatform }), + content: extractContent(message), // Default to TOP_BANNER layout in rare cases we don't have a Layout layout: InAppMessage?.Layout ? interpretLayout(InAppMessage.Layout) diff --git a/packages/notifications/src/inAppMessaging/types/message.ts b/packages/notifications/src/inAppMessaging/types/message.ts index 10c3674a4a6..5bb37ea2ca8 100644 --- a/packages/notifications/src/inAppMessaging/types/message.ts +++ b/packages/notifications/src/inAppMessaging/types/message.ts @@ -13,7 +13,7 @@ export type InAppMessageAction = 'CLOSE' | 'DEEP_LINK' | 'LINK'; export type InAppMessageTextAlign = 'center' | 'left' | 'right'; -export type ConfigPlatformType = 'Android' | 'IOS' | 'Web' | 'DefaultConfig'; +export type ButtonConfigPlatform = 'Android' | 'IOS' | 'Web' | 'DefaultConfig'; interface InAppMessageContainer { style?: InAppMessageStyle; From 91df63b76b0154a7e205317f05ff2de9ff44ff93 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sat, 3 Feb 2024 22:14:02 -0800 Subject: [PATCH 05/19] exposed internal type InAppMessageButton --- packages/core/src/index.ts | 2 +- packages/core/src/types/core.ts | 2 ++ .../inAppMessaging/providers/pinpoint/utils/helpers.ts | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 05c753c7e6b..16587014ac5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -60,7 +60,7 @@ export { sessionStorage, sharedInMemoryStorage, } from './storage'; -export { KeyValueStorageInterface } from './types'; +export { KeyValueStorageInterface, InAppMessageButton } from './types'; // Cache exports export { Cache } from './Cache'; diff --git a/packages/core/src/types/core.ts b/packages/core/src/types/core.ts index b66f11462e1..28f53fff32c 100644 --- a/packages/core/src/types/core.ts +++ b/packages/core/src/types/core.ts @@ -49,3 +49,5 @@ export type DelayFunction = ( args?: any[], error?: unknown ) => number | false; + +export { InAppMessageButton } from "../awsClients/pinpoint/types"; \ No newline at end of file diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index d817852ac01..ff2d1278270 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -1,10 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ConsoleLogger } from '@aws-amplify/core'; +import { ConsoleLogger, InAppMessageButton } from '@aws-amplify/core'; import { InAppMessagingAction, - getClientInfo, + getClientInfo } from '@aws-amplify/core/internals/utils'; import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import isEmpty from 'lodash/isEmpty.js'; @@ -259,13 +259,13 @@ export const extractContent = ({ SecondaryBtn, } = content; - const getButtonConfig = (button: any) => ({ + const getButtonConfig = (button?: InAppMessageButton) => ({ ...button?.DefaultConfig, ...button?.[configPlatform], }); - const defaultPrimaryButton = getButtonConfig(PrimaryBtn); - const defaultSecondaryButton = getButtonConfig(SecondaryBtn); + const defaultPrimaryButton = PrimaryBtn ? getButtonConfig(PrimaryBtn) : undefined; + const defaultSecondaryButton = SecondaryBtn ? getButtonConfig(SecondaryBtn) : undefined; const extractedContent: InAppMessageContent = {}; if (BackgroundColor) { From 71d885159b3ee29b87217a04f319eac069689ffa Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sat, 3 Feb 2024 22:25:13 -0800 Subject: [PATCH 06/19] added empty line --- packages/core/src/types/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/types/core.ts b/packages/core/src/types/core.ts index 28f53fff32c..8a6f83c4593 100644 --- a/packages/core/src/types/core.ts +++ b/packages/core/src/types/core.ts @@ -50,4 +50,4 @@ export type DelayFunction = ( error?: unknown ) => number | false; -export { InAppMessageButton } from "../awsClients/pinpoint/types"; \ No newline at end of file +export { InAppMessageButton } from "../awsClients/pinpoint/types"; From 556f739a8013bcd8786582f9c89111c37443681a Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sat, 3 Feb 2024 23:12:25 -0800 Subject: [PATCH 07/19] return immediately if os is falsy --- .../src/inAppMessaging/providers/pinpoint/utils/helpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index ff2d1278270..fa8b1dfceed 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -346,6 +346,7 @@ export const extractMetadata = ({ }); export const mapOSPlatform = (os?: string): ButtonConfigPlatform => { + if(!os) return 'DefaultConfig' // Check if running in a web browser if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return 'Web'; From 8448b9cd94142ce94914b2489fa15cd545fb1bbc Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sat, 3 Feb 2024 23:24:45 -0800 Subject: [PATCH 08/19] fixed lint warning --- .../src/inAppMessaging/providers/pinpoint/utils/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index fa8b1dfceed..0077260014f 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -346,7 +346,7 @@ export const extractMetadata = ({ }); export const mapOSPlatform = (os?: string): ButtonConfigPlatform => { - if(!os) return 'DefaultConfig' + if(!os) return 'DefaultConfig'; // Check if running in a web browser if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return 'Web'; From 8c56fe453a501179f477c2fe5fbb1a5ff28d0695 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 11 Feb 2024 18:07:05 -0800 Subject: [PATCH 09/19] pinpoint internal type exports, mergeOverride test util, simplified data object --- .../core/src/awsClients/pinpoint/index.ts | 2 +- packages/core/src/index.ts | 2 +- packages/core/src/types/core.ts | 2 - .../pinpoint/utils/helpers.native.test.ts | 43 +- .../providers/pinpoint/utils/helpers.test.ts | 41 +- .../notifications/__tests__/testUtils/data.ts | 409 +++--------------- .../mergeInAppMessageWithOverrides.ts | 59 +++ .../providers/pinpoint/utils/helpers.ts | 4 +- 8 files changed, 168 insertions(+), 394 deletions(-) create mode 100644 packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts diff --git a/packages/core/src/awsClients/pinpoint/index.ts b/packages/core/src/awsClients/pinpoint/index.ts index 95bfc0951b3..480f7aeb345 100644 --- a/packages/core/src/awsClients/pinpoint/index.ts +++ b/packages/core/src/awsClients/pinpoint/index.ts @@ -12,4 +12,4 @@ export { UpdateEndpointInput, UpdateEndpointOutput, } from './updateEndpoint'; -export { Event, InAppMessageCampaign, EventsBatch } from './types'; +export { Event, InAppMessageCampaign, EventsBatch, InAppMessageButton, OverrideButtonConfiguration } from './types'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 16587014ac5..05c753c7e6b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -60,7 +60,7 @@ export { sessionStorage, sharedInMemoryStorage, } from './storage'; -export { KeyValueStorageInterface, InAppMessageButton } from './types'; +export { KeyValueStorageInterface } from './types'; // Cache exports export { Cache } from './Cache'; diff --git a/packages/core/src/types/core.ts b/packages/core/src/types/core.ts index 8a6f83c4593..b66f11462e1 100644 --- a/packages/core/src/types/core.ts +++ b/packages/core/src/types/core.ts @@ -49,5 +49,3 @@ export type DelayFunction = ( args?: any[], error?: unknown ) => number | false; - -export { InAppMessageButton } from "../awsClients/pinpoint/types"; diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts index 08c20c7eb8c..9f4d8f0de52 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -4,8 +4,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import cloneDeep from 'lodash/cloneDeep'; - import { extractContent, mapOSPlatform, @@ -13,8 +11,11 @@ import { import { nonBrowserConfigTestCases, - nativePinpointInAppMessagesWithOverrides, + pinpointInAppMessage, + extractedContent, + nativeButtonOverrides, } from '../../../../testUtils/data'; +import { mergeExpectedContentWithExpectedOverride, mergeInAppMessageWithOverrides } from '../../../../testUtils/mergeInAppMessageWithOverrides'; jest.mock('@aws-amplify/core'); @@ -29,10 +30,24 @@ jest.mock('@aws-amplify/core/internals/utils', () => { }); describe('InAppMessaging Provider Utils', () => { + describe('mapOSPlatform method', () => { + describe('when running natively', () => { + nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); + }); + }); + }); + }); + describe('extractContent with overrides', () => { describe('when running natively', () => { - nativePinpointInAppMessagesWithOverrides.forEach( - ({ message, expectedContent, configPlatform }) => { + nativeButtonOverrides.forEach( + ({buttonOverrides, configPlatform }) => { + const message=mergeInAppMessageWithOverrides(pinpointInAppMessage,configPlatform, buttonOverrides); + const expectedContent = mergeExpectedContentWithExpectedOverride(extractedContent[0],buttonOverrides); + test(`correctly extracts content for ${configPlatform}`, () => { const utils = require('@aws-amplify/core/internals/utils'); // Dynamically override the mock for getClientInfo @@ -40,28 +55,16 @@ describe('InAppMessaging Provider Utils', () => { platform: configPlatform, })); - const pinpointInAppMessage = cloneDeep(message); - const content = extractContent(pinpointInAppMessage); + const content = extractContent(message); expect(content[0].primaryButton).toStrictEqual( - expectedContent[0].primaryButton + expectedContent.primaryButton ); expect(content[0].secondaryButton).toStrictEqual( - expectedContent[0].secondaryButton + expectedContent.secondaryButton ); }); } ); }); }); - - describe('mapOSPlatform method', () => { - describe('when running natively', () => { - nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { - test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { - const result = mapOSPlatform(os); - expect(result).toBe(expectedPlatform); - }); - }); - }); - }); }); diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 97925b567a0..544c2954950 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -21,9 +21,10 @@ import { extractedMetadata, pinpointInAppMessage, browserConfigTestCases, - browserPinpointInAppMessagesWithOverrides, + browserButtonOverrides, } from '../../../../testUtils/data'; -import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types'; +import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types'; +import { mergeExpectedContentWithExpectedOverride, mergeInAppMessageWithOverrides } from '../../../../testUtils/mergeInAppMessageWithOverrides'; jest.mock('@aws-amplify/core'); jest.mock('@aws-amplify/core/internals/providers/pinpoint'); @@ -285,10 +286,24 @@ describe('InAppMessaging Provider Utils', () => { expect(extractMetadata(message)).toStrictEqual(extractedMetadata); }); + describe('mapOSPlatform method', () => { + describe('when running in a browser', () => { + browserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); + }); + }); + }); + }); + describe('extractContent with overrides', () => { describe('when running in a browser', () => { - browserPinpointInAppMessagesWithOverrides.forEach( - ({ message, expectedContent, configPlatform }) => { + browserButtonOverrides.forEach( + ({buttonOverrides, configPlatform }) => { + const message=mergeInAppMessageWithOverrides(pinpointInAppMessage,configPlatform, buttonOverrides); + const expectedContent = mergeExpectedContentWithExpectedOverride(extractedContent[0], buttonOverrides); + test(`correctly extracts content for ${configPlatform}`, () => { const utils = require('@aws-amplify/core/internals/utils'); // Dynamically override the mock for getClientInfo @@ -296,28 +311,16 @@ describe('InAppMessaging Provider Utils', () => { platform: configPlatform, })); - const pinpointInAppMessage = cloneDeep(message); - const content = extractContent(pinpointInAppMessage); + const content = extractContent(message); expect(content[0].primaryButton).toStrictEqual( - expectedContent[0].primaryButton + expectedContent.primaryButton ); expect(content[0].secondaryButton).toStrictEqual( - expectedContent[0].secondaryButton + expectedContent.secondaryButton ); }); } ); }); }); - - describe('mapOSPlatform method', () => { - describe('when running in a browser', () => { - browserConfigTestCases.forEach(({ os, expectedPlatform }) => { - test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { - const result = mapOSPlatform(os); - expect(result).toBe(expectedPlatform); - }); - }); - }); - }); }); diff --git a/packages/notifications/__tests__/testUtils/data.ts b/packages/notifications/__tests__/testUtils/data.ts index 72c7e44e4d9..10d70f6a962 100644 --- a/packages/notifications/__tests__/testUtils/data.ts +++ b/packages/notifications/__tests__/testUtils/data.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint'; -import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; +import { type InAppMessageCampaign as PinpointInAppMessage, OverrideButtonConfiguration } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { InAppMessage, InAppMessageContent, @@ -184,354 +184,7 @@ export const pinpointInAppMessage: PinpointInAppMessage = { TreatmentId: 'T1', }; -export const browserPinpointInAppMessagesWithOverrides: { - message: PinpointInAppMessage; - expectedContent: InAppMessageContent[]; - configPlatform?: string; // should match the -}[] = [ - { - configPlatform: 'web', - expectedContent: [ - { - body: { - content: 'Body content', - style: { color: '#FF8888', textAlign: 'left' }, - }, - container: { style: { backgroundColor: '#FFFF88' } }, - header: { - content: 'Header content', - style: { color: '#88FF88', textAlign: 'center' }, - }, - image: { src: imageUrl }, - primaryButton: { - action: 'LINK', - style: { - backgroundColor: '#8888FF', - borderRadius: 4, - color: '#FF88FF', - }, - title: 'Close button', - url: 'https://webPrimaryButtonLink.com', - }, - secondaryButton: { - action: 'LINK', - style: { - backgroundColor: '#88FFFF', - borderRadius: 4, - color: '#FFFFFF', - }, - title: 'Link button', - url: 'https://webSecondaryButtonLink.com', - }, - }, - ], - message: { - CampaignId: 'uuid-3', - InAppMessage: { - Content: [ - { - BackgroundColor: '#FFFF88', - BodyConfig: { - Alignment: 'LEFT', - Body: 'Body content', - TextColor: '#FF8888', - }, - HeaderConfig: { - Alignment: 'CENTER', - Header: 'Header content', - TextColor: '#88FF88', - }, - ImageUrl: imageUrl, - PrimaryBtn: { - DefaultConfig: { - BackgroundColor: '#8888FF', - BorderRadius: 4, - ButtonAction: 'CLOSE', - Link: undefined, - Text: 'Close button', - TextColor: '#FF88FF', - }, - Web: { - ButtonAction: 'LINK', - Link: 'https://webPrimaryButtonLink.com', - }, - }, - SecondaryBtn: { - DefaultConfig: { - BackgroundColor: '#88FFFF', - BorderRadius: 4, - ButtonAction: 'LINK', - Link: 'http://link.fakeurl', - Text: 'Link button', - TextColor: '#FFFFFF', - }, - Web: { - ButtonAction: 'LINK', - Link: 'https://webSecondaryButtonLink.com', - }, - }, - }, - ], - Layout: 'TOP_BANNER', - CustomConfig: { foo: 'bar' }, - }, - Priority: 3, - Schedule: { - EndDate: '2021-01-01T00:00:00Z', - EventFilter: { - FilterType: 'SYSTEM', - Dimensions: { - Attributes: {}, - EventType: { - DimensionType: 'INCLUSIVE', - Values: ['clicked', 'swiped'], - }, - Metrics: {}, - }, - }, - QuietTime: { - End: undefined, - Start: undefined, - }, - }, - SessionCap: 0, - DailyCap: 0, - TotalCap: 0, - TreatmentId: 'T1', - }, - }, -]; - -export const nativePinpointInAppMessagesWithOverrides: { - message: PinpointInAppMessage; - expectedContent: InAppMessageContent[]; - configPlatform?: string; // should match the -}[] = [ - { - configPlatform: 'android', - expectedContent: [ - { - body: { - content: 'Body content', - style: { color: '#FF8888', textAlign: 'left' }, - }, - container: { style: { backgroundColor: '#FFFF88' } }, - header: { - content: 'Header content', - style: { color: '#88FF88', textAlign: 'center' }, - }, - image: { src: imageUrl }, - primaryButton: { - action: 'DEEP_LINK', - style: { - backgroundColor: '#8888FF', - borderRadius: 4, - color: '#FF88FF', - }, - title: 'Close button', - url: 'android-app://primaryButtonLink', - }, - secondaryButton: { - action: 'DEEP_LINK', - style: { - backgroundColor: '#88FFFF', - borderRadius: 4, - color: '#FFFFFF', - }, - title: 'Link button', - url: 'android-app://secondaryButtonLink', - }, - }, - ], - message: { - CampaignId: 'uuid-1', - InAppMessage: { - Content: [ - { - BackgroundColor: '#FFFF88', - BodyConfig: { - Alignment: 'LEFT', - Body: 'Body content', - TextColor: '#FF8888', - }, - HeaderConfig: { - Alignment: 'CENTER', - Header: 'Header content', - TextColor: '#88FF88', - }, - ImageUrl: imageUrl, - PrimaryBtn: { - DefaultConfig: { - BackgroundColor: '#8888FF', - BorderRadius: 4, - ButtonAction: 'CLOSE', - Link: undefined, - Text: 'Close button', - TextColor: '#FF88FF', - }, - Android: { - ButtonAction: 'DEEP_LINK', - Link: 'android-app://primaryButtonLink', - }, - }, - SecondaryBtn: { - DefaultConfig: { - BackgroundColor: '#88FFFF', - BorderRadius: 4, - ButtonAction: 'LINK', - Link: 'http://link.fakeurl', - Text: 'Link button', - TextColor: '#FFFFFF', - }, - Android: { - ButtonAction: 'DEEP_LINK', - Link: 'android-app://secondaryButtonLink', - }, - }, - }, - ], - Layout: 'TOP_BANNER', - CustomConfig: { foo: 'bar' }, - }, - Priority: 3, - Schedule: { - EndDate: '2021-01-01T00:00:00Z', - EventFilter: { - FilterType: 'SYSTEM', - Dimensions: { - Attributes: {}, - EventType: { - DimensionType: 'INCLUSIVE', - Values: ['clicked', 'swiped'], - }, - Metrics: {}, - }, - }, - QuietTime: { - End: undefined, - Start: undefined, - }, - }, - SessionCap: 0, - DailyCap: 0, - TotalCap: 0, - TreatmentId: 'T1', - }, - }, - { - configPlatform: 'ios', - expectedContent: [ - { - body: { - content: 'Body content', - style: { color: '#FF8888', textAlign: 'left' }, - }, - container: { style: { backgroundColor: '#FFFF88' } }, - header: { - content: 'Header content', - style: { color: '#88FF88', textAlign: 'center' }, - }, - image: { src: imageUrl }, - primaryButton: { - action: 'DEEP_LINK', - style: { - backgroundColor: '#8888FF', - borderRadius: 4, - color: '#FF88FF', - }, - title: 'Close button', - url: 'ios-app://primaryButtonLink', - }, - secondaryButton: { - action: 'DEEP_LINK', - style: { - backgroundColor: '#88FFFF', - borderRadius: 4, - color: '#FFFFFF', - }, - title: 'Link button', - url: 'ios-app://secondaryButtonLink', - }, - }, - ], - message: { - CampaignId: 'uuid-2', - InAppMessage: { - Content: [ - { - BackgroundColor: '#FFFF88', - BodyConfig: { - Alignment: 'LEFT', - Body: 'Body content', - TextColor: '#FF8888', - }, - HeaderConfig: { - Alignment: 'CENTER', - Header: 'Header content', - TextColor: '#88FF88', - }, - ImageUrl: imageUrl, - PrimaryBtn: { - DefaultConfig: { - BackgroundColor: '#8888FF', - BorderRadius: 4, - ButtonAction: 'CLOSE', - Link: undefined, - Text: 'Close button', - TextColor: '#FF88FF', - }, - IOS: { - ButtonAction: 'DEEP_LINK', - Link: 'ios-app://primaryButtonLink', - }, - }, - SecondaryBtn: { - DefaultConfig: { - BackgroundColor: '#88FFFF', - BorderRadius: 4, - ButtonAction: 'LINK', - Link: 'http://link.fakeurl', - Text: 'Link button', - TextColor: '#FFFFFF', - }, - IOS: { - ButtonAction: 'DEEP_LINK', - Link: 'ios-app://secondaryButtonLink', - }, - }, - }, - ], - Layout: 'TOP_BANNER', - CustomConfig: { foo: 'bar' }, - }, - Priority: 3, - Schedule: { - EndDate: '2021-01-01T00:00:00Z', - EventFilter: { - FilterType: 'SYSTEM', - Dimensions: { - Attributes: {}, - EventType: { - DimensionType: 'INCLUSIVE', - Values: ['clicked', 'swiped'], - }, - Metrics: {}, - }, - }, - QuietTime: { - End: undefined, - Start: undefined, - }, - }, - SessionCap: 0, - DailyCap: 0, - TotalCap: 0, - TreatmentId: 'T1', - }, - }, -]; - -export const extractedContent = [ +export const extractedContent:InAppMessageContent[] = [ { body: { content: 'Body content', @@ -558,6 +211,64 @@ export const extractedContent = [ }, ]; + +export const nativeButtonOverrides:{ + configPlatform:'ios' | 'android'; + buttonOverrides:{ + primaryButton:OverrideButtonConfiguration, + secondaryButton:OverrideButtonConfiguration + }; +}[] = [ + { + configPlatform:'android', + buttonOverrides:{ + primaryButton:{ + ButtonAction:'DEEP_LINK', + Link:'android-app://primaryButtonLink', + }, + secondaryButton:{ + ButtonAction:'LINK', + Link:'android-app://secondaryButtonLink', + } + } + }, + { + configPlatform:'ios', + buttonOverrides:{ + primaryButton:{ + ButtonAction:'DEEP_LINK', + Link:'ios-app://primaryButtonLink', + }, + secondaryButton:{ + ButtonAction:'LINK', + Link:'ios-app://secondaryButtonLink', + } + } + + } +] +export const browserButtonOverrides:{ + configPlatform:'web'; + buttonOverrides:{ + primaryButton:OverrideButtonConfiguration, + secondaryButton:OverrideButtonConfiguration + }; +}[] = [{ + configPlatform:'web', + buttonOverrides:{ + primaryButton:{ + ButtonAction:'LINK', + Link:'https://webPrimaryButtonLink.com', + }, + secondaryButton:{ + ButtonAction:'LINK', + Link:'https://webSecondaryButtonLink.com', + } + } + + } +] + export const extractedMetadata = { customData: { foo: 'bar' }, endDate: '2021-01-01T00:00:00Z', diff --git a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts new file mode 100644 index 00000000000..6d93d8f8335 --- /dev/null +++ b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts @@ -0,0 +1,59 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { cloneDeep } from "lodash"; +import { InAppMessageCampaign, OverrideButtonConfiguration } from "@aws-amplify/core/internals/aws-clients/pinpoint"; +import { InAppMessageButton, InAppMessageContent } from "../../src/inAppMessaging/types/message"; +import { mapOSPlatform } from "../../src/inAppMessaging/providers/pinpoint/utils/helpers"; + +export const mergeInAppMessageWithOverrides:( + pinpointInAppMessage:InAppMessageCampaign, + platform:'android'|'ios'|'web', + buttonOverrides?:{ + primaryButton:OverrideButtonConfiguration, + secondaryButton:OverrideButtonConfiguration + } + ) =>InAppMessageCampaign = (pinpointInAppMessage, platform, buttonOverrides)=>{ + const message= cloneDeep(pinpointInAppMessage); + const configPlatform = mapOSPlatform(platform); + if (message?.InAppMessage?.Content) { + message.InAppMessage.Content[0] = { + ...message.InAppMessage.Content[0], + PrimaryBtn:{ + ...message.InAppMessage.Content[0].PrimaryBtn, + [configPlatform]:buttonOverrides?.primaryButton + }, + SecondaryBtn:{ + ...message.InAppMessage.Content[0].SecondaryBtn, + [configPlatform]:buttonOverrides?.secondaryButton + } + } + } + return message +} + +export const mergeExpectedContentWithExpectedOverride:( + inAppMessage:InAppMessageContent, + expectedButtonConfig: { + primaryButton:OverrideButtonConfiguration, + secondaryButton:OverrideButtonConfiguration + } +)=>InAppMessageContent = (inAppMessage, expectedButtonConfig)=>{ + let expectedContent = cloneDeep(inAppMessage); + if (expectedContent) { + expectedContent ={ + ...expectedContent, + primaryButton:{ + ...expectedContent.primaryButton, + action:expectedButtonConfig.primaryButton.ButtonAction, + url:expectedButtonConfig.primaryButton.Link + } as InAppMessageButton, + secondaryButton:{ + ...expectedContent.secondaryButton, + action:expectedButtonConfig.secondaryButton.ButtonAction, + url:expectedButtonConfig.secondaryButton.Link + } as InAppMessageButton + } + } + return expectedContent +} \ No newline at end of file diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index 0077260014f..fb12d1cfcce 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ConsoleLogger, InAppMessageButton } from '@aws-amplify/core'; +import { ConsoleLogger } from '@aws-amplify/core'; import { InAppMessagingAction, getClientInfo } from '@aws-amplify/core/internals/utils'; -import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint'; +import type { InAppMessageCampaign as PinpointInAppMessage, InAppMessageButton } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import isEmpty from 'lodash/isEmpty.js'; import { InAppMessage, From 2439885970abe60ac5cfa8d6e707011d9c403d00 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 11 Feb 2024 18:58:22 -0800 Subject: [PATCH 10/19] removed unnecessary spread operator --- .../mergeInAppMessageWithOverrides.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts index 6d93d8f8335..18f336f1098 100644 --- a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts +++ b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts @@ -34,26 +34,23 @@ export const mergeInAppMessageWithOverrides:( export const mergeExpectedContentWithExpectedOverride:( inAppMessage:InAppMessageContent, - expectedButtonConfig: { + expectedButtonConfig: { primaryButton:OverrideButtonConfiguration, secondaryButton:OverrideButtonConfiguration } )=>InAppMessageContent = (inAppMessage, expectedButtonConfig)=>{ let expectedContent = cloneDeep(inAppMessage); if (expectedContent) { - expectedContent ={ - ...expectedContent, - primaryButton:{ - ...expectedContent.primaryButton, - action:expectedButtonConfig.primaryButton.ButtonAction, - url:expectedButtonConfig.primaryButton.Link - } as InAppMessageButton, - secondaryButton:{ - ...expectedContent.secondaryButton, - action:expectedButtonConfig.secondaryButton.ButtonAction, - url:expectedButtonConfig.secondaryButton.Link - } as InAppMessageButton - } + expectedContent.primaryButton = { + ...expectedContent.primaryButton, + action:expectedButtonConfig.primaryButton.ButtonAction, + url:expectedButtonConfig.primaryButton.Link + } as InAppMessageButton + expectedContent.secondaryButton = { + ...expectedContent.secondaryButton, + action:expectedButtonConfig.secondaryButton.ButtonAction, + url:expectedButtonConfig.secondaryButton.Link + } as InAppMessageButton } return expectedContent } \ No newline at end of file From 5307825aea9164bfad86796d9f32e82034f432ae Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 11 Feb 2024 19:04:27 -0800 Subject: [PATCH 11/19] refactored merging fn --- .../mergeInAppMessageWithOverrides.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts index 18f336f1098..d5cfceb7c0a 100644 --- a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts +++ b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts @@ -40,17 +40,15 @@ export const mergeExpectedContentWithExpectedOverride:( } )=>InAppMessageContent = (inAppMessage, expectedButtonConfig)=>{ let expectedContent = cloneDeep(inAppMessage); - if (expectedContent) { - expectedContent.primaryButton = { - ...expectedContent.primaryButton, - action:expectedButtonConfig.primaryButton.ButtonAction, - url:expectedButtonConfig.primaryButton.Link - } as InAppMessageButton - expectedContent.secondaryButton = { - ...expectedContent.secondaryButton, - action:expectedButtonConfig.secondaryButton.ButtonAction, - url:expectedButtonConfig.secondaryButton.Link - } as InAppMessageButton - } + expectedContent.primaryButton = { + ...expectedContent.primaryButton, + action:expectedButtonConfig.primaryButton.ButtonAction, + url:expectedButtonConfig.primaryButton.Link + } as InAppMessageButton + expectedContent.secondaryButton = { + ...expectedContent.secondaryButton, + action:expectedButtonConfig.secondaryButton.ButtonAction, + url:expectedButtonConfig.secondaryButton.Link + } as InAppMessageButton return expectedContent } \ No newline at end of file From a7d9f4309984b36bc4d1c7612ba849494e84617c Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 12:14:34 -0800 Subject: [PATCH 12/19] prettier --- .../core/src/awsClients/pinpoint/index.ts | 8 +- .../pinpoint/utils/helpers.native.test.ts | 47 ++++---- .../providers/pinpoint/utils/helpers.test.ts | 56 +++++----- .../notifications/__tests__/testUtils/data.ts | 101 +++++++++--------- .../mergeInAppMessageWithOverrides.ts | 52 +++++---- .../providers/pinpoint/utils/helpers.ts | 17 ++- 6 files changed, 159 insertions(+), 122 deletions(-) diff --git a/packages/core/src/awsClients/pinpoint/index.ts b/packages/core/src/awsClients/pinpoint/index.ts index 480f7aeb345..85477b4e6e8 100644 --- a/packages/core/src/awsClients/pinpoint/index.ts +++ b/packages/core/src/awsClients/pinpoint/index.ts @@ -12,4 +12,10 @@ export { UpdateEndpointInput, UpdateEndpointOutput, } from './updateEndpoint'; -export { Event, InAppMessageCampaign, EventsBatch, InAppMessageButton, OverrideButtonConfiguration } from './types'; +export { + Event, + InAppMessageCampaign, + EventsBatch, + InAppMessageButton, + OverrideButtonConfiguration, +} from './types'; diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts index 9f4d8f0de52..66aa08285fc 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -21,7 +21,7 @@ jest.mock('@aws-amplify/core'); jest.mock('@aws-amplify/core/internals/utils', () => { const originalModule = jest.requireActual( - '@aws-amplify/core/internals/utils' + '@aws-amplify/core/internals/utils', ); return { ...originalModule, @@ -43,28 +43,33 @@ describe('InAppMessaging Provider Utils', () => { describe('extractContent with overrides', () => { describe('when running natively', () => { - nativeButtonOverrides.forEach( - ({buttonOverrides, configPlatform }) => { - const message=mergeInAppMessageWithOverrides(pinpointInAppMessage,configPlatform, buttonOverrides); - const expectedContent = mergeExpectedContentWithExpectedOverride(extractedContent[0],buttonOverrides); + nativeButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + configPlatform, + buttonOverrides, + ); + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, + ); - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( - expectedContent.primaryButton - ); - expect(content[0].secondaryButton).toStrictEqual( - expectedContent.secondaryButton - ); - }); - } - ); + const content = extractContent(message); + expect(content[0].primaryButton).toStrictEqual( + expectedContent.primaryButton, + ); + expect(content[0].secondaryButton).toStrictEqual( + expectedContent.secondaryButton, + ); + }); + }); }); }); }); diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 544c2954950..5c45100272b 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -24,7 +24,10 @@ import { browserButtonOverrides, } from '../../../../testUtils/data'; import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types'; -import { mergeExpectedContentWithExpectedOverride, mergeInAppMessageWithOverrides } from '../../../../testUtils/mergeInAppMessageWithOverrides'; +import { + mergeExpectedContentWithExpectedOverride, + mergeInAppMessageWithOverrides, +} from '../../../../testUtils/mergeInAppMessageWithOverrides'; jest.mock('@aws-amplify/core'); jest.mock('@aws-amplify/core/internals/providers/pinpoint'); @@ -32,7 +35,7 @@ jest.mock('../../../../../src/inAppMessaging/providers/pinpoint/utils'); jest.mock('@aws-amplify/core/internals/utils', () => { const originalModule = jest.requireActual( - '@aws-amplify/core/internals/utils' + '@aws-amplify/core/internals/utils', ); return { ...originalModule, @@ -299,28 +302,33 @@ describe('InAppMessaging Provider Utils', () => { describe('extractContent with overrides', () => { describe('when running in a browser', () => { - browserButtonOverrides.forEach( - ({buttonOverrides, configPlatform }) => { - const message=mergeInAppMessageWithOverrides(pinpointInAppMessage,configPlatform, buttonOverrides); - const expectedContent = mergeExpectedContentWithExpectedOverride(extractedContent[0], buttonOverrides); - - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); - - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( - expectedContent.primaryButton - ); - expect(content[0].secondaryButton).toStrictEqual( - expectedContent.secondaryButton - ); - }); - } - ); + browserButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + configPlatform, + buttonOverrides, + ); + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, + ); + + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const content = extractContent(message); + expect(content[0].primaryButton).toStrictEqual( + expectedContent.primaryButton, + ); + expect(content[0].secondaryButton).toStrictEqual( + expectedContent.secondaryButton, + ); + }); + }); }); }); }); diff --git a/packages/notifications/__tests__/testUtils/data.ts b/packages/notifications/__tests__/testUtils/data.ts index 10d70f6a962..640fbb0b558 100644 --- a/packages/notifications/__tests__/testUtils/data.ts +++ b/packages/notifications/__tests__/testUtils/data.ts @@ -2,7 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint'; -import { type InAppMessageCampaign as PinpointInAppMessage, OverrideButtonConfiguration } from '@aws-amplify/core/internals/aws-clients/pinpoint'; +import { + type InAppMessageCampaign as PinpointInAppMessage, + OverrideButtonConfiguration, +} from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { InAppMessage, InAppMessageContent, @@ -184,7 +187,7 @@ export const pinpointInAppMessage: PinpointInAppMessage = { TreatmentId: 'T1', }; -export const extractedContent:InAppMessageContent[] = [ +export const extractedContent: InAppMessageContent[] = [ { body: { content: 'Body content', @@ -211,63 +214,61 @@ export const extractedContent:InAppMessageContent[] = [ }, ]; - -export const nativeButtonOverrides:{ - configPlatform:'ios' | 'android'; - buttonOverrides:{ - primaryButton:OverrideButtonConfiguration, - secondaryButton:OverrideButtonConfiguration +export const nativeButtonOverrides: { + configPlatform: 'ios' | 'android'; + buttonOverrides: { + primaryButton: OverrideButtonConfiguration; + secondaryButton: OverrideButtonConfiguration; }; }[] = [ { - configPlatform:'android', - buttonOverrides:{ - primaryButton:{ - ButtonAction:'DEEP_LINK', - Link:'android-app://primaryButtonLink', + configPlatform: 'android', + buttonOverrides: { + primaryButton: { + ButtonAction: 'DEEP_LINK', + Link: 'android-app://primaryButtonLink', }, - secondaryButton:{ - ButtonAction:'LINK', - Link:'android-app://secondaryButtonLink', - } - } + secondaryButton: { + ButtonAction: 'LINK', + Link: 'android-app://secondaryButtonLink', + }, + }, }, { - configPlatform:'ios', - buttonOverrides:{ - primaryButton:{ - ButtonAction:'DEEP_LINK', - Link:'ios-app://primaryButtonLink', + configPlatform: 'ios', + buttonOverrides: { + primaryButton: { + ButtonAction: 'DEEP_LINK', + Link: 'ios-app://primaryButtonLink', }, - secondaryButton:{ - ButtonAction:'LINK', - Link:'ios-app://secondaryButtonLink', - } - } - - } -] -export const browserButtonOverrides:{ - configPlatform:'web'; - buttonOverrides:{ - primaryButton:OverrideButtonConfiguration, - secondaryButton:OverrideButtonConfiguration + secondaryButton: { + ButtonAction: 'LINK', + Link: 'ios-app://secondaryButtonLink', + }, + }, + }, +]; +export const browserButtonOverrides: { + configPlatform: 'web'; + buttonOverrides: { + primaryButton: OverrideButtonConfiguration; + secondaryButton: OverrideButtonConfiguration; }; -}[] = [{ - configPlatform:'web', - buttonOverrides:{ - primaryButton:{ - ButtonAction:'LINK', - Link:'https://webPrimaryButtonLink.com', +}[] = [ + { + configPlatform: 'web', + buttonOverrides: { + primaryButton: { + ButtonAction: 'LINK', + Link: 'https://webPrimaryButtonLink.com', + }, + secondaryButton: { + ButtonAction: 'LINK', + Link: 'https://webSecondaryButtonLink.com', }, - secondaryButton:{ - ButtonAction:'LINK', - Link:'https://webSecondaryButtonLink.com', - } - } - - } -] + }, + }, +]; export const extractedMetadata = { customData: { foo: 'bar' }, diff --git a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts index d5cfceb7c0a..ded0948b144 100644 --- a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts +++ b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts @@ -1,36 +1,46 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { cloneDeep } from "lodash"; -import { InAppMessageCampaign, OverrideButtonConfiguration } from "@aws-amplify/core/internals/aws-clients/pinpoint"; -import { InAppMessageButton, InAppMessageContent } from "../../src/inAppMessaging/types/message"; -import { mapOSPlatform } from "../../src/inAppMessaging/providers/pinpoint/utils/helpers"; +import { cloneDeep } from 'lodash'; +import { + InAppMessageCampaign, + OverrideButtonConfiguration, +} from '@aws-amplify/core/internals/aws-clients/pinpoint'; +import { + InAppMessageButton, + InAppMessageContent, +} from '../../src/inAppMessaging/types/message'; +import { mapOSPlatform } from '../../src/inAppMessaging/providers/pinpoint/utils/helpers'; -export const mergeInAppMessageWithOverrides:( - pinpointInAppMessage:InAppMessageCampaign, - platform:'android'|'ios'|'web', - buttonOverrides?:{ - primaryButton:OverrideButtonConfiguration, - secondaryButton:OverrideButtonConfiguration - } - ) =>InAppMessageCampaign = (pinpointInAppMessage, platform, buttonOverrides)=>{ - const message= cloneDeep(pinpointInAppMessage); +export const mergeInAppMessageWithOverrides: ( + pinpointInAppMessage: InAppMessageCampaign, + platform: 'android' | 'ios' | 'web', + buttonOverrides?: { + primaryButton: OverrideButtonConfiguration; + secondaryButton: OverrideButtonConfiguration; + }, +) => InAppMessageCampaign = ( + pinpointInAppMessage, + platform, + buttonOverrides, +) => { + const message = cloneDeep(pinpointInAppMessage); const configPlatform = mapOSPlatform(platform); if (message?.InAppMessage?.Content) { message.InAppMessage.Content[0] = { ...message.InAppMessage.Content[0], - PrimaryBtn:{ + PrimaryBtn: { ...message.InAppMessage.Content[0].PrimaryBtn, - [configPlatform]:buttonOverrides?.primaryButton + [configPlatform]: buttonOverrides?.primaryButton, }, - SecondaryBtn:{ + SecondaryBtn: { ...message.InAppMessage.Content[0].SecondaryBtn, - [configPlatform]:buttonOverrides?.secondaryButton - } - } + [configPlatform]: buttonOverrides?.secondaryButton, + }, + }; } - return message -} + return message; +}; export const mergeExpectedContentWithExpectedOverride:( inAppMessage:InAppMessageContent, diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index fb12d1cfcce..eed5d38b45d 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -4,9 +4,12 @@ import { ConsoleLogger } from '@aws-amplify/core'; import { InAppMessagingAction, - getClientInfo + getClientInfo, } from '@aws-amplify/core/internals/utils'; -import type { InAppMessageCampaign as PinpointInAppMessage, InAppMessageButton } from '@aws-amplify/core/internals/aws-clients/pinpoint'; +import type { + InAppMessageCampaign as PinpointInAppMessage, + InAppMessageButton, +} from '@aws-amplify/core/internals/aws-clients/pinpoint'; import isEmpty from 'lodash/isEmpty.js'; import { InAppMessage, @@ -264,8 +267,12 @@ export const extractContent = ({ ...button?.[configPlatform], }); - const defaultPrimaryButton = PrimaryBtn ? getButtonConfig(PrimaryBtn) : undefined; - const defaultSecondaryButton = SecondaryBtn ? getButtonConfig(SecondaryBtn) : undefined; + const defaultPrimaryButton = PrimaryBtn + ? getButtonConfig(PrimaryBtn) + : undefined; + const defaultSecondaryButton = SecondaryBtn + ? getButtonConfig(SecondaryBtn) + : undefined; const extractedContent: InAppMessageContent = {}; if (BackgroundColor) { @@ -346,7 +353,7 @@ export const extractMetadata = ({ }); export const mapOSPlatform = (os?: string): ButtonConfigPlatform => { - if(!os) return 'DefaultConfig'; + if (!os) return 'DefaultConfig'; // Check if running in a web browser if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { return 'Web'; From d7721c397e1b4e676da8375682c36adfa38f5a68 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 12:40:27 -0800 Subject: [PATCH 13/19] flatten test structure --- .../pinpoint/utils/helpers.native.test.ts | 60 +++++++++--------- .../providers/pinpoint/utils/helpers.test.ts | 62 +++++++++---------- 2 files changed, 57 insertions(+), 65 deletions(-) diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts index 66aa08285fc..3c9fb68a66b 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -29,46 +29,42 @@ jest.mock('@aws-amplify/core/internals/utils', () => { }; }); -describe('InAppMessaging Provider Utils', () => { +describe('InAppMessaging Provider Utils (running natively)', () => { describe('mapOSPlatform method', () => { - describe('when running natively', () => { - nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { - test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { - const result = mapOSPlatform(os); - expect(result).toBe(expectedPlatform); - }); + nonBrowserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); }); }); }); describe('extractContent with overrides', () => { - describe('when running natively', () => { - nativeButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { - const message = mergeInAppMessageWithOverrides( - pinpointInAppMessage, - configPlatform, - buttonOverrides, - ); - const expectedContent = mergeExpectedContentWithExpectedOverride( - extractedContent[0], - buttonOverrides, - ); + nativeButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + configPlatform, + buttonOverrides, + ); + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, + ); - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( - expectedContent.primaryButton, - ); - expect(content[0].secondaryButton).toStrictEqual( - expectedContent.secondaryButton, - ); - }); + const content = extractContent(message); + expect(content[0].primaryButton).toStrictEqual( + expectedContent.primaryButton, + ); + expect(content[0].secondaryButton).toStrictEqual( + expectedContent.secondaryButton, + ); }); }); }); diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 5c45100272b..48a36639c11 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -289,45 +289,41 @@ describe('InAppMessaging Provider Utils', () => { expect(extractMetadata(message)).toStrictEqual(extractedMetadata); }); - describe('mapOSPlatform method', () => { - describe('when running in a browser', () => { - browserConfigTestCases.forEach(({ os, expectedPlatform }) => { - test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { - const result = mapOSPlatform(os); - expect(result).toBe(expectedPlatform); - }); + describe('mapOSPlatform method (running in a browser)', () => { + browserConfigTestCases.forEach(({ os, expectedPlatform }) => { + test(`correctly maps OS "${os}" to ConfigPlatformType "${expectedPlatform}"`, () => { + const result = mapOSPlatform(os); + expect(result).toBe(expectedPlatform); }); }); }); - describe('extractContent with overrides', () => { - describe('when running in a browser', () => { - browserButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { - const message = mergeInAppMessageWithOverrides( - pinpointInAppMessage, - configPlatform, - buttonOverrides, + describe('extractContent with overrides (running in a browser)', () => { + browserButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + configPlatform, + buttonOverrides, + ); + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, + ); + + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const content = extractContent(message); + expect(content[0].primaryButton).toStrictEqual( + expectedContent.primaryButton, ); - const expectedContent = mergeExpectedContentWithExpectedOverride( - extractedContent[0], - buttonOverrides, + expect(content[0].secondaryButton).toStrictEqual( + expectedContent.secondaryButton, ); - - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); - - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( - expectedContent.primaryButton, - ); - expect(content[0].secondaryButton).toStrictEqual( - expectedContent.secondaryButton, - ); - }); }); }); }); From b53cefc411391c958ac58838b2e1cc58218310fc Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 12:44:51 -0800 Subject: [PATCH 14/19] minor update --- .../providers/pinpoint/utils/helpers.native.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts index 3c9fb68a66b..d671e8020f6 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -58,11 +58,11 @@ describe('InAppMessaging Provider Utils (running natively)', () => { platform: configPlatform, })); - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( + const [firstContent] = extractContent(message); + expect(firstContent.primaryButton).toStrictEqual( expectedContent.primaryButton, ); - expect(content[0].secondaryButton).toStrictEqual( + expect(firstContent.secondaryButton).toStrictEqual( expectedContent.secondaryButton, ); }); From 59828bd1b19afbe3a0e0bcb961c8f8a22a43bab7 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 12:45:53 -0800 Subject: [PATCH 15/19] minor update --- .../inAppMessaging/providers/pinpoint/utils/helpers.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 48a36639c11..57b239cb33d 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -317,11 +317,11 @@ describe('InAppMessaging Provider Utils', () => { platform: configPlatform, })); - const content = extractContent(message); - expect(content[0].primaryButton).toStrictEqual( + const [firstContent] = extractContent(message); + expect(firstContent.primaryButton).toStrictEqual( expectedContent.primaryButton, ); - expect(content[0].secondaryButton).toStrictEqual( + expect(firstContent.secondaryButton).toStrictEqual( expectedContent.secondaryButton, ); }); From 3a58f157071dcb7ee62a9e8bf062c96bb24d7cd0 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 16:01:19 -0800 Subject: [PATCH 16/19] updated merge override fns signature and associated tests --- .../pinpoint/utils/helpers.native.test.ts | 52 ++++++++++--------- .../providers/pinpoint/utils/helpers.test.ts | 52 ++++++++++--------- .../notifications/__tests__/testUtils/data.ts | 6 +++ .../mergeInAppMessageWithOverrides.ts | 45 +++++++--------- 4 files changed, 80 insertions(+), 75 deletions(-) diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts index d671e8020f6..fcf9449ce53 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.native.test.ts @@ -40,32 +40,34 @@ describe('InAppMessaging Provider Utils (running natively)', () => { }); describe('extractContent with overrides', () => { - nativeButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { - const message = mergeInAppMessageWithOverrides( - pinpointInAppMessage, - configPlatform, - buttonOverrides, - ); - const expectedContent = mergeExpectedContentWithExpectedOverride( - extractedContent[0], - buttonOverrides, - ); - - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); - - const [firstContent] = extractContent(message); - expect(firstContent.primaryButton).toStrictEqual( - expectedContent.primaryButton, + nativeButtonOverrides.forEach( + ({ buttonOverrides, configPlatform, mappedPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + mappedPlatform, + buttonOverrides, ); - expect(firstContent.secondaryButton).toStrictEqual( - expectedContent.secondaryButton, + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, ); - }); - }); + + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const [firstContent] = extractContent(message); + expect(firstContent.primaryButton).toStrictEqual( + expectedContent.primaryButton, + ); + expect(firstContent.secondaryButton).toStrictEqual( + expectedContent.secondaryButton, + ); + }); + }, + ); }); }); diff --git a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts index 57b239cb33d..5409abac5c2 100644 --- a/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts +++ b/packages/notifications/__tests__/inAppMessaging/providers/pinpoint/utils/helpers.test.ts @@ -299,32 +299,34 @@ describe('InAppMessaging Provider Utils', () => { }); describe('extractContent with overrides (running in a browser)', () => { - browserButtonOverrides.forEach(({ buttonOverrides, configPlatform }) => { - const message = mergeInAppMessageWithOverrides( - pinpointInAppMessage, - configPlatform, - buttonOverrides, - ); - const expectedContent = mergeExpectedContentWithExpectedOverride( - extractedContent[0], - buttonOverrides, - ); - - test(`correctly extracts content for ${configPlatform}`, () => { - const utils = require('@aws-amplify/core/internals/utils'); - // Dynamically override the mock for getClientInfo - utils.getClientInfo.mockImplementation(() => ({ - platform: configPlatform, - })); - - const [firstContent] = extractContent(message); - expect(firstContent.primaryButton).toStrictEqual( - expectedContent.primaryButton, + browserButtonOverrides.forEach( + ({ buttonOverrides, configPlatform, mappedPlatform }) => { + const message = mergeInAppMessageWithOverrides( + pinpointInAppMessage, + mappedPlatform, + buttonOverrides, ); - expect(firstContent.secondaryButton).toStrictEqual( - expectedContent.secondaryButton, + const expectedContent = mergeExpectedContentWithExpectedOverride( + extractedContent[0], + buttonOverrides, ); - }); - }); + + test(`correctly extracts content for ${configPlatform}`, () => { + const utils = require('@aws-amplify/core/internals/utils'); + // Dynamically override the mock for getClientInfo + utils.getClientInfo.mockImplementation(() => ({ + platform: configPlatform, + })); + + const [firstContent] = extractContent(message); + expect(firstContent.primaryButton).toStrictEqual( + expectedContent.primaryButton, + ); + expect(firstContent.secondaryButton).toStrictEqual( + expectedContent.secondaryButton, + ); + }); + }, + ); }); }); diff --git a/packages/notifications/__tests__/testUtils/data.ts b/packages/notifications/__tests__/testUtils/data.ts index 640fbb0b558..6a3fddf37a5 100644 --- a/packages/notifications/__tests__/testUtils/data.ts +++ b/packages/notifications/__tests__/testUtils/data.ts @@ -12,6 +12,7 @@ import { InAppMessagingEvent, } from '../../src/inAppMessaging/types'; import { PushNotificationMessage } from '../../src/pushNotifications'; +import { ButtonConfigPlatform } from '../../src/inAppMessaging/types/message'; export const credentials = { credentials: { @@ -216,6 +217,7 @@ export const extractedContent: InAppMessageContent[] = [ export const nativeButtonOverrides: { configPlatform: 'ios' | 'android'; + mappedPlatform: ButtonConfigPlatform; buttonOverrides: { primaryButton: OverrideButtonConfiguration; secondaryButton: OverrideButtonConfiguration; @@ -223,6 +225,7 @@ export const nativeButtonOverrides: { }[] = [ { configPlatform: 'android', + mappedPlatform: 'Android', buttonOverrides: { primaryButton: { ButtonAction: 'DEEP_LINK', @@ -236,6 +239,7 @@ export const nativeButtonOverrides: { }, { configPlatform: 'ios', + mappedPlatform: 'IOS', buttonOverrides: { primaryButton: { ButtonAction: 'DEEP_LINK', @@ -250,6 +254,7 @@ export const nativeButtonOverrides: { ]; export const browserButtonOverrides: { configPlatform: 'web'; + mappedPlatform: ButtonConfigPlatform; buttonOverrides: { primaryButton: OverrideButtonConfiguration; secondaryButton: OverrideButtonConfiguration; @@ -257,6 +262,7 @@ export const browserButtonOverrides: { }[] = [ { configPlatform: 'web', + mappedPlatform: 'Web', buttonOverrides: { primaryButton: { ButtonAction: 'LINK', diff --git a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts index ded0948b144..09f90f03b8d 100644 --- a/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts +++ b/packages/notifications/__tests__/testUtils/mergeInAppMessageWithOverrides.ts @@ -7,58 +7,53 @@ import { OverrideButtonConfiguration, } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import { + ButtonConfigPlatform, InAppMessageButton, InAppMessageContent, } from '../../src/inAppMessaging/types/message'; -import { mapOSPlatform } from '../../src/inAppMessaging/providers/pinpoint/utils/helpers'; -export const mergeInAppMessageWithOverrides: ( +export const mergeInAppMessageWithOverrides = ( pinpointInAppMessage: InAppMessageCampaign, - platform: 'android' | 'ios' | 'web', + mappedPlatform: ButtonConfigPlatform, buttonOverrides?: { primaryButton: OverrideButtonConfiguration; secondaryButton: OverrideButtonConfiguration; }, -) => InAppMessageCampaign = ( - pinpointInAppMessage, - platform, - buttonOverrides, -) => { +): InAppMessageCampaign => { const message = cloneDeep(pinpointInAppMessage); - const configPlatform = mapOSPlatform(platform); if (message?.InAppMessage?.Content) { message.InAppMessage.Content[0] = { ...message.InAppMessage.Content[0], PrimaryBtn: { ...message.InAppMessage.Content[0].PrimaryBtn, - [configPlatform]: buttonOverrides?.primaryButton, + [mappedPlatform]: buttonOverrides?.primaryButton, }, SecondaryBtn: { ...message.InAppMessage.Content[0].SecondaryBtn, - [configPlatform]: buttonOverrides?.secondaryButton, + [mappedPlatform]: buttonOverrides?.secondaryButton, }, }; } return message; }; -export const mergeExpectedContentWithExpectedOverride:( - inAppMessage:InAppMessageContent, +export const mergeExpectedContentWithExpectedOverride = ( + inAppMessage: InAppMessageContent, expectedButtonConfig: { - primaryButton:OverrideButtonConfiguration, - secondaryButton:OverrideButtonConfiguration - } -)=>InAppMessageContent = (inAppMessage, expectedButtonConfig)=>{ + primaryButton: OverrideButtonConfiguration; + secondaryButton: OverrideButtonConfiguration; + }, +): InAppMessageContent => { let expectedContent = cloneDeep(inAppMessage); expectedContent.primaryButton = { ...expectedContent.primaryButton, - action:expectedButtonConfig.primaryButton.ButtonAction, - url:expectedButtonConfig.primaryButton.Link - } as InAppMessageButton + action: expectedButtonConfig.primaryButton.ButtonAction, + url: expectedButtonConfig.primaryButton.Link, + } as InAppMessageButton; expectedContent.secondaryButton = { ...expectedContent.secondaryButton, - action:expectedButtonConfig.secondaryButton.ButtonAction, - url:expectedButtonConfig.secondaryButton.Link - } as InAppMessageButton - return expectedContent -} \ No newline at end of file + action: expectedButtonConfig.secondaryButton.ButtonAction, + url: expectedButtonConfig.secondaryButton.Link, + } as InAppMessageButton; + return expectedContent; +}; \ No newline at end of file From 7ff8b96827cccda8f1a14598f8f426652cfbb879 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 16:05:54 -0800 Subject: [PATCH 17/19] extracted getButtonConfig fn and refactored to add data existence checks. --- .../providers/pinpoint/utils/helpers.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index eed5d38b45d..87172444e7e 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -262,17 +262,11 @@ export const extractContent = ({ SecondaryBtn, } = content; - const getButtonConfig = (button?: InAppMessageButton) => ({ - ...button?.DefaultConfig, - ...button?.[configPlatform], - }); - - const defaultPrimaryButton = PrimaryBtn - ? getButtonConfig(PrimaryBtn) - : undefined; - const defaultSecondaryButton = SecondaryBtn - ? getButtonConfig(SecondaryBtn) - : undefined; + const defaultPrimaryButton = getButtonConfig(configPlatform, PrimaryBtn); + const defaultSecondaryButton = getButtonConfig( + configPlatform, + SecondaryBtn, + ); const extractedContent: InAppMessageContent = {}; if (BackgroundColor) { @@ -368,3 +362,19 @@ export const mapOSPlatform = (os?: string): ButtonConfigPlatform => { return 'DefaultConfig'; } }; + +const getButtonConfig = ( + configPlatform: ButtonConfigPlatform, + button?: InAppMessageButton, +): InAppMessageButton['DefaultConfig'] | undefined => { + if (!button || !button?.DefaultConfig) { + return; + } + if (!configPlatform || !button?.[configPlatform]) { + return button?.DefaultConfig; + } + return { + ...button?.DefaultConfig, + ...button?.[configPlatform], + }; +}; From f7eb8005fb0b44f966477bc1cc26d1bf77153137 Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Sun, 18 Feb 2024 19:04:58 -0800 Subject: [PATCH 18/19] removed unnecessary optional chaining operators --- .../src/inAppMessaging/providers/pinpoint/utils/helpers.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index 87172444e7e..b2eca3eb96c 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -367,14 +367,14 @@ const getButtonConfig = ( configPlatform: ButtonConfigPlatform, button?: InAppMessageButton, ): InAppMessageButton['DefaultConfig'] | undefined => { - if (!button || !button?.DefaultConfig) { + if (!button?.DefaultConfig) { return; } if (!configPlatform || !button?.[configPlatform]) { return button?.DefaultConfig; } return { - ...button?.DefaultConfig, - ...button?.[configPlatform], + ...button.DefaultConfig, + ...button[configPlatform], }; }; From aa52fe758d7405cc41cba029e101c62b2a034a2a Mon Sep 17 00:00:00 2001 From: buddyeorl Date: Mon, 15 Apr 2024 21:36:04 -0700 Subject: [PATCH 19/19] fixed lint issues --- .../inAppMessaging/providers/pinpoint/utils/helpers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts index b68813c3c03..2d1cda76680 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/utils/helpers.ts @@ -6,9 +6,9 @@ import { InAppMessagingAction, getClientInfo, } from '@aws-amplify/core/internals/utils'; -import type { - InAppMessageCampaign as PinpointInAppMessage, +import type { InAppMessageButton, + InAppMessageCampaign as PinpointInAppMessage, } from '@aws-amplify/core/internals/aws-clients/pinpoint'; import isEmpty from 'lodash/isEmpty.js'; import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint'; @@ -22,12 +22,12 @@ import { InAppMessagingEvent, } from '../../../types'; import { MetricsComparator, PinpointMessageEvent } from '../types'; +import { ButtonConfigPlatform } from '../../../types/message'; import { resolveConfig } from './resolveConfig'; import { resolveCredentials } from './resolveCredentials'; import { CATEGORY } from './constants'; import { getInAppMessagingUserAgentString } from './userAgent'; -import { ButtonConfigPlatform } from '../../../types/message'; const DELIVERY_TYPE = 'IN_APP_MESSAGE'; @@ -260,6 +260,7 @@ export const extractContent = ({ }: PinpointInAppMessage): InAppMessageContent[] => { const clientInfo = getClientInfo(); const configPlatform = mapOSPlatform(clientInfo?.platform); + return ( message?.Content?.map(content => { const { @@ -383,6 +384,7 @@ const getButtonConfig = ( if (!configPlatform || !button?.[configPlatform]) { return button?.DefaultConfig; } + return { ...button.DefaultConfig, ...button[configPlatform],