@capillarytech/creatives-library 9.2.3 → 9.2.4-alpha.feature-rcs-multi-account.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/v2Components/CommonTestAndPreview/index.js +8 -2
- package/v2Components/CommonTestAndPreview/tests/index.test.js +58 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +2 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +16 -3
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/SenderDetails.js +7 -2
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/deliverySettingsConfig.test.js +44 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/deliverySettingsConfig.js +21 -8
- package/v2Containers/CreativesContainer/index.js +16 -0
- package/v2Containers/CreativesContainer/tests/index.test.js +66 -0
- package/v2Containers/Rcs/accountUtils.js +20 -0
- package/v2Containers/Rcs/index.js +18 -1
- package/v2Containers/Rcs/tests/accountUtils.test.js +24 -0
- package/v2Containers/Rcs/tests/index.test.js +23 -0
- package/v2Containers/Templates/ChannelTypeIllustration.js +12 -0
- package/v2Containers/Templates/index.js +8 -4
- package/v2Containers/Templates/messages.js +4 -0
- package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +14 -2
- package/v2Containers/Templates/tests/index.test.js +101 -0
package/package.json
CHANGED
|
@@ -229,6 +229,9 @@ const CommonTestAndPreview = (props) => {
|
|
|
229
229
|
} = props;
|
|
230
230
|
|
|
231
231
|
const smsFallbackContent = additionalProps?.smsFallbackContent;
|
|
232
|
+
// RCS multi-account (same as WhatsApp): the template's account sourceAccountIdentifier picks the default domain.
|
|
233
|
+
const rcsSourceAccountIdentifier = additionalProps?.rcsTestPreviewOptions?.sourceAccountIdentifier || '';
|
|
234
|
+
|
|
232
235
|
const smsFallbackTextForTagExtraction = useMemo(
|
|
233
236
|
() => getSmsFallbackTextForTagExtraction(smsFallbackContent),
|
|
234
237
|
[smsFallbackContent],
|
|
@@ -348,7 +351,10 @@ const CommonTestAndPreview = (props) => {
|
|
|
348
351
|
|
|
349
352
|
if (!isRcsDeliveryFullyUnset && !shouldOnlyFillSmsFallbackSender) return;
|
|
350
353
|
|
|
351
|
-
|
|
354
|
+
// Same as WhatsApp: default to the account's domain, else the first domain.
|
|
355
|
+
const firstRcsDomain = (rcsSourceAccountIdentifier
|
|
356
|
+
&& rcsDomainRows.find((domain) => domain?.sourceAccountIdentifier === rcsSourceAccountIdentifier))
|
|
357
|
+
|| rcsDomainRows[0];
|
|
352
358
|
const firstSmsFallbackDomain = smsFallbackDomainRows[0];
|
|
353
359
|
const usableRcsGsmSenders = filterUsableGsmSendersForDomain(
|
|
354
360
|
firstRcsDomain,
|
|
@@ -453,7 +459,7 @@ const CommonTestAndPreview = (props) => {
|
|
|
453
459
|
}
|
|
454
460
|
return next;
|
|
455
461
|
});
|
|
456
|
-
}, [channel, formData?.accountName, senderDetailsByChannel, smsTraiDltEnabled, registeredSenderIds, wecrmAccounts]);
|
|
462
|
+
}, [channel, formData?.accountName, senderDetailsByChannel, rcsSourceAccountIdentifier, smsTraiDltEnabled, registeredSenderIds, wecrmAccounts]);
|
|
457
463
|
|
|
458
464
|
// ============================================
|
|
459
465
|
// MEMOIZED VALUES
|
|
@@ -213,6 +213,64 @@ describe('CommonTestAndPreview', () => {
|
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
describe('Delivery settings / sender ID', () => {
|
|
216
|
+
describe('RCS multi-account default sender', () => {
|
|
217
|
+
const rcsDomainA = {
|
|
218
|
+
domainId: 1,
|
|
219
|
+
dgmId: 11,
|
|
220
|
+
domainName: 'RCS A',
|
|
221
|
+
sourceAccountIdentifier: 'acc-A',
|
|
222
|
+
gsmSenders: [{ value: 'RCS_A' }],
|
|
223
|
+
cdmaSenders: [],
|
|
224
|
+
};
|
|
225
|
+
const rcsDomainB = {
|
|
226
|
+
domainId: 2,
|
|
227
|
+
dgmId: 22,
|
|
228
|
+
domainName: 'RCS B',
|
|
229
|
+
sourceAccountIdentifier: 'acc-B',
|
|
230
|
+
gsmSenders: [{ value: 'RCS_B' }],
|
|
231
|
+
cdmaSenders: [],
|
|
232
|
+
};
|
|
233
|
+
const senderDetailsByChannel = { [CHANNELS.RCS]: [rcsDomainA, rcsDomainB] };
|
|
234
|
+
const renderRcs = (rcsTestPreviewOptions) => render(
|
|
235
|
+
<TestWrapper>
|
|
236
|
+
<CommonTestAndPreview
|
|
237
|
+
{...defaultProps}
|
|
238
|
+
channel={CHANNELS.RCS}
|
|
239
|
+
senderDetailsByChannel={senderDetailsByChannel}
|
|
240
|
+
rcsTestPreviewOptions={rcsTestPreviewOptions}
|
|
241
|
+
/>
|
|
242
|
+
</TestWrapper>
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
it('defaults to the template account domain and keeps every RCS domain in the list (same as WhatsApp)', async () => {
|
|
246
|
+
renderRcs({ isLibraryMode: false, sourceAccountIdentifier: 'acc-B' });
|
|
247
|
+
await waitFor(() => {
|
|
248
|
+
expect(lastSendTestMessageProps.deliverySettings).toMatchObject({
|
|
249
|
+
domainId: 2,
|
|
250
|
+
domainGatewayMapId: 22,
|
|
251
|
+
gsmSenderId: '2|RCS_B',
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
expect(lastSendTestMessageProps.senderDetailsByChannel).toBe(senderDetailsByChannel);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('defaults to the first RCS domain when no account is given (single-account behaviour)', async () => {
|
|
258
|
+
renderRcs({ isLibraryMode: false });
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(lastSendTestMessageProps.deliverySettings).toMatchObject({ domainId: 1, gsmSenderId: '1|RCS_A' });
|
|
261
|
+
});
|
|
262
|
+
expect(lastSendTestMessageProps.senderDetailsByChannel).toBe(senderDetailsByChannel);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('defaults to the first RCS domain when the account matches no domain', async () => {
|
|
266
|
+
renderRcs({ isLibraryMode: false, sourceAccountIdentifier: 'acc-unknown' });
|
|
267
|
+
await waitFor(() => {
|
|
268
|
+
expect(lastSendTestMessageProps.deliverySettings).toMatchObject({ domainId: 1, gsmSenderId: '1|RCS_A' });
|
|
269
|
+
});
|
|
270
|
+
expect(lastSendTestMessageProps.senderDetailsByChannel).toBe(senderDetailsByChannel);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
216
274
|
it('should call getSenderDetailsRequested when show and channel is SMS', async () => {
|
|
217
275
|
render(
|
|
218
276
|
<TestWrapper>
|
|
@@ -88,6 +88,8 @@ TestAndPreviewSlidebox.propTypes = {
|
|
|
88
88
|
/** Passed to CommonTestAndPreview for RCS test-meta resolution (slot semantics vs full-mode). */
|
|
89
89
|
rcsTestPreviewOptions: PropTypes.shape({
|
|
90
90
|
isLibraryMode: PropTypes.bool,
|
|
91
|
+
/** RCS multi-account: template account's sourceAccountIdentifier; scopes RCS senders to that account. */
|
|
92
|
+
sourceAccountIdentifier: PropTypes.string,
|
|
91
93
|
}),
|
|
92
94
|
// Redux props are passed through
|
|
93
95
|
actions: PropTypes.object.isRequired,
|
package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js
CHANGED
|
@@ -90,6 +90,18 @@ const DeliverySettingsSection = ({
|
|
|
90
90
|
return waContentItem?.templateData?.sourceAccountIdentifier || '';
|
|
91
91
|
}, [contentItems]);
|
|
92
92
|
|
|
93
|
+
// Extract RCS sourceAccountIdentifier from contentItems (set by CreativesContainer for multi-account RCS)
|
|
94
|
+
const rcsSourceAccountId = useMemo(() => {
|
|
95
|
+
const rcsContentItem = contentItems.find((contentItem) => (contentItem.channel)?.toUpperCase() === RCS);
|
|
96
|
+
return rcsContentItem?.templateData?.sourceAccountIdentifier || '';
|
|
97
|
+
}, [contentItems]);
|
|
98
|
+
|
|
99
|
+
// Account context for account-bound fields (WhatsApp WABA, RCS account)
|
|
100
|
+
const accountContext = useMemo(() => ({
|
|
101
|
+
whatsappSourceAccountId,
|
|
102
|
+
rcsSourceAccountId,
|
|
103
|
+
}), [whatsappSourceAccountId, rcsSourceAccountId]);
|
|
104
|
+
|
|
93
105
|
// Extract WhatsApp account name from contentItems (set by Whatsapp/index.js)
|
|
94
106
|
const whatsappAccNameFromContent = useMemo(() => {
|
|
95
107
|
const waContentItem = contentItems.find((contentItem) => (contentItem.channel)?.toUpperCase() === WHATSAPP);
|
|
@@ -221,7 +233,7 @@ const DeliverySettingsSection = ({
|
|
|
221
233
|
if (!entityWithWecrmViber || !onDeliverySettingChange || deliveryChannels.length === 0) return;
|
|
222
234
|
|
|
223
235
|
// Convert the API entity into the channelSetting shape (e.g. { SMS: { gsmSenderId: '...' } })
|
|
224
|
-
const senderDetailsFromAPI = parseSenderDetailsFromEntity(entityWithWecrmViber,
|
|
236
|
+
const senderDetailsFromAPI = parseSenderDetailsFromEntity(entityWithWecrmViber, accountContext);
|
|
225
237
|
const channelSettingFromAPI = buildChannelSettingFromFieldValues(senderDetailsFromAPI);
|
|
226
238
|
|
|
227
239
|
const savedChannelSetting = deliverySetting?.channelSetting || {};
|
|
@@ -252,13 +264,13 @@ const DeliverySettingsSection = ({
|
|
|
252
264
|
|
|
253
265
|
const parsedSenderDetails = useMemo(() => {
|
|
254
266
|
if (!entityWithWecrmViber) return null;
|
|
255
|
-
const fromEntity = parseSenderDetailsFromEntity(entityWithWecrmViber,
|
|
267
|
+
const fromEntity = parseSenderDetailsFromEntity(entityWithWecrmViber, accountContext);
|
|
256
268
|
const fromSaved = parseChannelSettingForDisplay(deliverySetting?.channelSetting);
|
|
257
269
|
// Derive WhatsApp account name: from entity domain or from content templateData
|
|
258
270
|
const waAccountName = whatsappAccNameFromContent
|
|
259
271
|
|| getWhatsappAccountName(entityWithWecrmViber, whatsappSourceAccountId);
|
|
260
272
|
return { ...fromEntity, ...fromSaved, whatsappAccountName: waAccountName || fromEntity.whatsappAccountName };
|
|
261
|
-
}, [entityWithWecrmViber, deliverySetting, whatsappSourceAccountId, whatsappAccNameFromContent]);
|
|
273
|
+
}, [entityWithWecrmViber, deliverySetting, accountContext, whatsappSourceAccountId, whatsappAccNameFromContent]);
|
|
262
274
|
|
|
263
275
|
// Map channel -> { labelKey, valueKey } or array of { labelKey, valueKey } for summary display
|
|
264
276
|
// SMS, RCS, EMAIL, VIBER: Sender ID | WHATSAPP: Sender number | LINE: Account
|
|
@@ -351,6 +363,7 @@ const DeliverySettingsSection = ({
|
|
|
351
363
|
isLoadingDomainProperties={isFetchingDomains}
|
|
352
364
|
savedFieldValues={parseChannelSettingForDisplay(deliverySetting?.channelSetting)}
|
|
353
365
|
whatsappSourceAccountId={whatsappSourceAccountId}
|
|
366
|
+
rcsSourceAccountId={rcsSourceAccountId}
|
|
354
367
|
whatsappAccountName={whatsappAccNameFromContent || getWhatsappAccountName(entityWithWecrmViber, whatsappSourceAccountId)}
|
|
355
368
|
onSave={handleDeliverySettingSave}
|
|
356
369
|
/>
|
|
@@ -47,6 +47,7 @@ const SenderDetails = ({
|
|
|
47
47
|
savedFieldValues,
|
|
48
48
|
onSave,
|
|
49
49
|
whatsappSourceAccountId,
|
|
50
|
+
rcsSourceAccountId,
|
|
50
51
|
whatsappAccountName,
|
|
51
52
|
intl,
|
|
52
53
|
}) => {
|
|
@@ -64,7 +65,8 @@ const SenderDetails = ({
|
|
|
64
65
|
// Context for WABA-bound fields (WhatsApp sender number filtered by sourceAccountIdentifier)
|
|
65
66
|
const wabaContext = useMemo(() => ({
|
|
66
67
|
whatsappSourceAccountId: whatsappSourceAccountId || '',
|
|
67
|
-
|
|
68
|
+
rcsSourceAccountId: rcsSourceAccountId || '',
|
|
69
|
+
}), [whatsappSourceAccountId, rcsSourceAccountId]);
|
|
68
70
|
|
|
69
71
|
// Only use preloaded data from parent (DeliverySettingsSection) - no fetch here to avoid duplicate API calls
|
|
70
72
|
// When reopening, use savedFieldValues to restore user's last saved selections
|
|
@@ -83,7 +85,7 @@ const SenderDetails = ({
|
|
|
83
85
|
initial.whatsappAccount = whatsappAccountName;
|
|
84
86
|
}
|
|
85
87
|
// Set RCS account name (disabled field)
|
|
86
|
-
const rcsAccName = getRcsAccountName(preloadedDomainProperties);
|
|
88
|
+
const rcsAccName = getRcsAccountName(preloadedDomainProperties, rcsSourceAccountId);
|
|
87
89
|
if (rcsAccName) {
|
|
88
90
|
initial.rcsAccount = rcsAccName;
|
|
89
91
|
}
|
|
@@ -322,6 +324,8 @@ SenderDetails.propTypes = {
|
|
|
322
324
|
savedFieldValues: PropTypes.object,
|
|
323
325
|
onSave: PropTypes.func,
|
|
324
326
|
whatsappSourceAccountId: PropTypes.string,
|
|
327
|
+
/** RCS multi-account: template account's sourceAccountIdentifier; binds RCS fields to its domain. */
|
|
328
|
+
rcsSourceAccountId: PropTypes.string,
|
|
325
329
|
whatsappAccountName: PropTypes.string,
|
|
326
330
|
intl: PropTypes.object.isRequired,
|
|
327
331
|
};
|
|
@@ -333,6 +337,7 @@ SenderDetails.defaultProps = {
|
|
|
333
337
|
savedFieldValues: null,
|
|
334
338
|
onSave: null,
|
|
335
339
|
whatsappSourceAccountId: '',
|
|
340
|
+
rcsSourceAccountId: '',
|
|
336
341
|
whatsappAccountName: '',
|
|
337
342
|
};
|
|
338
343
|
|
|
@@ -340,6 +340,50 @@ describe('deliverySettingsConfig — user-facing flows', () => {
|
|
|
340
340
|
});
|
|
341
341
|
});
|
|
342
342
|
|
|
343
|
+
describe('RCS: multi-account binding by sourceAccountIdentifier', () => {
|
|
344
|
+
const rcsRow = (domainName, sender, connectionProperties) => ({
|
|
345
|
+
domainProperties: {
|
|
346
|
+
domainName,
|
|
347
|
+
...(connectionProperties && { connectionProperties }),
|
|
348
|
+
contactInfo: [{
|
|
349
|
+
type: 'gsm_sender_id', value: sender, valid: true, default: true,
|
|
350
|
+
}],
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
const multiAccountEntity = {
|
|
354
|
+
RCS: [
|
|
355
|
+
rcsRow('Brand A', '+rcsA', { sourceAccountIdentifier: 'acc-A' }),
|
|
356
|
+
rcsRow('Brand B', '+rcsB', { sourceAccountIdentifier: 'acc-B' }),
|
|
357
|
+
],
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
it('binds account name and sender number to the template account domain', () => {
|
|
361
|
+
expect(getRcsAccountName(multiAccountEntity, 'acc-B')).toBe('Brand B');
|
|
362
|
+
const summary = parseEntityForDisplay(multiAccountEntity, { rcsSourceAccountId: 'acc-B' });
|
|
363
|
+
expect(summary.rcsAccountName).toBe('Brand B');
|
|
364
|
+
expect(summary.rcsSenderNumber).toBe('+rcsB');
|
|
365
|
+
expect(summary.senderNumber).toBe('+rcsB');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('falls back to the first RCS domain when the account is unknown', () => {
|
|
369
|
+
expect(getRcsAccountName(multiAccountEntity, 'unknown')).toBe('Brand A');
|
|
370
|
+
const summary = parseEntityForDisplay(multiAccountEntity, { rcsSourceAccountId: 'unknown' });
|
|
371
|
+
expect(summary.rcsSenderNumber).toBe('+rcsA');
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('falls back to the first RCS domain when no account is passed (single-account behaviour)', () => {
|
|
375
|
+
expect(getRcsAccountName(multiAccountEntity)).toBe('Brand A');
|
|
376
|
+
expect(parseEntityForDisplay(multiAccountEntity).rcsSenderNumber).toBe('+rcsA');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('does not let the RCS account change the WhatsApp sender number', () => {
|
|
380
|
+
const combined = { ...domainPropertiesFromApi, RCS: multiAccountEntity.RCS };
|
|
381
|
+
const summary = parseEntityForDisplay(combined, { rcsSourceAccountId: 'acc-B' });
|
|
382
|
+
expect(summary.senderNumber).toBe('+wa1');
|
|
383
|
+
expect(summary.rcsSenderNumber).toBe('+rcsB');
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
343
387
|
describe('Viber: gateway id 0 + alternate API sender types', () => {
|
|
344
388
|
it('uses viber_sender_id when GSM is not present (API variance)', () => {
|
|
345
389
|
const entity = domainPropertiesFromApi;
|
|
@@ -348,15 +348,27 @@ const getWhatsappSenderNumberOptions = (entity, context = {}) => {
|
|
|
348
348
|
return options?.map((option) => ({ label: option.value || option.label, value: option.value || option.label }));
|
|
349
349
|
};
|
|
350
350
|
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
// --- RCS account-bound domain (multi-account) ---
|
|
352
|
+
// Same as WhatsApp: the RCS template carries its account's sourceAccountIdentifier (contentItems templateData),
|
|
353
|
+
// matched against the domain's connectionProperties; falls back to the first RCS domain when unknown or unmatched.
|
|
354
|
+
|
|
355
|
+
/** Find the RCS domain matching a sourceAccountIdentifier */
|
|
356
|
+
const getRcsDomainBySourceAccount = (entity, sourceAccountId) => {
|
|
357
|
+
const rcsDomains = toArray(entity?.RCS);
|
|
358
|
+
if (!sourceAccountId) return rcsDomains?.length ? rcsDomains[0] : null;
|
|
359
|
+
const matchedDomain = rcsDomains.find((domain) => getDomainSourceAccountId(domain) === sourceAccountId);
|
|
360
|
+
return matchedDomain || (rcsDomains?.length ? rcsDomains[0] : null);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const getRcsSenderNumberValue = (entity, context = {}) => {
|
|
364
|
+
const channelData = getRcsDomainBySourceAccount(entity, context?.rcsSourceAccountId);
|
|
353
365
|
if (!channelData) return '';
|
|
354
366
|
return getValueFromContactInfo(channelData, 'gsm_sender_id', ['cdma_sender_id']);
|
|
355
367
|
};
|
|
356
368
|
|
|
357
|
-
/** Get RCS account name from
|
|
358
|
-
export const getRcsAccountName = (entity) => {
|
|
359
|
-
const rcsData =
|
|
369
|
+
/** Get RCS account name from the account's domain (like campaigns-v2: rcsSender display) */
|
|
370
|
+
export const getRcsAccountName = (entity, sourceAccountId = '') => {
|
|
371
|
+
const rcsData = getRcsDomainBySourceAccount(entity, sourceAccountId);
|
|
360
372
|
if (!rcsData) return '';
|
|
361
373
|
return rcsData.domainProperties?.domainName || rcsData.domainName || rcsData.label || '';
|
|
362
374
|
};
|
|
@@ -623,6 +635,7 @@ export const getFieldsForChannels = (channels = []) => {
|
|
|
623
635
|
export const parseEntityForDisplay = (entity, context = {}) => {
|
|
624
636
|
if (!entity) return null;
|
|
625
637
|
const whatsappSourceAccountId = context?.whatsappSourceAccountId || '';
|
|
638
|
+
const rcsSourceAccountId = context?.rcsSourceAccountId || '';
|
|
626
639
|
return {
|
|
627
640
|
senderDetails: entity,
|
|
628
641
|
smsSenderId: getSmsSenderIdValue(entity),
|
|
@@ -637,12 +650,12 @@ export const parseEntityForDisplay = (entity, context = {}) => {
|
|
|
637
650
|
lineSenderId: getSenderIdFromContactInfo(entity, 'LINE'),
|
|
638
651
|
whatsappSenderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }),
|
|
639
652
|
whatsappAccountName: getWhatsappAccountName(entity, whatsappSourceAccountId),
|
|
640
|
-
rcsSenderNumber: getRcsSenderNumberValue(entity),
|
|
641
|
-
rcsAccountName: getRcsAccountName(entity),
|
|
653
|
+
rcsSenderNumber: getRcsSenderNumberValue(entity, { rcsSourceAccountId }),
|
|
654
|
+
rcsAccountName: getRcsAccountName(entity, rcsSourceAccountId),
|
|
642
655
|
// RCS SMS-fallback: sourced from the SMS domain data (same as the SMS channel's own fields).
|
|
643
656
|
rcsSmsFallbackDomain: getSmsDomainValue(entity),
|
|
644
657
|
rcsSmsFallbackSenderId: getSmsSenderIdValue(entity),
|
|
645
|
-
senderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }) || getRcsSenderNumberValue(entity),
|
|
658
|
+
senderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }) || getRcsSenderNumberValue(entity, { rcsSourceAccountId }),
|
|
646
659
|
};
|
|
647
660
|
};
|
|
648
661
|
|
|
@@ -92,6 +92,7 @@ import { IMAGE, VIDEO } from '../Facebook/Advertisement/constant';
|
|
|
92
92
|
import { RCS_STATUSES, contentType as RCS_CONTENT_TYPE, EMBEDDED } from '../Rcs/constants';
|
|
93
93
|
import { pickRcsCardVarMappedEntries } from '../Rcs/rcsLibraryHydrationUtils';
|
|
94
94
|
import { mapRcsCardContentForConsumerWithResolvedTags } from '../Rcs/utils';
|
|
95
|
+
import { isRcsAccountForAccountId } from '../Rcs/accountUtils';
|
|
95
96
|
import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../../v2Components/CommonTestAndPreview/constants';
|
|
96
97
|
import { CREATIVE } from '../Facebook/constants';
|
|
97
98
|
import { LOYALTY } from '../App/constants';
|
|
@@ -1480,11 +1481,26 @@ export class Creatives extends React.Component {
|
|
|
1480
1481
|
cardVarMappedFromFirstRcsCard
|
|
1481
1482
|
&& Object.keys(cardVarMappedFromFirstRcsCard).length > 0
|
|
1482
1483
|
&& isFullModeForRcsConsumerPayload === true;
|
|
1484
|
+
// Multi-account (same contract as WhatsApp): tell the consumer which RCS account the template
|
|
1485
|
+
// belongs to. Use the selected account only when it is the one the template was saved with;
|
|
1486
|
+
// otherwise keep what the consumer passed in, so a stale selection never re-tags a template.
|
|
1487
|
+
const { Templates: templatesForRcsAccount, templateData: rcsTemplateDataProps } = this.props;
|
|
1488
|
+
const selectedRcsAccount = templatesForRcsAccount?.selectedRcsAccount;
|
|
1489
|
+
const isSelectedRcsAccountForTemplate = !isEmpty(selectedRcsAccount)
|
|
1490
|
+
&& (!accountId || isRcsAccountForAccountId(selectedRcsAccount, accountId));
|
|
1491
|
+
const rcsSourceAccountIdentifier = isSelectedRcsAccountForTemplate
|
|
1492
|
+
? (selectedRcsAccount?.sourceAccountIdentifier || '')
|
|
1493
|
+
: (rcsTemplateDataProps?.sourceAccountIdentifier || rcsTemplateDataProps?.accountDetails?.sourceAccountIdentifier || '');
|
|
1494
|
+
const rcsAccountName = isSelectedRcsAccountForTemplate
|
|
1495
|
+
? (selectedRcsAccount?.name || '')
|
|
1496
|
+
: (rcsTemplateDataProps?.accountName || rcsTemplateDataProps?.accountDetails?.name || '');
|
|
1483
1497
|
templateData = {
|
|
1484
1498
|
channel,
|
|
1485
1499
|
creativeName: name,
|
|
1486
1500
|
rcsContent,
|
|
1487
1501
|
accountId,
|
|
1502
|
+
...(rcsSourceAccountIdentifier && { sourceAccountIdentifier: rcsSourceAccountIdentifier }),
|
|
1503
|
+
...(rcsAccountName && { accountName: rcsAccountName }),
|
|
1488
1504
|
...(vfTemplateId && { templateId: vfTemplateId }),
|
|
1489
1505
|
...(includeRootRcsCardVarMappedOnConsumerPayload
|
|
1490
1506
|
? { rcsCardVarMapped: cardVarMappedFromFirstRcsCard }
|
|
@@ -250,6 +250,72 @@ describe('Test SlideBoxContent container', () => {
|
|
|
250
250
|
expect(instance.state.templateData.smsFallBackContent).toEqual({ message: 'fallback-body' });
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
+
describe('RCS multi-account fields on consumer templateData', () => {
|
|
254
|
+
const rcsAccountA = { id: 101, name: 'Brand A', sourceAccountIdentifier: 'acc-A' };
|
|
255
|
+
const buildRcsFormValue = (accountId) => ({
|
|
256
|
+
validity: true,
|
|
257
|
+
value: {
|
|
258
|
+
name: 'rcs_creative_name',
|
|
259
|
+
type: 'RCS',
|
|
260
|
+
versions: {
|
|
261
|
+
base: {
|
|
262
|
+
content: {
|
|
263
|
+
RCS: {
|
|
264
|
+
rcsContent: {
|
|
265
|
+
contentType: 'RICHCARD', cardType: 'STANDALONE', cardSettings: {}, cardContent: [{}], accountId,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
const renderRcsEdit = ({ selectedRcsAccount, templateData = rcsEditTemplateData }) => shallowWithIntl(
|
|
274
|
+
<Creatives
|
|
275
|
+
loyaltyMetaData={loyaltyMetaData}
|
|
276
|
+
Templates={{ ...rcsTemplates, selectedRcsAccount }}
|
|
277
|
+
channel="RCS"
|
|
278
|
+
slidBoxContent="editTemplate"
|
|
279
|
+
templateData={templateData}
|
|
280
|
+
handleCloseCreatives={handleCloseCreatives}
|
|
281
|
+
getCreativesData={getCreativesData}
|
|
282
|
+
isFullMode={false}
|
|
283
|
+
templateActions={{
|
|
284
|
+
getCdnTransformationConfig,
|
|
285
|
+
}}
|
|
286
|
+
/>,
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
it('adds the selected account when it is the account the template was saved with', async () => {
|
|
290
|
+
const wrapper = renderRcsEdit({ selectedRcsAccount: rcsAccountA });
|
|
291
|
+
const formValue = buildRcsFormValue('101');
|
|
292
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
293
|
+
expect(templateData.accountId).toBe('101');
|
|
294
|
+
expect(templateData.sourceAccountIdentifier).toBe('acc-A');
|
|
295
|
+
expect(templateData.accountName).toBe('Brand A');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('keeps the consumer-provided account when the selected account belongs to another account', async () => {
|
|
299
|
+
const wrapper = renderRcsEdit({
|
|
300
|
+
selectedRcsAccount: rcsAccountA,
|
|
301
|
+
templateData: { ...rcsEditTemplateData, sourceAccountIdentifier: 'acc-B', accountName: 'Brand B' },
|
|
302
|
+
});
|
|
303
|
+
const formValue = buildRcsFormValue('202');
|
|
304
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
305
|
+
expect(templateData.accountId).toBe('202');
|
|
306
|
+
expect(templateData.sourceAccountIdentifier).toBe('acc-B');
|
|
307
|
+
expect(templateData.accountName).toBe('Brand B');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('omits the account fields when no account is known', async () => {
|
|
311
|
+
const wrapper = renderRcsEdit({ selectedRcsAccount: undefined });
|
|
312
|
+
const formValue = buildRcsFormValue('');
|
|
313
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
314
|
+
expect(templateData).not.toHaveProperty('sourceAccountIdentifier');
|
|
315
|
+
expect(templateData).not.toHaveProperty('accountName');
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
253
319
|
it('RCS getFormData mirrors rcsCardVarMapped onto templateData for campaign reopen', async () => {
|
|
254
320
|
renderedComponent = shallowWithIntl(
|
|
255
321
|
<Creatives
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RCS multi-account helpers.
|
|
3
|
+
*
|
|
4
|
+
* A saved RCS template stores its account in `rcsContent.accountId`: the WeCRM account's
|
|
5
|
+
* sourceAccountIdentifier (full mode) or its WeCRM id (library mode).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const toTrimmedString = (value) => (value == null ? '' : String(value).trim());
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether a WeCRM RCS account is the one referenced by a saved `rcsContent.accountId`.
|
|
12
|
+
* @param {Object} account - WeCRM RCS account ({ id, sourceAccountIdentifier, ... })
|
|
13
|
+
* @param {string|number} accountId - saved rcsContent.accountId
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export const isRcsAccountForAccountId = (account, accountId) => {
|
|
17
|
+
const id = toTrimmedString(accountId);
|
|
18
|
+
if (!account || !id) return false;
|
|
19
|
+
return [account.sourceAccountIdentifier, account.id].map(toTrimmedString).includes(id);
|
|
20
|
+
};
|
|
@@ -162,6 +162,7 @@ import {
|
|
|
162
162
|
checkSmsFallbackBlocksDone,
|
|
163
163
|
isSmsFallbackContentTooLong,
|
|
164
164
|
} from './utils';
|
|
165
|
+
import { isRcsAccountForAccountId } from './accountUtils';
|
|
165
166
|
import {
|
|
166
167
|
getCarouselImageAssetIndex,
|
|
167
168
|
getCarouselVideoAssetIndex,
|
|
@@ -374,6 +375,22 @@ export const Rcs = (props) => {
|
|
|
374
375
|
setSuggestions(isHostIcs ? INITIAL_SUGGESTIONS_DATA_STOP : []);
|
|
375
376
|
}, [isHostIcs]);
|
|
376
377
|
const [rcsAccount, setRcsAccount] = useState('');
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Test & Preview options. `sourceAccountIdentifier` scopes RCS senders to this template's account
|
|
381
|
+
* (multi-account orgs). It is sent only when the selected account is the template's own account,
|
|
382
|
+
* so a stale selection from another account never narrows the sender list.
|
|
383
|
+
*/
|
|
384
|
+
const rcsTestPreviewOptions = useMemo(() => {
|
|
385
|
+
const selectedRcsAccount = accountData?.selectedRcsAccount;
|
|
386
|
+
const isSelectedAccountForTemplate = !isEmpty(selectedRcsAccount)
|
|
387
|
+
&& (!rcsAccount || isRcsAccountForAccountId(selectedRcsAccount, rcsAccount));
|
|
388
|
+
return {
|
|
389
|
+
isLibraryMode: !isFullMode,
|
|
390
|
+
...(isSelectedAccountForTemplate && accountId && { sourceAccountIdentifier: accountId }),
|
|
391
|
+
};
|
|
392
|
+
}, [isFullMode, accountData?.selectedRcsAccount, rcsAccount, accountId]);
|
|
393
|
+
|
|
377
394
|
useEffect(() => {
|
|
378
395
|
const accountObj = accountData.selectedRcsAccount || {};
|
|
379
396
|
if (!isEmpty(accountObj)) {
|
|
@@ -3507,7 +3524,7 @@ const onTitleAddVar = () => {
|
|
|
3507
3524
|
content={testAndPreviewContent}
|
|
3508
3525
|
currentChannel={RCS}
|
|
3509
3526
|
orgUnitId={orgUnitId}
|
|
3510
|
-
rcsTestPreviewOptions={
|
|
3527
|
+
rcsTestPreviewOptions={rcsTestPreviewOptions}
|
|
3511
3528
|
smsFallbackContent={
|
|
3512
3529
|
smsFallbackData && (smsFallbackData.templateContent || smsFallbackData.content)
|
|
3513
3530
|
? {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isRcsAccountForAccountId } from '../accountUtils';
|
|
2
|
+
|
|
3
|
+
describe('Rcs/accountUtils', () => {
|
|
4
|
+
describe('isRcsAccountForAccountId', () => {
|
|
5
|
+
const account = { id: 101, sourceAccountIdentifier: 'acc-A' };
|
|
6
|
+
|
|
7
|
+
it('matches sourceAccountIdentifier or WeCRM id', () => {
|
|
8
|
+
expect(isRcsAccountForAccountId(account, 'acc-A')).toBe(true);
|
|
9
|
+
expect(isRcsAccountForAccountId(account, 101)).toBe(true);
|
|
10
|
+
expect(isRcsAccountForAccountId(account, '101')).toBe(true);
|
|
11
|
+
expect(isRcsAccountForAccountId(account, ' acc-A ')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('does not match a different id', () => {
|
|
15
|
+
expect(isRcsAccountForAccountId(account, 'acc-B')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns false for empty id or account', () => {
|
|
19
|
+
expect(isRcsAccountForAccountId(account, '')).toBe(false);
|
|
20
|
+
expect(isRcsAccountForAccountId(account, undefined)).toBe(false);
|
|
21
|
+
expect(isRcsAccountForAccountId(null, 'acc-A')).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1663,6 +1663,29 @@ describe('botId in create payload', () => {
|
|
|
1663
1663
|
wrapper.update();
|
|
1664
1664
|
};
|
|
1665
1665
|
|
|
1666
|
+
it('passes the selected account sourceAccountIdentifier to Test & Preview (multi-account sender scoping)', () => {
|
|
1667
|
+
const wrapper = mountRcs({
|
|
1668
|
+
selectedRcsAccount: {
|
|
1669
|
+
id: 'acc-wecrm-1',
|
|
1670
|
+
sourceAccountIdentifier: 'acc-src-1',
|
|
1671
|
+
configs: { accessToken: 'token-1' },
|
|
1672
|
+
hostName: 'rcsvaluefirstbulk',
|
|
1673
|
+
name: 'Brand A',
|
|
1674
|
+
},
|
|
1675
|
+
});
|
|
1676
|
+
const slidebox = wrapper.find('TestAndPreviewSlidebox').at(0);
|
|
1677
|
+
expect(slidebox.props().rcsTestPreviewOptions).toEqual({
|
|
1678
|
+
isLibraryMode: false,
|
|
1679
|
+
sourceAccountIdentifier: 'acc-src-1',
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
|
|
1683
|
+
it('does not scope Test & Preview senders when no account is selected', () => {
|
|
1684
|
+
const wrapper = mountRcs({});
|
|
1685
|
+
const slidebox = wrapper.find('TestAndPreviewSlidebox').at(0);
|
|
1686
|
+
expect(slidebox.props().rcsTestPreviewOptions).toEqual({ isLibraryMode: false });
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1666
1689
|
it('includes botId from connectionProperties.agentid for ValueFirst accounts', async () => {
|
|
1667
1690
|
const createRcsTemplate = jest.fn();
|
|
1668
1691
|
const accountData = {
|
|
@@ -152,6 +152,18 @@ function ChannelTypeIllustration(props) {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
// RCS (same as WhatsApp): no hostName means the selected account has no matching domain.
|
|
156
|
+
if (type === RCS && !hostName) {
|
|
157
|
+
return {
|
|
158
|
+
illustrationImage: whatsappOrZaloAccountIllustration,
|
|
159
|
+
title: <FormattedMessage {...messages.rcsAccountNotConfiguredTitle} />,
|
|
160
|
+
description: <FormattedMessage {...messages.accountNotConfiguredDescription} />,
|
|
161
|
+
descriptionPosition: 'bottom',
|
|
162
|
+
descriptionClassName: 'illustration-desc zalo-illustration',
|
|
163
|
+
buttonClassName: 'zalo-illustration-button',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
155
167
|
if (type === WEBPUSH) {
|
|
156
168
|
return {
|
|
157
169
|
buttonLabel: <FormattedMessage {...messages.newWebPushTemplate} values={{ template: templateText }} />,
|
|
@@ -2143,7 +2143,8 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
2143
2143
|
isTraiDltFeature = this.checkDLTfeatureEnable();
|
|
2144
2144
|
break;
|
|
2145
2145
|
case RCS:
|
|
2146
|
-
|
|
2146
|
+
// Same as WhatsApp: no hostName means the account's domain is not configured, so no templates are shown.
|
|
2147
|
+
filteredTemplates = this.state?.hostName ? this.filterRcsTemplates(templates) : [];
|
|
2147
2148
|
break;
|
|
2148
2149
|
case ZALO:
|
|
2149
2150
|
filteredTemplates = this.filterZaloTemplates(templates);
|
|
@@ -2934,6 +2935,9 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
2934
2935
|
const noApprovedWhatsappZaloTemplates = filteredEmptyAndFullModeAs(false) && !isEmpty(this.state?.hostName);
|
|
2935
2936
|
const showWhatsappIllustration = accountWithNoHostWhatsapp(WHATSAPP_LOWERCASE);
|
|
2936
2937
|
const showZaloIllustration = accountWithNoHostZalo(ZALO_LOWERCASE)
|
|
2938
|
+
// RCS (same as WhatsApp): the selected account has no matching domain, so it is not configured.
|
|
2939
|
+
const showRcsAccountNotConfigured = channelLowerCase === RCS_LOWERCASE && !this.state?.hostName
|
|
2940
|
+
&& isEmpty(this.state.searchText) && !isLoading && !get(this.props, 'Templates.isArchivedMode', false);
|
|
2937
2941
|
|
|
2938
2942
|
const noLoaderAndSearchText = isEmpty(this.state.searchText) && !isLoading;
|
|
2939
2943
|
|
|
@@ -3027,10 +3031,10 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
3027
3031
|
</div>
|
|
3028
3032
|
)
|
|
3029
3033
|
}
|
|
3030
|
-
{showIllustrationForChannel(RCS_LOWERCASE) &&
|
|
3034
|
+
{(showIllustrationForChannel(RCS_LOWERCASE) || showRcsAccountNotConfigured) &&
|
|
3031
3035
|
<div style={this.isFullMode() ? { height: "calc(100vh - 325px)", overflow: 'auto' } : {}}>
|
|
3032
|
-
<ChannelTypeIllustration isFullMode={this.props.isFullMode} createTemplate={this.createTemplate} canCreate={this.canPerform(PERMISSIONS.CREATIVE_CREATE)} currentChannel={currentChannel}/>
|
|
3033
|
-
{filteredEmptyAndFullModeAs(false) && this.whatsappZaloIllustrationText(noApprovedRcsTemplatesTitle, noApprovedRcsTemplatesDesc)}
|
|
3036
|
+
<ChannelTypeIllustration isFullMode={this.props.isFullMode} createTemplate={this.createTemplate} canCreate={this.canPerform(PERMISSIONS.CREATIVE_CREATE)} currentChannel={currentChannel} hostName={this.state?.hostName}/>
|
|
3037
|
+
{!showRcsAccountNotConfigured && filteredEmptyAndFullModeAs(false) && this.whatsappZaloIllustrationText(noApprovedRcsTemplatesTitle, noApprovedRcsTemplatesDesc)}
|
|
3034
3038
|
</div>
|
|
3035
3039
|
}
|
|
3036
3040
|
{showIllustrationForChannel(INAPP_LOWERCASE) &&
|
|
@@ -410,6 +410,10 @@ export default defineMessages({
|
|
|
410
410
|
id: `${scope}.accountNotConfiguredDescription`,
|
|
411
411
|
defaultMessage: 'Please contact your Customer Success Manager to fix the issue.',
|
|
412
412
|
},
|
|
413
|
+
"rcsAccountNotConfiguredTitle": {
|
|
414
|
+
id: `${scope}.rcsAccountNotConfiguredTitle`,
|
|
415
|
+
defaultMessage: 'RCS account is not configured',
|
|
416
|
+
},
|
|
413
417
|
"zaloAccountNotConfiguredTitle": {
|
|
414
418
|
id: `${scope}.zaloAccountNotConfiguredTitle`,
|
|
415
419
|
defaultMessage: 'Zalo account is not configured',
|
|
@@ -152,8 +152,8 @@ describe('ChannelTypeIllustration', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
describe('RCS Channel', () => {
|
|
155
|
-
it('should return correct illustration info for RCS channel', () => {
|
|
156
|
-
const component = renderComponent({ currentChannel: RCS });
|
|
155
|
+
it('should return correct illustration info for RCS channel when hostName is available', () => {
|
|
156
|
+
const component = renderComponent({ currentChannel: RCS, hostName: 'ics' });
|
|
157
157
|
const capIllustration = component.find('CapIllustration');
|
|
158
158
|
|
|
159
159
|
expect(capIllustration.prop('illustrationImage')).toBe('test-file-stub');
|
|
@@ -164,6 +164,18 @@ describe('ChannelTypeIllustration', () => {
|
|
|
164
164
|
expect(capIllustration.prop('descriptionPosition')).toBe('bottom');
|
|
165
165
|
expect(capIllustration.prop('descriptionClassName')).toBe('illustration-desc rcs-illustration');
|
|
166
166
|
});
|
|
167
|
+
|
|
168
|
+
it('should return account not configured info for RCS when hostName is not available (same as WhatsApp)', () => {
|
|
169
|
+
const component = renderComponent({ currentChannel: RCS, hostName: '' });
|
|
170
|
+
const capIllustration = component.find('CapIllustration');
|
|
171
|
+
|
|
172
|
+
expect(capIllustration.prop('title').props.id).toBe('creatives.containersV2.Templates.rcsAccountNotConfiguredTitle');
|
|
173
|
+
expect(capIllustration.prop('description').props.id).toBe('creatives.containersV2.Templates.accountNotConfiguredDescription');
|
|
174
|
+
expect(capIllustration.prop('descriptionClassName')).toBe('illustration-desc zalo-illustration');
|
|
175
|
+
expect(capIllustration.prop('buttonClassName')).toBe('zalo-illustration-button');
|
|
176
|
+
expect(capIllustration.prop('onClick')).toBeUndefined();
|
|
177
|
+
expect(capIllustration.prop('buttonLabel')).toBeUndefined();
|
|
178
|
+
});
|
|
167
179
|
});
|
|
168
180
|
|
|
169
181
|
describe('ZALO Channel', () => {
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
|
|
3
3
|
|
|
4
4
|
import { Templates } from '../index';
|
|
5
|
+
import ChannelTypeIllustration from '../ChannelTypeIllustration';
|
|
5
6
|
import mockdata from '../../mockdata';
|
|
6
7
|
import { rcsTemplates, senderDetailsRcs } from './mockData';
|
|
7
8
|
import { exportEmailTemplateHtml } from '../../../utils/downloadFile';
|
|
@@ -454,6 +455,8 @@ describe('Test Templates container', () => {
|
|
|
454
455
|
Global: { user: { accessiblePermissions: [PERMISSIONS.CREATIVE_EDIT] } },
|
|
455
456
|
actions: { ...renderedComponent.props().actions, resetTemplateData: jest.fn() },
|
|
456
457
|
});
|
|
458
|
+
// A configured account (its domain was found), so the RCS templates are listed.
|
|
459
|
+
renderedComponent.setState({ hostName: 'ics' });
|
|
457
460
|
});
|
|
458
461
|
|
|
459
462
|
it('does not render the Duplicate menu item for RCS', () => {
|
|
@@ -499,6 +502,104 @@ describe('Test Templates container', () => {
|
|
|
499
502
|
});
|
|
500
503
|
});
|
|
501
504
|
|
|
505
|
+
describe('RCS multi-account (same as WhatsApp)', () => {
|
|
506
|
+
const accountA = { id: 1, name: 'Brand A', sourceAccountIdentifier: 'acc-A', configs: { accessToken: 'token-A' } };
|
|
507
|
+
const accountB = { id: 2, name: 'Brand B', sourceAccountIdentifier: 'acc-B', configs: { accessToken: 'token-B' } };
|
|
508
|
+
const accountUnconfigured = { id: 3, name: 'Brand C', sourceAccountIdentifier: 'acc-C', configs: { accessToken: 'token-C' } };
|
|
509
|
+
const rcsDomain = (hostName, sourceAccountIdentifier) => ({
|
|
510
|
+
domainProperties: { hostName, domainName: `${hostName}-${sourceAccountIdentifier}`, connectionProperties: { sourceAccountIdentifier } },
|
|
511
|
+
});
|
|
512
|
+
const domainProperties = [rcsDomain('ics', 'acc-A'), rcsDomain('infobip', 'acc-B')];
|
|
513
|
+
|
|
514
|
+
const renderRcsWithAccounts = () => {
|
|
515
|
+
RenderFunctionFor('rcs', true);
|
|
516
|
+
renderedComponent.setProps({
|
|
517
|
+
Templates: {
|
|
518
|
+
...rcsTemplates,
|
|
519
|
+
weCrmAccounts: [accountA, accountB, accountUnconfigured],
|
|
520
|
+
senderDetails: { domainProperties },
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
getAllTemplates.mockClear();
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
const findByType = (node, type, seen = new Set()) => {
|
|
527
|
+
if (!node || typeof node !== 'object' || seen.has(node)) return null;
|
|
528
|
+
seen.add(node);
|
|
529
|
+
if (Array.isArray(node)) {
|
|
530
|
+
for (let i = 0; i < node.length; i += 1) {
|
|
531
|
+
const found = findByType(node[i], type, seen);
|
|
532
|
+
if (found) return found;
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
if (node.type === type) return node;
|
|
537
|
+
return node.props ? findByType(node.props.children, type, seen) : null;
|
|
538
|
+
};
|
|
539
|
+
const getGrid = (templates) => renderedComponent.instance().getTemplateDataForGrid({
|
|
540
|
+
templates,
|
|
541
|
+
handlers: { handlePreviewClick: jest.fn(), handleEditClick: jest.fn() },
|
|
542
|
+
filterContent: null,
|
|
543
|
+
channel: 'rcs',
|
|
544
|
+
isLoading: false,
|
|
545
|
+
isInitialLoading: false,
|
|
546
|
+
loadingTip: '',
|
|
547
|
+
previewTemplateId: null,
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it('selecting an account picks the domain whose connectionProperties hold its sourceAccountIdentifier and loads its templates', () => {
|
|
551
|
+
renderRcsWithAccounts();
|
|
552
|
+
renderedComponent.instance().onAccountSelect({ target: { value: 'Brand B' } });
|
|
553
|
+
|
|
554
|
+
expect(renderedComponent.state('hostName')).toBe('infobip');
|
|
555
|
+
expect(setChannelAccount).toHaveBeenCalledWith('RCS', expect.objectContaining({
|
|
556
|
+
name: 'Brand B',
|
|
557
|
+
hostName: 'infobip',
|
|
558
|
+
connectionProperties: { sourceAccountIdentifier: 'acc-B' },
|
|
559
|
+
}));
|
|
560
|
+
expect(getAllTemplates).toHaveBeenCalledWith(
|
|
561
|
+
'Rcs',
|
|
562
|
+
expect.objectContaining({ accountId: 'acc-B', host: 'infobip', accessToken: 'token-B' }),
|
|
563
|
+
expect.anything(),
|
|
564
|
+
);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
it('selecting an account with no matching domain makes no listing call and leaves hostName empty', () => {
|
|
568
|
+
renderRcsWithAccounts();
|
|
569
|
+
renderedComponent.instance().onAccountSelect({ target: { value: 'Brand C' } });
|
|
570
|
+
|
|
571
|
+
expect(renderedComponent.state('hostName')).toBe('');
|
|
572
|
+
expect(getAllTemplates).not.toHaveBeenCalled();
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it('shows "RCS account is not configured" and hides any templates when hostName is empty', () => {
|
|
576
|
+
renderRcsWithAccounts();
|
|
577
|
+
renderedComponent.setState({ hostName: '' });
|
|
578
|
+
const approvedRcsTemplate = {
|
|
579
|
+
_id: 'rcs_1',
|
|
580
|
+
versions: { base: { content: { RCS: { rcsContent: { cardContent: [{ Status: 'approved' }] } } } } },
|
|
581
|
+
};
|
|
582
|
+
const grid = getGrid([approvedRcsTemplate]);
|
|
583
|
+
const illustration = findByType(grid, ChannelTypeIllustration);
|
|
584
|
+
|
|
585
|
+
expect(illustration).not.toBeNull();
|
|
586
|
+
expect(illustration.props.hostName).toBe('');
|
|
587
|
+
expect(illustration.props.currentChannel).toBe('RCS');
|
|
588
|
+
expect(findByClassName(grid, 'v2-pagination-container')).toBeNull();
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('does not show the not-configured illustration when the account has a domain', () => {
|
|
592
|
+
renderRcsWithAccounts();
|
|
593
|
+
renderedComponent.setState({ hostName: 'ics' });
|
|
594
|
+
const approvedRcsTemplate = {
|
|
595
|
+
_id: 'rcs_1',
|
|
596
|
+
versions: { base: { content: { RCS: { rcsContent: { cardContent: [{ Status: 'approved' }] } } } } },
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
expect(findByType(getGrid([approvedRcsTemplate]), ChannelTypeIllustration)).toBeNull();
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
|
|
502
603
|
describe('Mobile push grid tile buttons', () => {
|
|
503
604
|
it('renders button labels as typed with index keys, so duplicate labels do not clash', () => {
|
|
504
605
|
RenderFunctionFor('whatsapp', true);
|