@capillarytech/creatives-library 7.17.131 → 7.17.133
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/containers/Templates/index.js +2 -1
- package/package.json +2 -2
- package/services/api.js +17 -3
- package/services/tests/api.test.js +142 -0
- package/utils/commonUtils.js +17 -1
- package/utils/tests/commonUtil.test.js +58 -0
- package/v2Components/EmailPreviewV2/index.js +2 -1
- package/v2Containers/Templates/index.js +1 -1
|
@@ -44,6 +44,7 @@ import SlideBox from '../../components/SlideBox';
|
|
|
44
44
|
import Pagination from '../../components/Pagination';
|
|
45
45
|
import EmailPreview from '../../components/EmailPreview';
|
|
46
46
|
import WechatRichmediaTemplatePreview from '../../components/TemplatePreview/WechatRichmediaTemplatePreview';
|
|
47
|
+
import { EMAIL } from '../../v2Containers/App/constants';
|
|
47
48
|
|
|
48
49
|
const MenuItem = Menu.Item;
|
|
49
50
|
const Option = Select.Option;
|
|
@@ -984,7 +985,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
984
985
|
templateInfo.appName = this.props.Templates.selectedWeChatAccount.name;
|
|
985
986
|
} else if (this.state.channel.toLowerCase() === "email") {
|
|
986
987
|
|
|
987
|
-
this.props.actions.getTemplateDetails(template._id);
|
|
988
|
+
this.props.actions.getTemplateDetails(template._id, EMAIL);
|
|
988
989
|
} else if (this.state.channel.toLowerCase() === 'ebill') {
|
|
989
990
|
this.props.actions.getTemplateDetails(template._id);
|
|
990
991
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capillarytech/creatives-library",
|
|
3
3
|
"author": "meharaj",
|
|
4
|
-
"version": "7.17.
|
|
4
|
+
"version": "7.17.133",
|
|
5
5
|
"description": "Capillary creatives ui",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"module": "./index.es.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@babel/polyfill": "7.4.3",
|
|
16
16
|
"@bugsnag/js": "^7.2.1",
|
|
17
17
|
"@bugsnag/plugin-react": "^7.2.1",
|
|
18
|
-
"@capillarytech/cap-ui-utils": "
|
|
18
|
+
"@capillarytech/cap-ui-utils": "2.0.8",
|
|
19
19
|
"@mailupinc/bee-plugin": "^1.2.0",
|
|
20
20
|
"babel-cli": "^6.26.0",
|
|
21
21
|
"chalk": "1.1.3",
|
package/services/api.js
CHANGED
|
@@ -7,7 +7,9 @@ import config from '../config/app';
|
|
|
7
7
|
import pathConfig from '../config/path';
|
|
8
8
|
import getSchema from './getSchema';
|
|
9
9
|
import * as API from '../utils/ApiCaller';
|
|
10
|
-
import { GA } from '@capillarytech/cap-ui-utils';
|
|
10
|
+
import { GA, decompressJsonObject } from '@capillarytech/cap-ui-utils';
|
|
11
|
+
import { addBaseToTemplate } from '../utils/commonUtils';
|
|
12
|
+
import { EMAIL } from '../v2Containers/CreativesContainer/constants';
|
|
11
13
|
let API_ENDPOINT = config.development.api_endpoint;
|
|
12
14
|
let EXPORT_API_ENDPOINT = config.development.exports_api_endpoint;
|
|
13
15
|
let CAMPAIGNS_API_ENDPOINT = config.development.campaigns_api_endpoint;
|
|
@@ -270,7 +272,15 @@ export const createChannelWiseTemplate = ({ channel, template }) => {
|
|
|
270
272
|
|
|
271
273
|
export const getTemplateDetails = ({id, channel}) => {
|
|
272
274
|
const url = `${API_ENDPOINT}/templates/${id}/${channel ? channel.toUpperCase() : 'SMS'}`;
|
|
273
|
-
|
|
275
|
+
const compressedTemplatesData = request(url, getAPICallObject('GET'));
|
|
276
|
+
return compressedTemplatesData.then(async (data) => {
|
|
277
|
+
const { response = '' } = data || {};
|
|
278
|
+
const decompressData = await decompressJsonObject(response);
|
|
279
|
+
if (channel?.toUpperCase() === EMAIL) {
|
|
280
|
+
return { ...data, response: addBaseToTemplate(decompressData) };
|
|
281
|
+
}
|
|
282
|
+
return { ...data, response: decompressData };
|
|
283
|
+
});
|
|
274
284
|
};
|
|
275
285
|
|
|
276
286
|
export const getAllTemplates = ({channel, queryParams = {}}) => {
|
|
@@ -278,7 +288,11 @@ export const getAllTemplates = ({channel, queryParams = {}}) => {
|
|
|
278
288
|
url: `${API_ENDPOINT}/templates/${channel}?`,
|
|
279
289
|
queryParams,
|
|
280
290
|
});
|
|
281
|
-
|
|
291
|
+
const compressedTemplatesData = request(url, getAPICallObject('GET'));
|
|
292
|
+
return compressedTemplatesData.then(async (data) => {
|
|
293
|
+
const { response = '' } = data || {};
|
|
294
|
+
return { ...data, response: await decompressJsonObject(response)};
|
|
295
|
+
});
|
|
282
296
|
};
|
|
283
297
|
|
|
284
298
|
export const deleteTemplate = ({channel, id}) => {
|
|
@@ -6,10 +6,21 @@ import {
|
|
|
6
6
|
getMetaTags,
|
|
7
7
|
getSupportVideosConfig,
|
|
8
8
|
getNavigationConfigApi,
|
|
9
|
+
getAllTemplates,
|
|
10
|
+
getTemplateDetails,
|
|
9
11
|
} from '../api';
|
|
10
12
|
import { mockData } from './mockData';
|
|
11
13
|
const sampleFile = require('../../assets/line.png');
|
|
12
14
|
|
|
15
|
+
let mockDecompressJsonObject;
|
|
16
|
+
jest.mock('@capillarytech/cap-ui-utils', () => {
|
|
17
|
+
mockDecompressJsonObject = jest.fn();
|
|
18
|
+
return {
|
|
19
|
+
...jest.requireActual('@capillarytech/cap-ui-utils'),
|
|
20
|
+
decompressJsonObject: mockDecompressJsonObject,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
13
24
|
describe('getSenderDetails -- Test with valid responses', () => {
|
|
14
25
|
it('Should return correct response', () =>
|
|
15
26
|
expect(getSenderDetails('WHATSAPP', -1)).toEqual(Promise.resolve()));
|
|
@@ -83,3 +94,134 @@ describe('getNavigationConfigApi -- Test with valid responses', () => {
|
|
|
83
94
|
it('Should return correct response', () =>
|
|
84
95
|
expect(getNavigationConfigApi()).toEqual(Promise.resolve()));
|
|
85
96
|
});
|
|
97
|
+
|
|
98
|
+
describe('getAllTemplates -- Test with valid responses', () => {
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
global.fetch = jest.fn(); // Mocking global fetch function
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
jest.restoreAllMocks(); // Restore all mocks after each test
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('Should return correct response', async () => {
|
|
108
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
109
|
+
status: 200,
|
|
110
|
+
json: () => Promise.resolve({
|
|
111
|
+
status: 200,
|
|
112
|
+
response: {
|
|
113
|
+
_id: '123',
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
}));
|
|
117
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
118
|
+
_id: '123',
|
|
119
|
+
}));
|
|
120
|
+
expect(await getAllTemplates({channel: 'email'})).toEqual({
|
|
121
|
+
response: {
|
|
122
|
+
_id: '123',
|
|
123
|
+
},
|
|
124
|
+
status: 200,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('Should not return correct response', async () => {
|
|
129
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
130
|
+
status: 200,
|
|
131
|
+
json: () => Promise.resolve({
|
|
132
|
+
status: 200,
|
|
133
|
+
data: {
|
|
134
|
+
_id: '123',
|
|
135
|
+
},
|
|
136
|
+
}),
|
|
137
|
+
}));
|
|
138
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
139
|
+
_id: '123',
|
|
140
|
+
}));
|
|
141
|
+
expect(await getAllTemplates({channel: 'email'})).toEqual({
|
|
142
|
+
data: {
|
|
143
|
+
_id: '123',
|
|
144
|
+
},
|
|
145
|
+
response: {
|
|
146
|
+
_id: '123',
|
|
147
|
+
},
|
|
148
|
+
status: 200,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('getTemplateDetails -- Test with valid responses', () => {
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
global.fetch = jest.fn(); // Mocking global fetch function
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
afterEach(() => {
|
|
159
|
+
jest.restoreAllMocks(); // Restore all mocks after each test
|
|
160
|
+
});
|
|
161
|
+
it('Should return correct response', async () => {
|
|
162
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
163
|
+
status: 200,
|
|
164
|
+
json: () => Promise.resolve({
|
|
165
|
+
status: 200,
|
|
166
|
+
response: {
|
|
167
|
+
_id: '123',
|
|
168
|
+
versions: {
|
|
169
|
+
history: ['v1', 'v2'],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
}));
|
|
174
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
175
|
+
_id: '123',
|
|
176
|
+
versions: {
|
|
177
|
+
history: ['v1', 'v2'],
|
|
178
|
+
},
|
|
179
|
+
}));
|
|
180
|
+
expect(await getTemplateDetails({id: '123', channel: 'email'})).toEqual({
|
|
181
|
+
response: {
|
|
182
|
+
_id: '123',
|
|
183
|
+
versions: {
|
|
184
|
+
history: ['v1', 'v2'],
|
|
185
|
+
base: 'v1',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
status: 200,
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('Should return response when channel is not email', async () => {
|
|
193
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
194
|
+
status: 200,
|
|
195
|
+
json: () => Promise.resolve({
|
|
196
|
+
status: 200,
|
|
197
|
+
data: {
|
|
198
|
+
_id: '123',
|
|
199
|
+
versions: {
|
|
200
|
+
history: ['v1', 'v2'],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
}));
|
|
205
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
206
|
+
_id: '123',
|
|
207
|
+
versions: {
|
|
208
|
+
history: ['v1', 'v2'],
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
expect(await getTemplateDetails({id: '123'})).toEqual({
|
|
212
|
+
data: {
|
|
213
|
+
_id: '123',
|
|
214
|
+
versions: {
|
|
215
|
+
history: ['v1', 'v2'],
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
response: {
|
|
219
|
+
_id: '123',
|
|
220
|
+
versions: {
|
|
221
|
+
history: ['v1', 'v2'],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
status: 200,
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
package/utils/commonUtils.js
CHANGED
|
@@ -3,4 +3,20 @@ import { FormattedMessage } from 'react-intl';
|
|
|
3
3
|
|
|
4
4
|
export const apiMessageFormatHandler = (id, fallback) => (
|
|
5
5
|
<FormattedMessage id={id} defaultMessage={fallback} />
|
|
6
|
-
);
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export const addBaseToTemplate = (template) => {
|
|
9
|
+
const { versions: {
|
|
10
|
+
history = [],
|
|
11
|
+
} = {}} = template || {};
|
|
12
|
+
if (history?.length) {
|
|
13
|
+
return ({
|
|
14
|
+
...template,
|
|
15
|
+
versions: {
|
|
16
|
+
...template.versions,
|
|
17
|
+
base: history[0],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return template;
|
|
22
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "@testing-library/jest-dom";
|
|
2
2
|
import { getTreeStructuredTags } from "../common";
|
|
3
3
|
import * as mockdata from "./common.mockdata";
|
|
4
|
+
import { addBaseToTemplate } from "../commonUtils";
|
|
4
5
|
|
|
5
6
|
jest.mock('@capillarytech/cap-ui-utils', () => ({
|
|
6
7
|
Auth: {
|
|
@@ -19,3 +20,60 @@ describe("common utils test", () => {
|
|
|
19
20
|
expect(getTreeStructuredTags({tagsList: []})).toEqual([]);
|
|
20
21
|
});
|
|
21
22
|
});
|
|
23
|
+
|
|
24
|
+
describe('addBaseToTemplate', () => {
|
|
25
|
+
it('should add the first item in history as base if history exists', () => {
|
|
26
|
+
const template = {
|
|
27
|
+
versions: {
|
|
28
|
+
history: ['v1', 'v2', 'v3'],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const expected = {
|
|
32
|
+
versions: {
|
|
33
|
+
history: ['v1', 'v2', 'v3'],
|
|
34
|
+
base: 'v1',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
expect(addBaseToTemplate(template)).toEqual(expected);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should return the original template if history is empty', () => {
|
|
41
|
+
const template = {
|
|
42
|
+
versions: {
|
|
43
|
+
history: [],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
expect(addBaseToTemplate(template)).toEqual(template);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return the original template if history is undefined', () => {
|
|
50
|
+
const template = {
|
|
51
|
+
versions: {},
|
|
52
|
+
};
|
|
53
|
+
expect(addBaseToTemplate(template)).toEqual(template);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return the original template if versions is undefined', () => {
|
|
57
|
+
const template = {};
|
|
58
|
+
expect(addBaseToTemplate(template)).toEqual(template);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle null input gracefully', () => {
|
|
62
|
+
expect(addBaseToTemplate(null)).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should handle undefined input gracefully', () => {
|
|
66
|
+
expect(addBaseToTemplate(undefined)).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should not modify the original template object', () => {
|
|
70
|
+
const template = {
|
|
71
|
+
versions: {
|
|
72
|
+
history: ['v1', 'v2', 'v3'],
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const originalTemplateCopy = JSON.parse(JSON.stringify(template));
|
|
76
|
+
addBaseToTemplate(template);
|
|
77
|
+
expect(template).toEqual(originalTemplateCopy);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -23,6 +23,7 @@ import { iframePreviewAdjustWidth, removeLinksFromHtmlContent } from './../../ut
|
|
|
23
23
|
|
|
24
24
|
import {selectTemplateContent} from '../../v2Containers/Templates/selectors';
|
|
25
25
|
import * as templateActions from '../../v2Containers/Templates/actions';
|
|
26
|
+
import { EMAIL } from '../../v2Containers/CreativesContainer/constants';
|
|
26
27
|
|
|
27
28
|
const deviceAspectRatio = {
|
|
28
29
|
desktop: () => ({
|
|
@@ -59,7 +60,7 @@ export class EmailPreviewV2 extends React.Component {
|
|
|
59
60
|
componentWillMount() {
|
|
60
61
|
const {templateData, templateContent} = this.props;
|
|
61
62
|
if (isEmpty(templateContent) && !isEmpty(templateData) && templateData._id) { // templateData: comes from templates list email preview
|
|
62
|
-
this.props.templateActions.getTemplateDetails(templateData._id); // templateContent: html data to be shown in iframe
|
|
63
|
+
this.props.templateActions.getTemplateDetails(templateData._id, EMAIL); // templateContent: html data to be shown in iframe
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
componentWillUnmount() {
|
|
@@ -2089,7 +2089,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
2089
2089
|
templateInfo.content = template.versions.base;
|
|
2090
2090
|
templateInfo.appName = this.props.Templates.selectedWeChatAccount.name;
|
|
2091
2091
|
} else if (this.state.channel.toLowerCase() === "email") {
|
|
2092
|
-
this.props.actions.getTemplateDetails(template._id);
|
|
2092
|
+
this.props.actions.getTemplateDetails(template._id, EMAIL);
|
|
2093
2093
|
} else if (this.state.channel.toLowerCase() === "ebill") {
|
|
2094
2094
|
this.props.actions.getTemplateDetails(template._id);
|
|
2095
2095
|
}
|