@capillarytech/creatives-library 8.0.57 → 8.0.58
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
CHANGED
package/services/api.js
CHANGED
|
@@ -269,7 +269,7 @@ export const createChannelWiseTemplate = ({ channel, template }) => {
|
|
|
269
269
|
export const getTemplateDetails = async ({id, channel}) => {
|
|
270
270
|
const url = `${API_ENDPOINT}/templates/v1/${id}/${channel ? channel.toUpperCase() : SMS}`;
|
|
271
271
|
const compressedTemplatesData = await request(url, getAPICallObject('GET'));
|
|
272
|
-
const {response = ''} = compressedTemplatesData
|
|
272
|
+
const {response = ''} = compressedTemplatesData;
|
|
273
273
|
const decompressData = decompressJsonObject(response);
|
|
274
274
|
if (channel?.toUpperCase() === EMAIL) {
|
|
275
275
|
return { ...compressedTemplatesData, response: addBaseToTemplate(decompressData) };
|
|
@@ -283,7 +283,7 @@ export const getAllTemplates = async ({channel, queryParams = {}}) => {
|
|
|
283
283
|
queryParams,
|
|
284
284
|
});
|
|
285
285
|
const compressedTemplatesData = await request(url, getAPICallObject('GET'));
|
|
286
|
-
const {response = ''} = compressedTemplatesData
|
|
286
|
+
const {response = ''} = compressedTemplatesData;
|
|
287
287
|
return { ...compressedTemplatesData, response: decompressJsonObject(response)};
|
|
288
288
|
};
|
|
289
289
|
|
|
@@ -132,6 +132,14 @@ describe('getAllTemplates -- Test with valid responses', () => {
|
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
it('Should work for empty response', async () => {
|
|
136
|
+
global.fetch.mockReturnValue(Promise.resolve({json: () => Promise.resolve(),}));
|
|
137
|
+
mockDecompressJsonObject.mockReturnValue();
|
|
138
|
+
expect(await getAllTemplates({channel: 'email'})).toEqual({
|
|
139
|
+
"response": undefined,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
135
143
|
it('Should not return correct response', async () => {
|
|
136
144
|
global.fetch.mockReturnValue(Promise.resolve({
|
|
137
145
|
status: 200,
|
|
@@ -197,7 +205,18 @@ describe('getTemplateDetails -- Test with valid responses', () => {
|
|
|
197
205
|
status: 200,
|
|
198
206
|
});
|
|
199
207
|
});
|
|
200
|
-
|
|
208
|
+
it('Should work incase of empty response', async () => {
|
|
209
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
210
|
+
status: 200,
|
|
211
|
+
json: () => Promise.resolve({
|
|
212
|
+
status: 200,
|
|
213
|
+
}),
|
|
214
|
+
}));
|
|
215
|
+
mockDecompressJsonObject.mockReturnValue();
|
|
216
|
+
expect(await getTemplateDetails({id: '123', channel: 'email'})).toEqual({
|
|
217
|
+
status: 200,
|
|
218
|
+
});
|
|
219
|
+
});
|
|
201
220
|
it('Should return response when channel is not email', async () => {
|
|
202
221
|
global.fetch.mockReturnValue(Promise.resolve({
|
|
203
222
|
status: 200,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
iframePreviewAdjustWidth,
|
|
13
13
|
getDecodedFileName,
|
|
14
14
|
createQueryString,
|
|
15
|
+
getMergedUserList
|
|
15
16
|
} from "../common";
|
|
16
17
|
import * as mockdata from "./common.mockdata";
|
|
17
18
|
|
|
@@ -317,3 +318,48 @@ describe('createQueryString', () => {
|
|
|
317
318
|
expect(result).toBe('?name=John');
|
|
318
319
|
});
|
|
319
320
|
});
|
|
321
|
+
describe('getMergedUserList', () => {
|
|
322
|
+
it('should merge user list when isCapUser is true', () => {
|
|
323
|
+
const userList = {
|
|
324
|
+
capUsers: [{ id: 1, name: 'Cap User 1' }],
|
|
325
|
+
otherUsers: [{ id: 2, name: 'Other User 1' }],
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const result = getMergedUserList(userList, true);
|
|
329
|
+
|
|
330
|
+
expect(result).toEqual([
|
|
331
|
+
{ id: 1, name: 'Cap User 1' },
|
|
332
|
+
{ id: 2, name: 'Other User 1' },
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('should merge user list excluding capUsers when isCapUser is false', () => {
|
|
337
|
+
const userList = {
|
|
338
|
+
capUsers: [{ id: 1, name: 'Cap User 1' }],
|
|
339
|
+
otherUsers: [{ id: 2, name: 'Other User 1' }],
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const result = getMergedUserList(userList, false);
|
|
343
|
+
|
|
344
|
+
expect(result).toEqual([{ id: 2, name: 'Other User 1' }]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('should handle empty userList', () => {
|
|
348
|
+
const userList = {};
|
|
349
|
+
|
|
350
|
+
const result = getMergedUserList(userList, true);
|
|
351
|
+
|
|
352
|
+
expect(result).toEqual([]);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should handle userList with empty arrays', () => {
|
|
356
|
+
const userList = {
|
|
357
|
+
capUsers: [],
|
|
358
|
+
otherUsers: [],
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const result = getMergedUserList(userList);
|
|
362
|
+
|
|
363
|
+
expect(result).toEqual([]);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
@@ -53,9 +53,7 @@ import { v2InAppSagas } from '../InApp/sagas';
|
|
|
53
53
|
import { v2ViberSagas } from '../Viber/sagas';
|
|
54
54
|
import { v2FacebookSagas } from '../Facebook/sagas';
|
|
55
55
|
import createReducer from '../Line/Container/reducer';
|
|
56
|
-
import { v2ZaloSagas } from '../Zalo/saga';
|
|
57
56
|
import { DAEMON } from '@capillarytech/vulcan-react-sdk/utils/sagaInjectorTypes';
|
|
58
|
-
|
|
59
57
|
const gtm = window.dataLayer || [];
|
|
60
58
|
const {
|
|
61
59
|
logNewTab,
|
|
@@ -618,7 +616,6 @@ const withEbillSaga = injectSaga({ key: 'ebill', saga: v2EbillSagas });
|
|
|
618
616
|
const withEmailSaga = injectSaga({ key: 'email', saga: v2EmailDuplicateTemplateSaga });
|
|
619
617
|
const withLineContainerSaga = injectSaga({ key: 'lineCreate', saga: v2LineContainerSagas });
|
|
620
618
|
const withMobilePushCreateSaga = injectSaga({ key: 'mobileCreate', saga: v2MobilePushCreateSagas });
|
|
621
|
-
const withZaloSaga = injectSaga({ key: 'zalo', saga: v2ZaloSagas });
|
|
622
619
|
const withWechatMapTemplatesSaga = injectSaga({ key: 'weChatMapTemplate', saga: v2WechatMapTemplatesSagas });
|
|
623
620
|
const withRcsSaga = injectSaga({ key: 'rcs', saga: v2RcsSagas });
|
|
624
621
|
const withInAppSaga = injectSaga({ key: 'inapp', saga: v2InAppSagas });
|
|
@@ -635,7 +632,6 @@ export default compose(
|
|
|
635
632
|
withLineContainerSaga,
|
|
636
633
|
withMobilePushCreateSaga,
|
|
637
634
|
withWechatMapTemplatesSaga,
|
|
638
|
-
withZaloSaga,
|
|
639
635
|
withRcsSaga,
|
|
640
636
|
withInAppSaga,
|
|
641
637
|
withViberSaga,
|
|
@@ -17,7 +17,7 @@ describe("v2SmsEditSagas Combined", () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
describe('editTemplate Saga', () => {
|
|
20
|
-
const template = { id: 1, name: 'Updated Template' };
|
|
20
|
+
const template = { id: 1, name: 'Updated Template',message: 'esd' };
|
|
21
21
|
|
|
22
22
|
it('handles successful template edit', () => {
|
|
23
23
|
const fakeResponse = {
|
|
@@ -38,6 +38,47 @@ describe("v2SmsEditSagas Combined", () => {
|
|
|
38
38
|
.run();
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
it('handles successful template edit for empty response', () => {
|
|
42
|
+
const fakeResponse = {
|
|
43
|
+
status: { code: 200 }
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return expectSaga(editTemplate, template)
|
|
47
|
+
.provide([
|
|
48
|
+
[call(api.editTemplate, template), fakeResponse]
|
|
49
|
+
])
|
|
50
|
+
.put({
|
|
51
|
+
type: types.EDIT_TEMPLATE_SUCCESS,
|
|
52
|
+
data: fakeResponse.response,
|
|
53
|
+
statusCode: 200,
|
|
54
|
+
errorMsg: undefined
|
|
55
|
+
})
|
|
56
|
+
.run();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('handles failure template edit for empty response', () => {
|
|
60
|
+
const fakeResponse = {
|
|
61
|
+
status: { code: 500 }
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return expectSaga(editTemplate, template)
|
|
65
|
+
.provide([
|
|
66
|
+
[call(api.editTemplate, template), fakeResponse]
|
|
67
|
+
])
|
|
68
|
+
.put({
|
|
69
|
+
type: types.EDIT_TEMPLATE_SUCCESS,
|
|
70
|
+
data: undefined,
|
|
71
|
+
statusCode: 500,
|
|
72
|
+
errorMsg: undefined
|
|
73
|
+
})
|
|
74
|
+
.put({
|
|
75
|
+
type: types.EDIT_TEMPLATE_FAILURE,
|
|
76
|
+
error: new TypeError('template.onUpdateTemplateComplete is not a function'),
|
|
77
|
+
errorMsg: undefined
|
|
78
|
+
})
|
|
79
|
+
.run();
|
|
80
|
+
});
|
|
81
|
+
|
|
41
82
|
it('handles failure in editing a template', () => {
|
|
42
83
|
const error = new Error('Edit failed');
|
|
43
84
|
|
|
@@ -53,7 +53,6 @@ import injectReducer from '../../utils/injectReducer';
|
|
|
53
53
|
import * as globalActions from '../Cap/actions';
|
|
54
54
|
import v2ZaloReducer from './reducer';
|
|
55
55
|
import { v2ZaloSagas } from './saga';
|
|
56
|
-
import { DAEMON } from '@capillarytech/vulcan-react-sdk/utils/sagaInjectorTypes';
|
|
57
56
|
|
|
58
57
|
export const Zalo = (props) => {
|
|
59
58
|
const {
|
|
@@ -507,9 +506,7 @@ const mapDispatchToProps = (dispatch) => ({
|
|
|
507
506
|
|
|
508
507
|
|
|
509
508
|
const withReducer = injectReducer({ key: 'zalo', reducer: v2ZaloReducer });
|
|
510
|
-
|
|
511
|
-
//DAEMON mode ensures that this saga is not injected twice
|
|
512
|
-
const withZaloSaga = injectSaga({ key: 'zalo', saga: v2ZaloSagas, mode: DAEMON });
|
|
509
|
+
const withZaloSaga = injectSaga({ key: 'zalo', saga: v2ZaloSagas });
|
|
513
510
|
|
|
514
511
|
export default withCreatives({
|
|
515
512
|
WrappedComponent: Zalo,
|