@capillarytech/creatives-library 7.17.134 → 7.17.135
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/services/api.js +5 -1
- package/services/tests/api.test.js +66 -0
package/package.json
CHANGED
package/services/api.js
CHANGED
|
@@ -527,7 +527,11 @@ export const getS3UrlFileSizes = (data) => {
|
|
|
527
527
|
|
|
528
528
|
export const getTemplateInfoById = ({id, username, oa_id, token}) => {
|
|
529
529
|
const url = `${API_ENDPOINT}/templates/${id}/Zalo?username=${username}&oa_id=${oa_id}&token=${token}`;
|
|
530
|
-
|
|
530
|
+
const compressedTemplatesData = request(url, getAPICallObject('GET'));
|
|
531
|
+
return compressedTemplatesData.then(async (data) => {
|
|
532
|
+
const { response = '' } = data || {};
|
|
533
|
+
return { ...data, response: await decompressJsonObject(response)};
|
|
534
|
+
});
|
|
531
535
|
};
|
|
532
536
|
|
|
533
537
|
export const getMetaTags = ({previewUrl}) => {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getNavigationConfigApi,
|
|
9
9
|
getAllTemplates,
|
|
10
10
|
getTemplateDetails,
|
|
11
|
+
getTemplateInfoById,
|
|
11
12
|
} from '../api';
|
|
12
13
|
import { mockData } from './mockData';
|
|
13
14
|
const sampleFile = require('../../assets/line.png');
|
|
@@ -225,3 +226,68 @@ describe('getTemplateDetails -- Test with valid responses', () => {
|
|
|
225
226
|
});
|
|
226
227
|
});
|
|
227
228
|
});
|
|
229
|
+
|
|
230
|
+
describe('getTemplateInfoById -- Test with valid responses', () => {
|
|
231
|
+
beforeEach(() => {
|
|
232
|
+
global.fetch = jest.fn(); // Mocking global fetch function
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
afterEach(() => {
|
|
236
|
+
jest.restoreAllMocks(); // Restore all mocks after each test
|
|
237
|
+
});
|
|
238
|
+
it('Should return correct response', async () => {
|
|
239
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
240
|
+
status: 200,
|
|
241
|
+
json: () => Promise.resolve({
|
|
242
|
+
status: 200,
|
|
243
|
+
response: {
|
|
244
|
+
_id: '123',
|
|
245
|
+
},
|
|
246
|
+
}),
|
|
247
|
+
}));
|
|
248
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
249
|
+
_id: '123',
|
|
250
|
+
}));
|
|
251
|
+
expect(await getTemplateInfoById({id: '123', username: 'capillary_zns', 'oa_id': 'jfhagsdhj', token: 'tuyagjahs'})).toEqual({
|
|
252
|
+
response: {
|
|
253
|
+
_id: '123',
|
|
254
|
+
},
|
|
255
|
+
status: 200,
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('Should not return correct response', async () => {
|
|
260
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
261
|
+
status: 200,
|
|
262
|
+
json: () => Promise.resolve({
|
|
263
|
+
status: 200,
|
|
264
|
+
data: {
|
|
265
|
+
_id: '123',
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
}));
|
|
269
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve({
|
|
270
|
+
_id: '123',
|
|
271
|
+
}));
|
|
272
|
+
expect(await getTemplateInfoById({id: '123', username: 'capillary_zns', 'oa_id': 'jfhagsdhj', token: 'tuyagjahs'})).toEqual({
|
|
273
|
+
data: {
|
|
274
|
+
_id: '123',
|
|
275
|
+
},
|
|
276
|
+
response: {
|
|
277
|
+
_id: '123',
|
|
278
|
+
},
|
|
279
|
+
status: 200,
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('Should not return correct response when data is undefined', async () => {
|
|
284
|
+
global.fetch.mockReturnValue(Promise.resolve({
|
|
285
|
+
status: 200,
|
|
286
|
+
json: () => Promise.resolve(),
|
|
287
|
+
}));
|
|
288
|
+
mockDecompressJsonObject.mockReturnValue(Promise.resolve());
|
|
289
|
+
expect(await getTemplateInfoById({id: '123', username: 'capillary_zns', 'oa_id': 'jfhagsdhj', token: 'tuyagjahs'})).toEqual({
|
|
290
|
+
response: undefined,
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|