@capillarytech/creatives-library 7.17.203 → 7.17.204

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.17.203",
4
+ "version": "7.17.204",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/services/api.js CHANGED
@@ -357,10 +357,11 @@ export const getUserList = () => {
357
357
  return API.get(url);// request(url, getAPICallObject('GET'));
358
358
  };
359
359
 
360
- export const fetchSchemaForEntity = ({queryParams}) => {
360
+ export const fetchSchemaForEntity = async ({queryParams}) => {
361
361
  if (queryParams.version === "v2" && queryParams.type === "LAYOUT") {
362
362
  const schema = getSchema(queryParams.layout);
363
- return schema.then((layout) => layout).catch((err) => {
363
+ // Added async/await to ensure the schema object is resolved before returning it
364
+ return await schema.then((layout) => layout).catch((err) => {
364
365
  console.error(err);
365
366
  });
366
367
  }
@@ -11,8 +11,10 @@ import {
11
11
  getTemplateInfoById,
12
12
  askAiraForLiquid,
13
13
  getLiquidTags,
14
+ fetchSchemaForEntity,
14
15
  } from '../api';
15
16
  import { mockData } from './mockData';
17
+ import getSchema from '../getSchema';
16
18
  const sampleFile = require('../../assets/line.png');
17
19
 
18
20
  let mockDecompressJsonObject;
@@ -24,6 +26,8 @@ jest.mock('@capillarytech/cap-ui-utils', () => {
24
26
  };
25
27
  });
26
28
 
29
+ jest.mock('../getSchema', () => jest.fn());
30
+
27
31
  describe('getSenderDetails -- Test with valid responses', () => {
28
32
  it('Should return correct response', () =>
29
33
  expect(getSenderDetails('WHATSAPP', -1)).toEqual(Promise.resolve()));
@@ -438,4 +442,33 @@ describe('getLiquidTags -- Test with various responses', () => {
438
442
  error: 'Internal Server Error',
439
443
  });
440
444
  });
441
- });
445
+ });
446
+
447
+ describe('fetchSchemaForEntity', () => {
448
+ it('should fetch schema for version v2 and type LAYOUT', async () => {
449
+ const queryParams = { version: 'v2', type: 'LAYOUT', layout: 'testLayout' };
450
+ const mockLayout = { id: 'layout1', name: 'Test Layout' };
451
+
452
+ getSchema.mockReturnValue(Promise.resolve(mockLayout));
453
+
454
+ const result = await fetchSchemaForEntity({ queryParams });
455
+
456
+ expect(getSchema).toHaveBeenCalledWith(queryParams.layout);
457
+ expect(result).toEqual(mockLayout);
458
+ });
459
+
460
+ it('should handle errors when fetching schema', async () => {
461
+ const queryParams = { version: 'v2', type: 'LAYOUT', layout: 'testLayout' };
462
+ const mockError = new Error('Failed to fetch schema');
463
+
464
+ getSchema.mockReturnValue(Promise.reject(mockError));
465
+
466
+ console.error = jest.fn();
467
+
468
+ const result = await fetchSchemaForEntity({ queryParams });
469
+
470
+ expect(getSchema).toHaveBeenCalledWith(queryParams.layout);
471
+ expect(result).toBeUndefined();
472
+ expect(console.error).toHaveBeenCalledWith(mockError);
473
+ });
474
+ });
@@ -36,6 +36,7 @@ import { MOBILE_PUSH } from '../../CreativesContainer/constants';
36
36
  import { getCdnUrl } from '../../../utils/cdnTransformation';
37
37
  import { MAPP_SDK } from './constants';
38
38
  import { isEmbeddedEditOrPreview } from '../../../utils/commonUtils';
39
+ import { EMBEDDED } from '../../Whatsapp/constants';
39
40
 
40
41
  const PrefixWrapper = styled.div`
41
42
  margin-right: 16px;
@@ -110,27 +111,35 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
110
111
  let selectedWeChatAccount = {};
111
112
  const queryType = String(get(this.props, 'location.query.type', ''))?.toLowerCase();
112
113
  const creativesMode = String(get(this.props, 'creativesMode', ''))?.toLowerCase();
114
+ const { Edit: EditProps, Templates } = this.props || {};
115
+ const { selectedWeChatAccount: editSelectedWeChatAccount, templateDetails } = EditProps || {};
116
+ const { id: selectedWeChatAccountId } = editSelectedWeChatAccount || {};
117
+ const { definition } = templateDetails || {};
118
+ const { accountId: templateAccountId } = definition || {};
119
+ const { Edit: nextEdit } = nextProps || {};
113
120
  if (isEmbeddedEditOrPreview(queryType, creativesMode)) {
114
- selectedWeChatAccount = !_.isEmpty(this.props.Edit.selectedWeChatAccount)
115
- ? this.props.Edit.selectedWeChatAccount
116
- : nextProps.Edit.selectedWeChatAccount;
117
- } else if (!_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
118
- selectedWeChatAccount = this.props.Templates.selectedWeChatAccount;
121
+ selectedWeChatAccount = !_.isEmpty(editSelectedWeChatAccount)
122
+ ? editSelectedWeChatAccount
123
+ : nextEdit?.selectedWeChatAccount;
124
+ } else if (!_.isEmpty(Templates?.selectedWeChatAccount)) {
125
+ selectedWeChatAccount = Templates?.selectedWeChatAccount;
119
126
  }
120
127
 
121
- if (this.props.location.query.type === 'embedded' && !nextProps.Edit.fetchingWeCrmAccounts && !_.isEqual(this.props.Edit.weCrmAccounts, nextProps.Edit.weCrmAccounts) && (!selectedWeChatAccount || _.isEmpty(selectedWeChatAccount))) {
122
- this.setMobilePushAccountOptions(nextProps.Edit.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
128
+ if (queryType === EMBEDDED && !nextEdit?.fetchingWeCrmAccounts && !_.isEqual(EditProps?.weCrmAccounts, nextEdit?.weCrmAccounts) && (!selectedWeChatAccount || _.isEmpty(selectedWeChatAccount))) {
129
+ this.setMobilePushAccountOptions(nextEdit?.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
123
130
  }
124
- // Check if the query type is 'embedded' and the creatives mode is either 'edit' or 'preview'. Also, ensure that the selected WeChat account ID is not equal to the account ID in the template details.
125
- // If all conditions are met, set the mobile push account options using the provided weCrmAccounts and the account ID from templateData.
126
- if (isEmbeddedEditOrPreview(queryType, creativesMode) && !_.isEqual(this.props.Edit.selectedWeChatAccount?.id, this.props.Edit.templateDetails?.definition?.accountId)) {
127
- this.setMobilePushAccountOptions(nextProps.Edit.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
131
+ // Check if the current mode is either embedded edit or preview, and if the selected WeChat account ID,
132
+ // template account ID, and the next props' weCrmAccounts are available, and if fetchingWeCrmAccounts is false,
133
+ // and if the selected WeChat account ID is not equal to the template account ID.
134
+ // If all conditions are met, set the mobile push account options using the next props' weCrmAccounts and the template account ID.
135
+ if (isEmbeddedEditOrPreview(queryType, creativesMode) && nextEdit?.weCrmAccounts && templateAccountId && selectedWeChatAccountId && !_.isEqual(selectedWeChatAccountId, templateAccountId)) {
136
+ this.setMobilePushAccountOptions(nextEdit?.weCrmAccounts, templateAccountId);
128
137
  }
129
- if (!_.isEmpty(nextProps.Edit.selectedWeChatAccount) && !_.isEqual(this.props.Edit.selectedWeChatAccount, nextProps.Edit.selectedWeChatAccount) && (this.props.location.query.type === 'embedded') && this.props.location.query.module === "loyalty") {
138
+ if (!_.isEmpty(nextEdit?.selectedWeChatAccount) && !_.isEqual(editSelectedWeChatAccount, nextEdit?.selectedWeChatAccount) && (queryType === EMBEDDED) && this.props.location.query.module === "loyalty") {
130
139
  const params = {
131
140
  name: '',
132
141
  sortBy: 'Most Recent',
133
- accountId: nextProps.Edit.selectedWeChatAccount.id,
142
+ accountId: nextEdit?.selectedWeChatAccount?.id,
134
143
  };
135
144
  this.props.actions.getMobilepushTemplatesList('mobilepush', params);
136
145
  }
@@ -159,7 +168,6 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
159
168
  this.setTemplateOptions(nextProps.Edit.mobilepushTemplates);
160
169
  }
161
170
  }
162
-
163
171
  this.handleEditSchemaOnPropsChange(nextProps, selectedWeChatAccount);
164
172
  if (nextProps.Edit.uploadedAssetData) {
165
173
  const formData = _.cloneDeep(this.state.formData);