@capillarytech/creatives-library 8.0.345-alpha.14 → 8.0.345-alpha.16

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.345-alpha.14",
4
+ "version": "8.0.345-alpha.16",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -87,6 +87,7 @@ function emailReducer(state = initialState, action) {
87
87
  case types.GET_CMS_EDITOR_DETAILS_SUCCESS:
88
88
  return state
89
89
  .set('fetchingCmsSettings', false)
90
+ .set('isBeeEnabled', action.isBeeEnabled)
90
91
  .set('CmsSettings', fromJS(action.settings));
91
92
  case types.GET_CMS_EDITOR_DETAILS_FAILURE:
92
93
  return state
@@ -103,18 +103,19 @@ export function* getAllAssets(assetType, queryParams) {
103
103
  }
104
104
 
105
105
  export function* getCmsSetting({
106
- cmsType, projectId, cmsMode, langId, isEdmSupport,
106
+ cmsType, projectId, cmsMode, langId, isEdmSupport, isBEEAppEnable: isBEEAppEnableFromAction,
107
107
  }) {
108
108
  try {
109
109
  const emailState = yield select((state) => state.get('email'));
110
- if (!emailState.get('cmsAccountsLoaded')) {
110
+ if (!emailState.get('cmsAccountsLoaded') && emailState.get('fetchingCmsAccounts')) {
111
111
  yield take([types.GET_CMS_ACCOUNTS_SUCCESS, types.GET_CMS_ACCOUNTS_FAILURE]);
112
112
  }
113
113
  const updatedState = yield select((state) => state.get('email'));
114
- const isBEEAppEnable = updatedState.get('isBeeEnabled');
115
-
114
+ const isBEEAppEnable = updatedState.get('isBeeEnabled') ?? isBEEAppEnableFromAction;
116
115
  const result = yield call(Api.getCmsTemplateSettingsV2, cmsType, projectId, cmsMode, langId, isEdmSupport, isBEEAppEnable);
117
- yield put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: result.data.response.cmsDetails });
116
+ const cmsAccountDetail = result.data?.response.cmsDetails || {};
117
+ const isBeeEnabled = cmsAccountDetail?.type === cmsType;
118
+ yield put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: cmsAccountDetail, isBeeEnabled });
118
119
  } catch (error) {
119
120
  yield put({ type: types.GET_CMS_EDITOR_DETAILS_FAILURE, error });
120
121
  }
@@ -16,6 +16,53 @@ describe('emailReducer', () => {
16
16
  expect(emailReducer(undefined, action)).toMatchSnapshot();
17
17
  });
18
18
 
19
+ it.concurrent('it handles GET_CMS_EDITOR_DETAILS_SUCCESS action — sets isBeeEnabled true and CmsSettings', () => {
20
+ const initialState = fromJS({ isBeeEnabled: null, fetchingCmsSettings: true });
21
+ const action = {
22
+ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS,
23
+ isBeeEnabled: true,
24
+ settings: { isDragDrop: true, editorType: 'bee' },
25
+ };
26
+ const result = emailReducer(initialState, action);
27
+ expect(result.get('fetchingCmsSettings')).toBe(false);
28
+ expect(result.get('isBeeEnabled')).toBe(true);
29
+ expect(result.getIn(['CmsSettings', 'isDragDrop'])).toBe(true);
30
+ });
31
+
32
+ it.concurrent('it handles GET_CMS_EDITOR_DETAILS_SUCCESS action — sets isBeeEnabled false', () => {
33
+ const initialState = fromJS({ isBeeEnabled: true, fetchingCmsSettings: true });
34
+ const action = {
35
+ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS,
36
+ isBeeEnabled: false,
37
+ settings: {},
38
+ };
39
+ const result = emailReducer(initialState, action);
40
+ expect(result.get('fetchingCmsSettings')).toBe(false);
41
+ expect(result.get('isBeeEnabled')).toBe(false);
42
+ });
43
+
44
+ it.concurrent('it handles GET_CMS_EDITOR_DETAILS_SUCCESS action — overwrites stale isBeeEnabled from CLEAR_ALL_VALUES (null)', () => {
45
+ const initialState = fromJS({ isBeeEnabled: null, fetchingCmsSettings: true });
46
+ const action = {
47
+ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS,
48
+ isBeeEnabled: true,
49
+ settings: { type: 'bee' },
50
+ };
51
+ const result = emailReducer(initialState, action);
52
+ expect(result.get('isBeeEnabled')).toBe(true);
53
+ });
54
+
55
+ it.concurrent('it handles GET_CMS_EDITOR_DETAILS_SUCCESS action — sets CmsSettings to empty object when settings is {}', () => {
56
+ const initialState = fromJS({ CmsSettings: { old: 'data' } });
57
+ const action = {
58
+ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS,
59
+ isBeeEnabled: false,
60
+ settings: {},
61
+ };
62
+ const result = emailReducer(initialState, action);
63
+ expect(result.get('CmsSettings').toJS()).toEqual({});
64
+ });
65
+
19
66
  it.concurrent('it handles GET_CMS_ACCOUNTS_REQUEST action (line 111-113)', () => {
20
67
  const initialState = fromJS({
21
68
  isBeeEnabled: true, // Start with true to verify it gets set to false
@@ -717,7 +717,7 @@ describe('getCmsSetting saga', () => {
717
717
  },
718
718
  [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
719
719
  ])
720
- .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails })
720
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails, isBeeEnabled: true })
721
721
  .run();
722
722
  });
723
723
 
@@ -739,7 +739,7 @@ describe('getCmsSetting saga', () => {
739
739
  },
740
740
  [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
741
741
  ])
742
- .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails })
742
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: fakeResponse.data.response.cmsDetails, isBeeEnabled: false })
743
743
  .run();
744
744
  });
745
745
 
@@ -759,7 +759,7 @@ describe('getCmsSetting saga', () => {
759
759
  },
760
760
  [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
761
761
  ])
762
- .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: undefined })
762
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: {}, isBeeEnabled: false })
763
763
  .run();
764
764
  });
765
765
 
@@ -778,6 +778,128 @@ describe('getCmsSetting saga', () => {
778
778
  .put({ type: types.GET_CMS_EDITOR_DETAILS_FAILURE, error: fakeError })
779
779
  .run();
780
780
  });
781
+
782
+ it('should wait for accounts when fetchingCmsAccounts is true and cmsAccountsLoaded is false (accounts succeed)', () => {
783
+ const fakeResponse = {
784
+ data: { response: { cmsDetails: { type: 'bee', settings: {} } } },
785
+ };
786
+ let selectCallCount = 0;
787
+
788
+ return expectSaga(sagas.getCmsSetting, basePayload)
789
+ .provide([
790
+ {
791
+ select(effect, next) {
792
+ selectCallCount += 1;
793
+ if (selectCallCount === 1) {
794
+ return fromJS({ cmsAccountsLoaded: false, fetchingCmsAccounts: true, isBeeEnabled: null });
795
+ }
796
+ return fromJS({ cmsAccountsLoaded: true, fetchingCmsAccounts: false, isBeeEnabled: true });
797
+ },
798
+ },
799
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
800
+ ])
801
+ .dispatch({ type: types.GET_CMS_ACCOUNTS_SUCCESS, isBeeEnabled: true })
802
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { type: 'bee', settings: {} }, isBeeEnabled: true })
803
+ .run();
804
+ });
805
+
806
+ it('should wait for accounts when fetchingCmsAccounts is true and cmsAccountsLoaded is false (accounts fail)', () => {
807
+ const fakeResponse = {
808
+ data: { response: { cmsDetails: { type: 'ck', settings: {} } } },
809
+ };
810
+ let selectCallCount = 0;
811
+
812
+ return expectSaga(sagas.getCmsSetting, basePayload)
813
+ .provide([
814
+ {
815
+ select(effect, next) {
816
+ selectCallCount += 1;
817
+ if (selectCallCount === 1) {
818
+ return fromJS({ cmsAccountsLoaded: false, fetchingCmsAccounts: true, isBeeEnabled: null });
819
+ }
820
+ return fromJS({ cmsAccountsLoaded: true, fetchingCmsAccounts: false, isBeeEnabled: false });
821
+ },
822
+ },
823
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
824
+ ])
825
+ .dispatch({ type: types.GET_CMS_ACCOUNTS_FAILURE })
826
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { type: 'ck', settings: {} }, isBeeEnabled: false })
827
+ .run();
828
+ });
829
+
830
+ it('should skip wait and use isBEEAppEnableFromAction as fallback when cmsAccountsLoaded is false but fetchingCmsAccounts is false', () => {
831
+ const fakeResponse = {
832
+ data: { response: { cmsDetails: { type: 'bee', settings: {} } } },
833
+ };
834
+
835
+ return expectSaga(sagas.getCmsSetting, { ...basePayload, isBEEAppEnable: true })
836
+ .provide([
837
+ {
838
+ select(effect, next) {
839
+ return fromJS({ cmsAccountsLoaded: false, fetchingCmsAccounts: false, isBeeEnabled: null });
840
+ },
841
+ },
842
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
843
+ ])
844
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { type: 'bee', settings: {} }, isBeeEnabled: true })
845
+ .run();
846
+ });
847
+
848
+ it('should use state isBeeEnabled (null) and fall back to isBEEAppEnableFromAction via ?? operator', () => {
849
+ const fakeResponse = {
850
+ data: { response: { cmsDetails: { type: 'bee', settings: {} } } },
851
+ };
852
+
853
+ return expectSaga(sagas.getCmsSetting, { ...basePayload, isBEEAppEnable: true })
854
+ .provide([
855
+ {
856
+ select(effect, next) {
857
+ return fromJS({ cmsAccountsLoaded: true, fetchingCmsAccounts: false, isBeeEnabled: null });
858
+ },
859
+ },
860
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
861
+ ])
862
+ .call(Api.getCmsTemplateSettingsV2, basePayload.cmsType, basePayload.projectId, basePayload.cmsMode, basePayload.langId, basePayload.isEdmSupport, true)
863
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { type: 'bee', settings: {} }, isBeeEnabled: true })
864
+ .run();
865
+ });
866
+
867
+ it('should use state isBeeEnabled false over isBEEAppEnableFromAction true via ?? operator (false is not null/undefined)', () => {
868
+ const fakeResponse = {
869
+ data: { response: { cmsDetails: { type: 'bee', settings: {} } } },
870
+ };
871
+
872
+ return expectSaga(sagas.getCmsSetting, { ...basePayload, isBEEAppEnable: true })
873
+ .provide([
874
+ {
875
+ select(effect, next) {
876
+ return fromJS({ cmsAccountsLoaded: true, fetchingCmsAccounts: false, isBeeEnabled: false });
877
+ },
878
+ },
879
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
880
+ ])
881
+ .call(Api.getCmsTemplateSettingsV2, basePayload.cmsType, basePayload.projectId, basePayload.cmsMode, basePayload.langId, basePayload.isEdmSupport, false)
882
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { type: 'bee', settings: {} }, isBeeEnabled: true })
883
+ .run();
884
+ });
885
+
886
+ it('should derive isBeeEnabled false when cmsDetails type is undefined', () => {
887
+ const fakeResponse = {
888
+ data: { response: { cmsDetails: { settings: {} } } },
889
+ };
890
+
891
+ return expectSaga(sagas.getCmsSetting, basePayload)
892
+ .provide([
893
+ {
894
+ select(effect, next) {
895
+ return fromJS({ cmsAccountsLoaded: true, fetchingCmsAccounts: false, isBeeEnabled: true });
896
+ },
897
+ },
898
+ [matchers.call.fn(Api.getCmsTemplateSettingsV2), fakeResponse],
899
+ ])
900
+ .put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: { settings: {} }, isBeeEnabled: false })
901
+ .run();
902
+ });
781
903
  });
782
904
 
783
905