@capillarytech/creatives-library 8.0.290-alpha.3 → 8.0.290

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.
Files changed (76) hide show
  1. package/constants/unified.js +1 -0
  2. package/initialState.js +2 -0
  3. package/package.json +1 -1
  4. package/utils/common.js +8 -5
  5. package/utils/commonUtils.js +85 -4
  6. package/utils/tagValidations.js +222 -84
  7. package/utils/tests/commonUtil.test.js +124 -147
  8. package/utils/tests/tagValidations.test.js +358 -280
  9. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +33 -0
  10. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +397 -0
  11. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.scss +35 -0
  12. package/v2Components/CommonTestAndPreview/DeliverySettings/TECH_DETAILING_DELIVERY_SETTINGS.md +725 -0
  13. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +92 -0
  14. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +243 -0
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +111 -0
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +91 -0
  17. package/v2Components/CommonTestAndPreview/SendTestMessage.js +33 -1
  18. package/v2Components/CommonTestAndPreview/actions.js +20 -0
  19. package/v2Components/CommonTestAndPreview/constants.js +10 -0
  20. package/v2Components/CommonTestAndPreview/index.js +133 -15
  21. package/v2Components/CommonTestAndPreview/reducer.js +47 -0
  22. package/v2Components/CommonTestAndPreview/sagas.js +60 -0
  23. package/v2Components/CommonTestAndPreview/selectors.js +51 -0
  24. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +782 -0
  25. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +200 -0
  26. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +235 -0
  27. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +127 -0
  28. package/v2Components/CommonTestAndPreview/tests/actions.test.js +50 -0
  29. package/v2Components/CommonTestAndPreview/tests/constants.test.js +18 -0
  30. package/v2Components/CommonTestAndPreview/tests/index.test.js +214 -1
  31. package/v2Components/CommonTestAndPreview/tests/reducer.test.js +118 -0
  32. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +145 -0
  33. package/v2Components/CommonTestAndPreview/tests/selectors.test.js +146 -0
  34. package/v2Components/ErrorInfoNote/index.js +5 -2
  35. package/v2Components/FormBuilder/index.js +162 -84
  36. package/v2Components/FormBuilder/messages.js +8 -0
  37. package/v2Components/HtmlEditor/HTMLEditor.js +5 -0
  38. package/v2Components/HtmlEditor/__tests__/HTMLEditor.apiErrors.test.js +1 -0
  39. package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +15 -0
  40. package/v2Components/HtmlEditor/components/CodeEditorPane/index.js +2 -1
  41. package/v2Components/TestAndPreviewSlidebox/index.js +14 -0
  42. package/v2Containers/Cap/mockData.js +14 -0
  43. package/v2Containers/Cap/reducer.js +55 -3
  44. package/v2Containers/Cap/tests/reducer.test.js +102 -0
  45. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -3
  46. package/v2Containers/CreativesContainer/index.js +6 -19
  47. package/v2Containers/Email/index.js +5 -1
  48. package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +62 -10
  49. package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +115 -12
  50. package/v2Containers/FTP/index.js +51 -2
  51. package/v2Containers/FTP/messages.js +4 -0
  52. package/v2Containers/InApp/index.js +96 -1
  53. package/v2Containers/InApp/tests/index.test.js +6 -17
  54. package/v2Containers/InappAdvance/index.js +103 -2
  55. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +24 -3
  56. package/v2Containers/Line/Container/Text/index.js +1 -0
  57. package/v2Containers/MobilePush/Create/index.js +16 -6
  58. package/v2Containers/MobilePush/Edit/index.js +16 -6
  59. package/v2Containers/MobilePushNew/index.js +33 -2
  60. package/v2Containers/Rcs/index.js +37 -12
  61. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +667 -16
  62. package/v2Containers/Sms/Create/index.js +3 -35
  63. package/v2Containers/Sms/Create/messages.js +0 -4
  64. package/v2Containers/Sms/Edit/index.js +3 -33
  65. package/v2Containers/Sms/commonMethods.js +6 -6
  66. package/v2Containers/SmsTrai/Edit/index.js +47 -6
  67. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +147 -6
  68. package/v2Containers/Viber/index.js +1 -0
  69. package/v2Containers/WebPush/Create/hooks/useTagManagement.js +3 -1
  70. package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +7 -0
  71. package/v2Containers/WebPush/Create/index.js +2 -2
  72. package/v2Containers/WebPush/Create/utils/validation.js +2 -17
  73. package/v2Containers/WebPush/Create/utils/validation.test.js +24 -0
  74. package/v2Containers/Whatsapp/index.js +18 -10
  75. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +25849 -3524
  76. package/v2Containers/Zalo/index.js +11 -3
@@ -52,12 +52,14 @@ jest.mock('../CustomValuesEditor', () => {
52
52
  };
53
53
  });
54
54
 
55
+ let lastSendTestMessageProps = null;
55
56
  jest.mock('../SendTestMessage', () => {
56
57
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
57
58
  const ReactLib = require('react');
58
59
  return {
59
60
  __esModule: true,
60
- default: function MockSendTestMessage() {
61
+ default: function MockSendTestMessage(props) {
62
+ lastSendTestMessageProps = props;
61
63
  return ReactLib.createElement('div', { 'data-testid': 'send-test-message' }, 'Send Test Message');
62
64
  },
63
65
  };
@@ -122,6 +124,8 @@ describe('CommonTestAndPreview', () => {
122
124
  getPrefilledValuesRequested: jest.fn(),
123
125
  clearPrefilledValues: jest.fn(),
124
126
  clearPreviewErrors: jest.fn(),
127
+ getSenderDetailsRequested: jest.fn(),
128
+ getWeCrmAccountsRequested: jest.fn(),
125
129
  };
126
130
 
127
131
  const defaultProps = {
@@ -171,10 +175,15 @@ describe('CommonTestAndPreview', () => {
171
175
  fetchPrefilledValuesErrors: [],
172
176
  isSendingTestMessage: false,
173
177
  currentTab: 1,
178
+ senderDetailsByChannel: {},
179
+ wecrmAccounts: [],
180
+ isLoadingSenderDetails: false,
181
+ orgUnitId: -1,
174
182
  };
175
183
 
176
184
  beforeEach(() => {
177
185
  jest.clearAllMocks();
186
+ lastSendTestMessageProps = null;
178
187
  // Reset all mock function implementations
179
188
  Object.values(mockActions).forEach((mockFn) => {
180
189
  if (jest.isMockFunction(mockFn)) {
@@ -183,6 +192,210 @@ describe('CommonTestAndPreview', () => {
183
192
  });
184
193
  });
185
194
 
195
+ describe('Delivery settings / sender ID', () => {
196
+ it('should call getSenderDetailsRequested when show and channel is SMS', async () => {
197
+ render(
198
+ <TestWrapper>
199
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.SMS} />
200
+ </TestWrapper>
201
+ );
202
+ await waitFor(() => {
203
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenCalledWith({
204
+ channel: CHANNELS.SMS,
205
+ orgUnitId: -1,
206
+ });
207
+ });
208
+ });
209
+
210
+ it('should call getSenderDetailsRequested when show and channel is EMAIL', async () => {
211
+ render(
212
+ <TestWrapper>
213
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.EMAIL} />
214
+ </TestWrapper>
215
+ );
216
+ await waitFor(() => {
217
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenCalledWith({
218
+ channel: CHANNELS.EMAIL,
219
+ orgUnitId: -1,
220
+ });
221
+ });
222
+ });
223
+
224
+ it('should call getSenderDetailsRequested and getWeCrmAccountsRequested when show and channel is WHATSAPP', async () => {
225
+ render(
226
+ <TestWrapper>
227
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.WHATSAPP} />
228
+ </TestWrapper>
229
+ );
230
+ await waitFor(() => {
231
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenCalledWith({
232
+ channel: CHANNELS.WHATSAPP,
233
+ orgUnitId: -1,
234
+ });
235
+ expect(mockActions.getWeCrmAccountsRequested).toHaveBeenCalledWith({
236
+ sourceName: CHANNELS.WHATSAPP,
237
+ });
238
+ });
239
+ });
240
+
241
+ it('should not call getSenderDetailsRequested when channel is INAPP', async () => {
242
+ render(
243
+ <TestWrapper>
244
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.INAPP} />
245
+ </TestWrapper>
246
+ );
247
+ await waitFor(() => {
248
+ expect(screen.getByTestId('left-panel')).toBeTruthy();
249
+ });
250
+ expect(mockActions.getSenderDetailsRequested).not.toHaveBeenCalled();
251
+ expect(mockActions.getWeCrmAccountsRequested).not.toHaveBeenCalled();
252
+ });
253
+
254
+ it('should pass orgUnitId to getSenderDetailsRequested when provided', async () => {
255
+ render(
256
+ <TestWrapper>
257
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.SMS} orgUnitId={100} />
258
+ </TestWrapper>
259
+ );
260
+ await waitFor(() => {
261
+ expect(mockActions.getSenderDetailsRequested).toHaveBeenCalledWith({
262
+ channel: CHANNELS.SMS,
263
+ orgUnitId: 100,
264
+ });
265
+ });
266
+ });
267
+
268
+ it('should not call getSenderDetailsRequested when show is false', async () => {
269
+ render(
270
+ <TestWrapper>
271
+ <CommonTestAndPreview {...defaultProps} show={false} channel={CHANNELS.SMS} />
272
+ </TestWrapper>
273
+ );
274
+ await waitFor(() => {
275
+ expect(screen.queryByTestId('left-panel')).toBeNull();
276
+ });
277
+ expect(mockActions.getSenderDetailsRequested).not.toHaveBeenCalled();
278
+ });
279
+
280
+ it('should pass delivery-related props to SendTestMessage for SMS channel', async () => {
281
+ const senderDetailsByChannel = {
282
+ [CHANNELS.SMS]: [{ domainId: 1, domainName: 'SMS Dom', gsmSenders: [], cdmaSenders: [] }],
283
+ };
284
+ render(
285
+ <TestWrapper>
286
+ <CommonTestAndPreview
287
+ {...defaultProps}
288
+ channel={CHANNELS.SMS}
289
+ senderDetailsByChannel={senderDetailsByChannel}
290
+ wecrmAccounts={[]}
291
+ />
292
+ </TestWrapper>
293
+ );
294
+ await waitFor(() => {
295
+ expect(screen.getByTestId('send-test-message')).toBeTruthy();
296
+ });
297
+ expect(lastSendTestMessageProps).toBeDefined();
298
+ expect(lastSendTestMessageProps.deliverySettings).toBeDefined();
299
+ expect(lastSendTestMessageProps.senderDetailsOptions).toEqual(senderDetailsByChannel[CHANNELS.SMS]);
300
+ expect(lastSendTestMessageProps.wecrmAccounts).toEqual([]);
301
+ expect(typeof lastSendTestMessageProps.onSaveDeliverySettings).toBe('function');
302
+ expect(lastSendTestMessageProps.isLoadingSenderDetails).toBe(false);
303
+ });
304
+
305
+ it('should pass formDataForSendTest (formData when provided) to SendTestMessage', async () => {
306
+ render(
307
+ <TestWrapper>
308
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.EMAIL} />
309
+ </TestWrapper>
310
+ );
311
+ await waitFor(() => {
312
+ expect(lastSendTestMessageProps).toBeDefined();
313
+ });
314
+ expect(lastSendTestMessageProps.formData).toEqual(defaultProps.formData);
315
+ });
316
+
317
+ it('should auto-set WhatsApp delivery settings from formData accountName when matching account exists', async () => {
318
+ const senderDetailsByChannel = {
319
+ [CHANNELS.WHATSAPP]: [
320
+ {
321
+ domainId: 1,
322
+ sourceAccountIdentifier: 'waba-1',
323
+ gsmSenders: [{ value: '+1111111111' }],
324
+ },
325
+ {
326
+ domainId: 2,
327
+ sourceAccountIdentifier: 'waba-2',
328
+ gsmSenders: [{ value: '+2222222222' }],
329
+ },
330
+ ],
331
+ };
332
+ const wecrmAccounts = [
333
+ { name: 'Account One', sourceAccountIdentifier: 'waba-1' },
334
+ { name: 'Account Two', sourceAccountIdentifier: 'waba-2' },
335
+ ];
336
+
337
+ render(
338
+ <TestWrapper>
339
+ <CommonTestAndPreview
340
+ {...defaultProps}
341
+ channel={CHANNELS.WHATSAPP}
342
+ formData={{ accountName: 'Account Two', templateMsg: 'WhatsApp test' }}
343
+ senderDetailsByChannel={senderDetailsByChannel}
344
+ wecrmAccounts={wecrmAccounts}
345
+ />
346
+ </TestWrapper>
347
+ );
348
+
349
+ await waitFor(() => {
350
+ expect(lastSendTestMessageProps).toBeDefined();
351
+ expect(lastSendTestMessageProps.deliverySettings).toEqual({
352
+ domainId: 2,
353
+ senderMobNum: '+2222222222',
354
+ sourceAccountIdentifier: 'waba-2',
355
+ });
356
+ });
357
+ });
358
+
359
+ it('should include delivery settings in payload when handleSendTestMessage is called for EMAIL', async () => {
360
+ render(
361
+ <TestWrapper>
362
+ <CommonTestAndPreview {...defaultProps} channel={CHANNELS.EMAIL} />
363
+ </TestWrapper>
364
+ );
365
+ await waitFor(() => {
366
+ expect(lastSendTestMessageProps).toBeDefined();
367
+ expect(typeof lastSendTestMessageProps.handleSendTestMessage).toBe('function');
368
+ });
369
+ lastSendTestMessageProps.handleSendTestMessage();
370
+ expect(mockActions.createMessageMetaRequested).toHaveBeenCalled();
371
+ const [initialPayload] = mockActions.createMessageMetaRequested.mock.calls[0];
372
+ expect(initialPayload.emailDeliverySettings).toBeDefined();
373
+ expect(initialPayload.emailDeliverySettings.channelSettings).toBeDefined();
374
+ expect(initialPayload.emailDeliverySettings.channelSettings.channel).toBe(CHANNELS.EMAIL);
375
+ });
376
+
377
+ it('should include delivery settings in payload when handleSendTestMessage is called for SMS', async () => {
378
+ render(
379
+ <TestWrapper>
380
+ <CommonTestAndPreview
381
+ {...defaultProps}
382
+ channel={CHANNELS.SMS}
383
+ formData={{ 'sms-editor': 'Test SMS' }}
384
+ />
385
+ </TestWrapper>
386
+ );
387
+ await waitFor(() => {
388
+ expect(lastSendTestMessageProps).toBeDefined();
389
+ });
390
+ lastSendTestMessageProps.handleSendTestMessage();
391
+ expect(mockActions.createMessageMetaRequested).toHaveBeenCalled();
392
+ const [initialPayload] = mockActions.createMessageMetaRequested.mock.calls[0];
393
+ expect(initialPayload.smsDeliverySettings).toBeDefined();
394
+ expect(initialPayload.smsDeliverySettings.channelSettings).toBeDefined();
395
+ expect(initialPayload.smsDeliverySettings.channelSettings.channel).toBe(CHANNELS.SMS);
396
+ });
397
+ });
398
+
186
399
  describe('Component Rendering', () => {
187
400
  it('should render when show is true', async () => {
188
401
  render(
@@ -35,6 +35,13 @@ import {
35
35
  GET_PREFILLED_VALUES_FAILURE,
36
36
  CLEAR_PREFILLED_VALUES,
37
37
  CLEAR_PREVIEW_ERRORS,
38
+ GET_SENDER_DETAILS_REQUESTED,
39
+ GET_SENDER_DETAILS_SUCCESS,
40
+ GET_SENDER_DETAILS_FAILURE,
41
+ GET_WECRM_ACCOUNTS_REQUESTED,
42
+ GET_WECRM_ACCOUNTS_SUCCESS,
43
+ GET_WECRM_ACCOUNTS_FAILURE,
44
+ CHANNELS,
38
45
  } from '../constants';
39
46
 
40
47
  describe('previewAndTestReducer', () => {
@@ -80,6 +87,15 @@ describe('previewAndTestReducer', () => {
80
87
  isFetchingPrefilledValues: false,
81
88
  fetchPrefilledValuesError: null,
82
89
  fetchPrefilledValuesErrors: [],
90
+ senderDetailsByChannel: fromJS({
91
+ [CHANNELS.SMS]: [],
92
+ [CHANNELS.EMAIL]: [],
93
+ [CHANNELS.WHATSAPP]: [],
94
+ }),
95
+ wecrmAccounts: fromJS([]),
96
+ isLoadingSenderDetails: false,
97
+ fetchSenderDetailsError: null,
98
+ fetchWeCrmAccountsError: null,
83
99
  });
84
100
  });
85
101
 
@@ -773,6 +789,108 @@ describe('previewAndTestReducer', () => {
773
789
  });
774
790
  });
775
791
 
792
+ describe('GET_SENDER_DETAILS_REQUESTED', () => {
793
+ it('should set isLoadingSenderDetails to true and clear fetchSenderDetailsError', () => {
794
+ const action = {
795
+ type: GET_SENDER_DETAILS_REQUESTED,
796
+ payload: { channel: CHANNELS.SMS, orgUnitId: 123 },
797
+ };
798
+ const result = previewAndTestReducer(initialState, action);
799
+
800
+ expect(result.get('isLoadingSenderDetails')).toBe(true);
801
+ expect(result.get('fetchSenderDetailsError')).toBeNull();
802
+ });
803
+ });
804
+
805
+ describe('GET_SENDER_DETAILS_SUCCESS', () => {
806
+ it('should store domains for channel and set loading to false', () => {
807
+ const domains = [
808
+ { domainId: 1, domainName: 'Domain 1', gsmSenders: [] },
809
+ ];
810
+ const action = {
811
+ type: GET_SENDER_DETAILS_SUCCESS,
812
+ payload: { channel: CHANNELS.SMS, domains },
813
+ };
814
+ const result = previewAndTestReducer(initialState, action);
815
+
816
+ expect(result.getIn(['senderDetailsByChannel', CHANNELS.SMS])).toEqual(fromJS(domains));
817
+ expect(result.get('isLoadingSenderDetails')).toBe(false);
818
+ expect(result.get('fetchSenderDetailsError')).toBeNull();
819
+ });
820
+
821
+ it('should return state unchanged when channel is missing', () => {
822
+ const action = {
823
+ type: GET_SENDER_DETAILS_SUCCESS,
824
+ payload: { domains: [] },
825
+ };
826
+ const result = previewAndTestReducer(initialState, action);
827
+
828
+ expect(result).toEqual(initialState);
829
+ });
830
+ });
831
+
832
+ describe('GET_SENDER_DETAILS_FAILURE', () => {
833
+ it('should set loading to false and store error', () => {
834
+ const action = {
835
+ type: GET_SENDER_DETAILS_FAILURE,
836
+ payload: { channel: CHANNELS.EMAIL, error: 'Failed to fetch' },
837
+ };
838
+ const result = previewAndTestReducer(initialState, action);
839
+
840
+ expect(result.get('isLoadingSenderDetails')).toBe(false);
841
+ expect(result.get('fetchSenderDetailsError')).toBe('Failed to fetch');
842
+ });
843
+ });
844
+
845
+ describe('GET_WECRM_ACCOUNTS_REQUESTED', () => {
846
+ it('should clear fetchWeCrmAccountsError', () => {
847
+ const stateWithError = initialState.set('fetchWeCrmAccountsError', 'Error');
848
+ const action = {
849
+ type: GET_WECRM_ACCOUNTS_REQUESTED,
850
+ payload: { sourceName: 'WHATSAPP' },
851
+ };
852
+ const result = previewAndTestReducer(stateWithError, action);
853
+
854
+ expect(result.get('fetchWeCrmAccountsError')).toBeNull();
855
+ });
856
+ });
857
+
858
+ describe('GET_WECRM_ACCOUNTS_SUCCESS', () => {
859
+ it('should store wecrm accounts and clear error', () => {
860
+ const accounts = [{ name: 'Account 1', sourceAccountIdentifier: 'acc-1' }];
861
+ const action = {
862
+ type: GET_WECRM_ACCOUNTS_SUCCESS,
863
+ payload: { accounts },
864
+ };
865
+ const result = previewAndTestReducer(initialState, action);
866
+
867
+ expect(result.get('wecrmAccounts')).toEqual(fromJS(accounts));
868
+ expect(result.get('fetchWeCrmAccountsError')).toBeNull();
869
+ });
870
+
871
+ it('should handle empty accounts', () => {
872
+ const action = {
873
+ type: GET_WECRM_ACCOUNTS_SUCCESS,
874
+ payload: { accounts: [] },
875
+ };
876
+ const result = previewAndTestReducer(initialState, action);
877
+
878
+ expect(result.get('wecrmAccounts')).toEqual(fromJS([]));
879
+ });
880
+ });
881
+
882
+ describe('GET_WECRM_ACCOUNTS_FAILURE', () => {
883
+ it('should store fetchWeCrmAccountsError', () => {
884
+ const action = {
885
+ type: GET_WECRM_ACCOUNTS_FAILURE,
886
+ payload: { error: 'WeCRM fetch failed' },
887
+ };
888
+ const result = previewAndTestReducer(initialState, action);
889
+
890
+ expect(result.get('fetchWeCrmAccountsError')).toBe('WeCRM fetch failed');
891
+ });
892
+ });
893
+
776
894
  describe('CLEAR_PREVIEW_ERRORS', () => {
777
895
  it('should clear all preview-related errors', () => {
778
896
  const stateWithErrors = initialState
@@ -25,9 +25,17 @@ import {
25
25
  watchFetchTestGroups,
26
26
  watchCreateMessageMeta,
27
27
  watchGetPrefilledValues,
28
+ getSenderDetailsSaga,
29
+ getWeCrmAccountsSaga,
30
+ watchGetSenderDetails,
31
+ watchGetWeCrmAccounts,
28
32
  commonTestAndPreviewSaga,
29
33
  } from '../sagas';
30
34
  import * as Api from '../../../services/api';
35
+ jest.mock('../DeliverySettings/utils/parseSenderDetailsResponse', () => ({
36
+ parseSenderDetailsResponse: jest.fn((channel, response) => ({ domains: response?.entity?.[channel] || [] })),
37
+ }));
38
+ import { parseSenderDetailsResponse } from '../DeliverySettings/utils/parseSenderDetailsResponse';
31
39
  import {
32
40
  SEARCH_CUSTOMERS_SUCCESS,
33
41
  SEARCH_CUSTOMERS_FAILURE,
@@ -45,6 +53,10 @@ import {
45
53
  CREATE_MESSAGE_META_FAILURE,
46
54
  GET_PREFILLED_VALUES_SUCCESS,
47
55
  GET_PREFILLED_VALUES_FAILURE,
56
+ GET_SENDER_DETAILS_SUCCESS,
57
+ GET_SENDER_DETAILS_FAILURE,
58
+ GET_WECRM_ACCOUNTS_SUCCESS,
59
+ GET_WECRM_ACCOUNTS_FAILURE,
48
60
  } from '../constants';
49
61
 
50
62
  describe('CommonTestAndPreview Sagas', () => {
@@ -1694,6 +1706,137 @@ describe('CommonTestAndPreview Sagas', () => {
1694
1706
  );
1695
1707
  expect(generator.next().done).toBe(true);
1696
1708
  });
1709
+
1710
+ it('should watch for GET_SENDER_DETAILS_REQUESTED', () => {
1711
+ const generator = watchGetSenderDetails();
1712
+ expect(generator.next().value).toEqual(
1713
+ takeLatest('app/CommonTestAndPreview/GET_SENDER_DETAILS_REQUESTED', getSenderDetailsSaga)
1714
+ );
1715
+ expect(generator.next().done).toBe(true);
1716
+ });
1717
+
1718
+ it('should watch for GET_WECRM_ACCOUNTS_REQUESTED', () => {
1719
+ const generator = watchGetWeCrmAccounts();
1720
+ expect(generator.next().value).toEqual(
1721
+ takeLatest('app/CommonTestAndPreview/GET_WECRM_ACCOUNTS_REQUESTED', getWeCrmAccountsSaga)
1722
+ );
1723
+ expect(generator.next().done).toBe(true);
1724
+ });
1725
+ });
1726
+
1727
+ describe('getSenderDetailsSaga', () => {
1728
+ it('should fetch sender details and put SUCCESS with parsed domains', () => {
1729
+ const action = { payload: { channel: 'SMS', orgUnitId: 100 } };
1730
+ const apiResponse = { entity: { SMS: [{ id: 1, domainProperties: {} }] } };
1731
+ parseSenderDetailsResponse.mockReturnValue({ domains: [{ domainId: 1 }] });
1732
+
1733
+ const generator = getSenderDetailsSaga(action);
1734
+
1735
+ expect(generator.next().value).toEqual(call(Api.getSenderDetails, 'SMS', 100));
1736
+ expect(generator.next(apiResponse).value).toEqual(
1737
+ put({ type: GET_SENDER_DETAILS_SUCCESS, payload: { channel: 'SMS', domains: [{ domainId: 1 }] } })
1738
+ );
1739
+ expect(generator.next().done).toBe(true);
1740
+ });
1741
+
1742
+ it('should use orgUnitId -1 when not provided', () => {
1743
+ const action = { payload: { channel: 'EMAIL' } };
1744
+ const apiResponse = { entity: { EMAIL: [] } };
1745
+ parseSenderDetailsResponse.mockReturnValue({ domains: [] });
1746
+
1747
+ const generator = getSenderDetailsSaga(action);
1748
+
1749
+ expect(generator.next().value).toEqual(call(Api.getSenderDetails, 'EMAIL', -1));
1750
+ generator.next(apiResponse);
1751
+ expect(generator.next().done).toBe(true);
1752
+ });
1753
+
1754
+ it('should return early when channel is missing', () => {
1755
+ const action = { payload: {} };
1756
+ const generator = getSenderDetailsSaga(action);
1757
+ expect(generator.next().done).toBe(true);
1758
+ });
1759
+
1760
+ it('should put FAILURE when response has errors', () => {
1761
+ const action = { payload: { channel: 'SMS' } };
1762
+ const apiResponse = { errors: [{ message: 'Forbidden' }] };
1763
+
1764
+ const generator = getSenderDetailsSaga(action);
1765
+ generator.next();
1766
+ expect(generator.next(apiResponse).value).toEqual(
1767
+ put({
1768
+ type: GET_SENDER_DETAILS_FAILURE,
1769
+ payload: { channel: 'SMS', error: [{ message: 'Forbidden' }] },
1770
+ })
1771
+ );
1772
+ expect(generator.next().done).toBe(true);
1773
+ });
1774
+
1775
+ it('should put FAILURE on throw', () => {
1776
+ const action = { payload: { channel: 'WHATSAPP' } };
1777
+ const generator = getSenderDetailsSaga(action);
1778
+ generator.next();
1779
+ const err = generator.throw(new Error('Network error'));
1780
+ expect(err.value).toEqual(
1781
+ put({
1782
+ type: GET_SENDER_DETAILS_FAILURE,
1783
+ payload: { channel: 'WHATSAPP', error: 'Network error' },
1784
+ })
1785
+ );
1786
+ expect(generator.next().done).toBe(true);
1787
+ });
1788
+ });
1789
+
1790
+ describe('getWeCrmAccountsSaga', () => {
1791
+ it('should fetch wecrm accounts and put SUCCESS with list from response', () => {
1792
+ const action = { payload: { sourceName: 'WHATSAPP' } };
1793
+ const apiResult = { response: [{ name: 'WABA1', sourceAccountIdentifier: 'waba-1' }] };
1794
+
1795
+ const generator = getWeCrmAccountsSaga(action);
1796
+
1797
+ expect(generator.next().value).toEqual(call(Api.fetchWeCrmAccounts, 'WHATSAPP'));
1798
+ expect(generator.next(apiResult).value).toEqual(
1799
+ put({ type: GET_WECRM_ACCOUNTS_SUCCESS, payload: { accounts: [{ name: 'WABA1', sourceAccountIdentifier: 'waba-1' }] } })
1800
+ );
1801
+ expect(generator.next().done).toBe(true);
1802
+ });
1803
+
1804
+ it('should use WHATSAPP when sourceName not provided', () => {
1805
+ const action = { payload: {} };
1806
+ const generator = getWeCrmAccountsSaga(action);
1807
+ expect(generator.next().value).toEqual(call(Api.fetchWeCrmAccounts, 'WHATSAPP'));
1808
+ });
1809
+
1810
+ it('should use entity when response not present', () => {
1811
+ const action = { payload: {} };
1812
+ const apiResult = { entity: [{ name: 'Acc1' }] };
1813
+
1814
+ const generator = getWeCrmAccountsSaga(action);
1815
+ generator.next();
1816
+ expect(generator.next(apiResult).value).toEqual(
1817
+ put({ type: GET_WECRM_ACCOUNTS_SUCCESS, payload: { accounts: [{ name: 'Acc1' }] } })
1818
+ );
1819
+ });
1820
+
1821
+ it('should put empty array when result has no list', () => {
1822
+ const action = { payload: {} };
1823
+ const generator = getWeCrmAccountsSaga(action);
1824
+ generator.next();
1825
+ expect(generator.next({}).value).toEqual(
1826
+ put({ type: GET_WECRM_ACCOUNTS_SUCCESS, payload: { accounts: [] } })
1827
+ );
1828
+ });
1829
+
1830
+ it('should put FAILURE on throw', () => {
1831
+ const action = { payload: {} };
1832
+ const generator = getWeCrmAccountsSaga(action);
1833
+ generator.next();
1834
+ const err = generator.throw(new Error('API failed'));
1835
+ expect(err.value).toEqual(
1836
+ put({ type: GET_WECRM_ACCOUNTS_FAILURE, payload: { error: 'API failed' } })
1837
+ );
1838
+ expect(generator.next().done).toBe(true);
1839
+ });
1697
1840
  });
1698
1841
 
1699
1842
  describe('commonTestAndPreviewSaga', () => {
@@ -1710,6 +1853,8 @@ describe('CommonTestAndPreview Sagas', () => {
1710
1853
  watchFetchTestGroups(),
1711
1854
  watchCreateMessageMeta(),
1712
1855
  watchGetPrefilledValues(),
1856
+ watchGetSenderDetails(),
1857
+ watchGetWeCrmAccounts(),
1713
1858
  ])
1714
1859
  );
1715
1860