@capillarytech/creatives-library 8.0.334-alpha.1 → 8.0.335

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": "8.0.334-alpha.1",
4
+ "version": "8.0.335",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -227,9 +227,11 @@ function BeeEditor(props) {
227
227
  },
228
228
  },
229
229
  onSave: (jsonFile, htmlFile) => {
230
- if (isGetBeeDataRef.current) {
230
+ if (isGetBeeDataRef.current && typeof getBEEData === 'function') {
231
231
  getBEEData(jsonFile, htmlFile);
232
- } else {
232
+ return;
233
+ }
234
+ if (typeof saveBeeData === 'function') {
233
235
  saveBeeData(jsonFile, htmlFile);
234
236
  }
235
237
  },
@@ -426,6 +428,7 @@ BeeEditor.propTypes = {
426
428
  userLocale: PropTypes.string,
427
429
  eventContextTags: PropTypes.array,
428
430
  isGetBeeData: PropTypes.bool,
431
+ getBEEData: PropTypes.func,
429
432
  };
430
433
 
431
434
  const mapStateToProps = () => createStructuredSelector({
@@ -3064,7 +3064,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
3064
3064
  });
3065
3065
 
3066
3066
  schema = this.showInsertImageButton(schema);
3067
- this.setState({ schema, showConfirmationModal: false, isSchemaChanged: true }, () => {
3067
+ this.setState({ schema, showConfirmationModal: false, isSchemaChanged: true, isGetBeeData: false }, () => {
3068
3068
  this.injectEvents(schema);
3069
3069
  });
3070
3070
  });
@@ -109,7 +109,6 @@ export function* getCmsSetting({
109
109
  const result = yield call(Api.getCmsTemplateSettingsV2, cmsType, projectId, cmsMode, langId, isEdmSupport, isBEEAppEnable);
110
110
  const cmsAccountDetail = result.data?.response.cmsDetails || {};
111
111
  const isBeeEnabled = cmsAccountDetail?.type === cmsType;
112
- console.log(isBeeEnabled, "isBeeEnabled");
113
112
  yield put({ type: types.GET_CMS_ACCOUNTS_SUCCESS, isBeeEnabled });
114
113
  yield put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: result.data.response.cmsDetails });
115
114
  } catch (error) {
@@ -4,7 +4,7 @@ exports[` 1`] = `
4
4
  Immutable.Map {
5
5
  "createTemplateInProgress": false,
6
6
  "createResponse": Immutable.Map {},
7
- "isBeeEnabled": false,
7
+ "isBeeEnabled": null,
8
8
  }
9
9
  `;
10
10
 
@@ -12,6 +12,6 @@ exports[` 2`] = `
12
12
  Immutable.Map {
13
13
  "createTemplateInProgress": true,
14
14
  "createResponse": Immutable.Map {},
15
- "isBeeEnabled": false,
15
+ "isBeeEnabled": null,
16
16
  }
17
17
  `;
@@ -88,6 +88,55 @@ describe('Email Templates Sagas', () => {
88
88
  .run();
89
89
  });
90
90
 
91
+ it('should handle creating a template successfully with onCreateTemplateComplete callback', () => {
92
+ const onCreateTemplateComplete = jest.fn();
93
+ const template = { id: 1, name: 'New Template', onCreateTemplateComplete };
94
+ const fakeResponse = {
95
+ success: true,
96
+ response: { id: 1, name: 'New Template', status: 'created' },
97
+ status: { code: 200 },
98
+ };
99
+
100
+ return expectSaga(sagas.createTemplate, template)
101
+ .provide([
102
+ [matchers.call.fn(Api.createEmailTemplate), fakeResponse],
103
+ ])
104
+ .put({
105
+ type: types.CREATE_TEMPLATE_SUCCESS,
106
+ data: fakeResponse.response,
107
+ statusCode: 200,
108
+ errorMsg: undefined,
109
+ })
110
+ .run()
111
+ .then(() => {
112
+ expect(onCreateTemplateComplete).toHaveBeenCalledWith(fakeResponse.response);
113
+ });
114
+ });
115
+
116
+ it('should handle creating a template successfully when result has no status (statusCode empty string)', () => {
117
+ const onCreateTemplateComplete = jest.fn();
118
+ const template = { id: 1, name: 'New Template', onCreateTemplateComplete };
119
+ const fakeResponse = {
120
+ success: true,
121
+ response: { id: 1, name: 'New Template' },
122
+ };
123
+
124
+ return expectSaga(sagas.createTemplate, template)
125
+ .provide([
126
+ [matchers.call.fn(Api.createEmailTemplate), fakeResponse],
127
+ ])
128
+ .put({
129
+ type: types.CREATE_TEMPLATE_SUCCESS,
130
+ data: fakeResponse.response,
131
+ statusCode: '',
132
+ errorMsg: undefined,
133
+ })
134
+ .run()
135
+ .then(() => {
136
+ expect(onCreateTemplateComplete).toHaveBeenCalledWith(fakeResponse.response);
137
+ });
138
+ });
139
+
91
140
  it('should handle errors when creating a template fails', () => {
92
141
  const template = { id: 1, name: 'New Template' };
93
142
  const fakeError = new Error('Failed to create template');
@@ -150,6 +199,29 @@ describe('Email Templates Sagas', () => {
150
199
  .run();
151
200
  });
152
201
 
202
+ it('should handle successful asset upload with no status (empty statusCode)', () => {
203
+ const uploadResponse = {
204
+ response: {
205
+ asset: {
206
+ id: 1,
207
+ url: 'http://example.com/asset.jpg',
208
+ metaInfo: { secure_file_path: 'path', file_size: 1024 },
209
+ },
210
+ },
211
+ };
212
+
213
+ return expectSaga(sagas.uploadAsset, file, assetType, fileParams)
214
+ .provide([
215
+ [matchers.call.fn(Api.uploadFile), uploadResponse],
216
+ ])
217
+ .put({
218
+ type: types.UPLOAD_ASSET_SUCCESS,
219
+ data: uploadResponse.response.asset,
220
+ statusCode: '',
221
+ })
222
+ .run();
223
+ });
224
+
153
225
  it('should handle failure in asset upload', () => {
154
226
  const error = new Error('Failed to upload asset');
155
227
 
@@ -275,6 +347,37 @@ describe('getAllAssets saga', () => {
275
347
  .run();
276
348
  });
277
349
 
350
+ it('should handle success when page > 1 (isReset false)', () => {
351
+ const fakeResponse = {
352
+ status: { code: 200 },
353
+ response: [{ id: 3, name: 'Asset 3' }],
354
+ };
355
+ const payload = { assetType: 'image', queryParams: { page: 2 } };
356
+
357
+ return expectSaga(sagas.getAllAssets, payload)
358
+ .provide([
359
+ [matchers.call.fn(Api.getAllAssets), fakeResponse],
360
+ ])
361
+ .put({
362
+ type: types.GET_ALL_ASSETS_SUCCESS,
363
+ data: fakeResponse.response,
364
+ isReset: false,
365
+ })
366
+ .run();
367
+ });
368
+
369
+ it('should handle failure when fetching all assets throws an error', () => {
370
+ const error = new Error('Network error');
371
+ const payload = { assetType: 'image', queryParams: { page: 1 } };
372
+
373
+ return expectSaga(sagas.getAllAssets, payload)
374
+ .provide([
375
+ [matchers.call.fn(Api.getAllAssets), throwError(error)],
376
+ ])
377
+ .put({ type: types.GET_ALL_ASSETS_FAILURE, error })
378
+ .run();
379
+ });
380
+
278
381
  describe('getCmsAccounts saga', () => {
279
382
  it('should handle successful CMS accounts fetch with matching type', () => {
280
383
  const cmsType = 'bee';
@@ -463,6 +566,20 @@ describe('getAllAssets saga', () => {
463
566
  .run();
464
567
  });
465
568
 
569
+ it('should use "Unknown error" fallback when statusCode is also undefined', () => {
570
+ const template = { id: 1, name: 'New Template' };
571
+ const fakeResponse = {
572
+ success: false,
573
+ };
574
+
575
+ return expectSaga(sagas.createTemplate, template)
576
+ .provide([
577
+ [matchers.call.fn(Api.createEmailTemplate), fakeResponse],
578
+ ])
579
+ .put({ type: types.CREATE_TEMPLATE_FAILURE, errorMsg: 'API Error: Unknown error' })
580
+ .run();
581
+ });
582
+
466
583
  it('should handle callback error gracefully', () => {
467
584
  const template = {
468
585
  id: 1,
@@ -569,3 +686,116 @@ describe('getAllAssets saga', () => {
569
686
  });
570
687
  });
571
688
  });
689
+
690
+
691
+ describe('getCmsSetting saga', () => {
692
+ const basePayload = {
693
+ cmsType: 'bee',
694
+ projectId: 1,
695
+ cmsMode: 'normal',
696
+ langId: 1,
697
+ isEdmSupport: false,
698
+ isBEEAppEnable: true,
699
+ };
700
+
701
+ it('should handle successful settings fetch with matching type (isBeeEnabled true)', () => {
702
+ const fakeResponse = {
703
+ data: {
704
+ response: {
705
+ cmsDetails: { type: 'bee', settings: {} },
706
+ },
707
+ },
708
+ };
709
+
710
+ return expectSaga(sagas.getCmsSetting, basePayload)
711
+ .provide([
712
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
713
+ ])
714
+ .put({ type: types.GET_CMS_ACCOUNTS_SUCCESS, isBeeEnabled: true })
715
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails })
716
+ .run();
717
+ });
718
+
719
+ it('should handle successful settings fetch with non-matching type (isBeeEnabled false)', () => {
720
+ const fakeResponse = {
721
+ data: {
722
+ response: {
723
+ cmsDetails: { type: 'ck', settings: {} },
724
+ },
725
+ },
726
+ };
727
+
728
+ return expectSaga(sagas.getCmsSetting, basePayload)
729
+ .provide([
730
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
731
+ ])
732
+ .put({ type: types.GET_CMS_ACCOUNTS_SUCCESS, isBeeEnabled: false })
733
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails })
734
+ .run();
735
+ });
736
+
737
+ it('should handle successful settings fetch when cmsDetails is undefined (fallback to empty object)', () => {
738
+ const fakeResponse = {
739
+ data: {
740
+ response: {},
741
+ },
742
+ };
743
+
744
+ return expectSaga(sagas.getCmsSetting, basePayload)
745
+ .provide([
746
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
747
+ ])
748
+ .put({ type: types.GET_CMS_ACCOUNTS_SUCCESS, isBeeEnabled: false })
749
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: undefined })
750
+ .run();
751
+ });
752
+
753
+ it('should handle error when fetching CMS settings fails', () => {
754
+ const fakeError = new Error('Failed to fetch CMS settings');
755
+
756
+ return expectSaga(sagas.getCmsSetting, basePayload)
757
+ .provide([
758
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), throwError(fakeError)],
759
+ ])
760
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_FAILURE, error: fakeError })
761
+ .run();
762
+ });
763
+ });
764
+
765
+
766
+ describe('getCmsData saga', () => {
767
+ const payload = { cmsType: 'bee', projectId: 1, langId: 1 };
768
+
769
+ it('should handle successful CMS data fetch', () => {
770
+ const fakeResponse = {
771
+ data: {
772
+ response: {
773
+ data: { html: '<p>content</p>' },
774
+ langId: 1,
775
+ },
776
+ },
777
+ };
778
+
779
+ return expectSaga(sagas.getCmsData, payload)
780
+ .provide([
781
+ [matchers.call.fn(Api.getCmsTemplateDataV2), fakeResponse],
782
+ ])
783
+ .put({
784
+ type: types.GET_CMS_EDITOR_DATA_SUCCESS,
785
+ data: fakeResponse.data.response.data,
786
+ langId: fakeResponse.data.response.langId,
787
+ })
788
+ .run();
789
+ });
790
+
791
+ it('should handle error when fetching CMS data fails', () => {
792
+ const fakeError = new Error('Failed to fetch CMS data');
793
+
794
+ return expectSaga(sagas.getCmsData, payload)
795
+ .provide([
796
+ [matchers.call.fn(Api.getCmsTemplateDataV2), throwError(fakeError)],
797
+ ])
798
+ .put({ type: types.GET_CMS_EDITOR_DATA_FAILURE, error: fakeError })
799
+ .run();
800
+ });
801
+ });