@capillarytech/creatives-library 8.0.67 → 8.0.68-alpha.2

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.67",
4
+ "version": "8.0.68-alpha.2",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -1,90 +1,92 @@
1
1
  export const expectedStateGetLiquidTagsRequest = {
2
- fetchingLiquidTags: true,
3
- fetchingSchema: true,
4
- fetchingSchemaError: "",
5
- liquidTags: [],
6
- messages: [],
7
- metaEntities: {
8
- layouts: [],
9
- tagLookupMap: {},
10
- tags: []
11
- },
12
- orgID: "",
13
- token: ""
14
- };
15
-
16
- export const expectedStateGetLiquidTagsFailure = {
17
- fetchingLiquidTags: false,
18
- fetchingSchema: true,
19
- fetchingSchemaError: "",
20
- liquidTags: [],
21
- messages: [],
22
- metaEntities: {
23
- layouts: [],
24
- tagLookupMap: {},
25
- tags: []
26
- },
27
- orgID: "",
28
- token: ""
29
- };
30
-
31
- export const expectedStateGetLiquidTagsSuccess = {
32
- fetchingLiquidTags: false,
33
- fetchingSchema: true,
34
- fetchingSchemaError: "",
35
- liquidTags: [],
36
- messages: [],
37
- metaEntities: {
38
- layouts: [],
39
- tagLookupMap: {},
40
- tags: []
41
- },
42
- orgID: "",
43
- token: ""
44
- };
45
-
46
- export const expectedStateGetSchemaForEntitySuccessTAG = {
47
- fetchingLiquidTags: false,
48
- fetchingSchema: false,
49
- fetchingSchemaError: false,
50
- liquidTags: [],
51
- messages: [],
52
- metaEntities: {
53
- layouts: undefined,
54
- tagLookupMap: { undefined: {definition: {}} },
55
- tags: { standard: { random: "32" } }
56
- },
57
- orgID: "",
58
- token: ""
59
- };
60
-
61
- export const expectedStateGetSchemaForEntitySuccess = {
62
- fetchingLiquidTags: false,
63
- fetchingSchema: false,
64
- fetchingSchemaError: false,
65
- liquidTags: [],
66
- messages: [],
67
- metaEntities: {
68
- layouts: undefined,
69
- tagLookupMap: undefined,
70
- tags: undefined
71
- },
72
- orgID: "",
73
- token: ""
74
- };
2
+ fetchingLiquidTags: true,
3
+ fetchingSchema: true,
4
+ fetchingSchemaError: "",
5
+ liquidTags: [],
6
+ messages: [],
7
+ metaEntities: {
8
+ layouts: [],
9
+ tagLookupMap: {},
10
+ tags: [],
11
+ },
12
+ orgID: "",
13
+ token: "",
14
+ };
15
+
16
+ export const expectedStateGetLiquidTagsFailure = {
17
+ fetchingLiquidTags: false,
18
+ fetchingSchema: true,
19
+ fetchingSchemaError: "",
20
+ liquidTags: [],
21
+ messages: [],
22
+ metaEntities: {
23
+ layouts: [],
24
+ tagLookupMap: {},
25
+ tags: [],
26
+ },
27
+ orgID: "",
28
+ token: "",
29
+ };
30
+
31
+ export const expectedStateGetLiquidTagsSuccess = {
32
+ fetchingLiquidTags: false,
33
+ fetchingSchema: true,
34
+ fetchingSchemaError: "",
35
+ liquidTags: [],
36
+ messages: [],
37
+ metaEntities: {
38
+ layouts: [],
39
+ tagLookupMap: {},
40
+ tags: [],
41
+ },
42
+ orgID: "",
43
+ token: "",
44
+ };
45
+
46
+ export const expectedStateGetSchemaForEntitySuccessTAG = {
47
+ fetchingLiquidTags: false,
48
+ fetchingSchema: false,
49
+ fetchingSchemaError: false,
50
+ liquidTags: [],
51
+ messages: [],
52
+ metaEntities: {
53
+ layouts: undefined,
54
+ tagLookupMap: { undefined: { definition: {} } },
55
+ tags: { standard: { random: "32" } },
56
+ },
57
+ orgID: "",
58
+ token: "",
59
+ };
60
+
61
+ export const expectedStateGetSchemaForEntitySuccess = {
62
+ fetchingLiquidTags: false,
63
+ fetchingSchema: false,
64
+ fetchingSchemaError: false,
65
+ liquidTags: [],
66
+ messages: [],
67
+ metaEntities: {
68
+ layouts: undefined,
69
+ tagLookupMap: undefined,
70
+ tags: undefined,
71
+ },
72
+ orgID: "",
73
+ token: "",
74
+ };
75
+
76
+ export const expectedForwardedTags = {
77
+ fetchingLiquidTags: false,
78
+ fetchingSchema: false,
79
+ fetchingSchemaError: '',
80
+ injectedTags: undefined,
81
+ liquidTags: [],
82
+ messages: [],
83
+ metaEntities: {
84
+ layouts: [],
85
+ tagLookupMap: {
75
86
 
76
- export const expectedForwardedTags = {
77
- fetchingLiquidTags: false,
78
- fetchingSchema: true,
79
- fetchingSchemaError: '',
80
- injectedTags: undefined,
81
- liquidTags: [],
82
- messages: [],
83
- metaEntities: {
84
- layouts: [],
85
- tagLookupMap: {},
86
- tags: []
87
87
  },
88
- orgID: "",
89
- token: ""
90
- };
88
+ tags: [],
89
+ },
90
+ orgID: "",
91
+ token: "",
92
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Created by vivek on 22/5/17.
3
3
  */
4
- import { fromJS } from 'immutable';
4
+ import { fromJS, Map as ImmutableMap } from 'immutable';
5
5
  import _ from 'lodash';
6
6
  import * as types from './constants';
7
7
  import initialState from '../../initialState';
@@ -113,20 +113,28 @@ function capReducer(state = fromJS(initialState.cap), action) {
113
113
  // Process extended tags
114
114
  const extendedSubtags = getTagMapValue(action?.data?.metaEntities?.extended);
115
115
 
116
+ const getExistingTagLookupMap = (state) => {
117
+ if (!state || !state.get) return {};
118
+ const tagLookupMap = state.getIn(['metaEntities', 'tagLookupMap']);
119
+ return state.get('metaEntities') && ImmutableMap.isMap(tagLookupMap)
120
+ ? tagLookupMap.toJS()
121
+ : {};
122
+ };
123
+
116
124
  // Combine all maps
117
125
  const combinedTagMap = {
118
126
  ...standardTagMap,
119
127
  ...customSubtags,
120
128
  ...extendedSubtags,
121
- ...state.getIn(['metaEntities', 'tagLookupMap'])?.toJS(),
129
+ ...getExistingTagLookupMap(state),
122
130
  };
123
131
  const stateMeta = state.get("metaEntities");
124
132
  return state
125
133
  .set('fetchingSchema', false)
126
134
  .set('fetchingLiquidTags', false)
127
135
  .set('metaEntities', {
128
- layouts: action.data && action.entityType === 'LAYOUT' ? action.data.metaEntities : stateMeta.layouts,
129
- tags: action.data && action.entityType === 'TAG' ? action.data.metaEntities : stateMeta.tags,
136
+ layouts: action.data && action.entityType === 'LAYOUT' ? action.data.metaEntities : stateMeta?.layouts,
137
+ tags: action.data && action.entityType === 'TAG' ? action.data.metaEntities : stateMeta?.tags,
130
138
  tagLookupMap: action?.data && action?.entityType === TAG ? combinedTagMap : stateMeta?.tagLookupMap,
131
139
  })
132
140
  .set('fetchingSchemaError', false);
@@ -1,16 +1,16 @@
1
- import { fromJS } from 'immutable';
1
+ import { fromJS, Map as ImmutableMap } from 'immutable';
2
2
  import {
3
- GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
4
- GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
5
- GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
6
- REQUEST,
7
- SUCCESS,
8
- FAILURE,
9
- GET_LIQUID_TAGS_SUCCESS,
10
- GET_LIQUID_TAGS_FAILURE,
11
- GET_LIQUID_TAGS_REQUEST,
12
- GET_SCHEMA_FOR_ENTITY_SUCCESS,
13
- SET_INJECTED_TAGS,
3
+ GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
4
+ GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
5
+ GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
6
+ REQUEST,
7
+ SUCCESS,
8
+ FAILURE,
9
+ GET_LIQUID_TAGS_SUCCESS,
10
+ GET_LIQUID_TAGS_FAILURE,
11
+ GET_LIQUID_TAGS_REQUEST,
12
+ GET_SCHEMA_FOR_ENTITY_SUCCESS,
13
+ SET_INJECTED_TAGS,
14
14
  } from '../constants';
15
15
  import reducer from '../reducer';
16
16
  import initialState from '../../../initialState';
@@ -20,12 +20,13 @@ import {
20
20
  expectedStateGetLiquidTagsSuccess,
21
21
  expectedStateGetSchemaForEntitySuccessTAG,
22
22
  expectedStateGetSchemaForEntitySuccess,
23
- expectedForwardedTags
24
23
  } from '../mockData';
24
+ import { TAG } from '../../Whatsapp/constants';
25
+ import { loadItem } from '../../../services/localStorageApi';
25
26
 
26
- const mockedInitialState = fromJS(initialState.cap);
27
27
 
28
28
  describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
29
+ const mockedInitialState = fromJS(initialState.cap);
29
30
  it('should handle GET_SUPPORT_VIDEOS_CONFIG_REQUEST', () => {
30
31
  const action = {
31
32
  type: GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
@@ -42,7 +43,7 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
42
43
  is_active: true,
43
44
  _id: "12345",
44
45
  json_config: [
45
- { data: 'Test data' },
46
+ { data: 'Test data' },
46
47
  ],
47
48
  };
48
49
  const action = {
@@ -93,8 +94,8 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
93
94
  it('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action with action type as TAG', () => {
94
95
  const action = {
95
96
  type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
96
- data: {metaEntities:{standard:{"random": "32"}}},
97
- entityType: "TAG"
97
+ data: { metaEntities: { standard: { random: "32" } } },
98
+ entityType: "TAG",
98
99
  };
99
100
 
100
101
  expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccessTAG);
@@ -103,7 +104,7 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
103
104
  it('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action', () => {
104
105
  const action = {
105
106
  type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
106
- data: {metaEntities:{standard:{"random": "32"}}},
107
+ data: { metaEntities: { standard: { random: "32" } } },
107
108
  };
108
109
 
109
110
  expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccess);
@@ -113,7 +114,108 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
113
114
  type: SET_INJECTED_TAGS,
114
115
  data: {},
115
116
  };
116
-
117
+
117
118
  expect(reducer(mockedInitialState, action).toJS())?.fetchingSchema?.toEqual(true);
118
119
  });
119
120
  });
121
+
122
+ describe('GET_SCHEMA_FOR_ENTITY_SUCCESS handler', () => {
123
+ it('should handle existing tagLookupMap correctly when metaEntities and tagLookupMap exist', () => {
124
+ const initialStateTest = fromJS({
125
+ token: loadItem('token') || '',
126
+ orgID: loadItem('orgID') || '',
127
+ messages: [],
128
+ metaEntities: {
129
+ tags: [{ id: 1, name: 'tag1' }],
130
+ layouts: ['layout1', 'layout2'],
131
+ tagLookupMap: {
132
+ existingTag: { definition: { value: 'existing' } },
133
+ anotherTag: { definition: { value: 'another' } },
134
+ },
135
+ standard: [],
136
+ },
137
+ liquidTags: [],
138
+ fetchingLiquidTags: false,
139
+ fetchingSchema: false,
140
+ fetchingSchemaError: '',
141
+ });
142
+
143
+ let action = {
144
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
145
+ entityType: TAG,
146
+ data: {
147
+ metaEntities: {
148
+ standard: [],
149
+ custom: [],
150
+ extended: [],
151
+ },
152
+ },
153
+ };
154
+
155
+ let newState = reducer(initialStateTest, action);
156
+ let metaEntities = newState.get('metaEntities');
157
+
158
+ expect(metaEntities).toEqual(expect.objectContaining({
159
+ tagLookupMap: expect.objectContaining({
160
+ existingTag: expect.objectContaining({
161
+ definition: expect.objectContaining({
162
+ value: 'existing',
163
+ }),
164
+ }),
165
+ }),
166
+ }));
167
+
168
+ action = {
169
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
170
+ entityType: 'LAYOUT',
171
+ data: {
172
+ metaEntities: {
173
+ layouts: ['layout1', 'layout2'],
174
+ standard: [],
175
+ },
176
+ },
177
+ };
178
+ newState = reducer(initialStateTest, action);
179
+ metaEntities = newState.get('metaEntities');
180
+ expect(metaEntities).toEqual(expect.objectContaining({
181
+ layouts: expect.objectContaining({
182
+ layouts: expect.arrayContaining(['layout1', 'layout2']),
183
+ }),
184
+ }));
185
+ });
186
+
187
+ it('should handle non-existent tagLookupMap by returning empty object', () => {
188
+ const initialStateTest = fromJS({
189
+ token: loadItem('token') || '',
190
+ orgID: loadItem('orgID') || '',
191
+ messages: [],
192
+ metaEntities: {
193
+ tagLookupMap: {},
194
+ },
195
+ liquidTags: [],
196
+ fetchingLiquidTags: false,
197
+ fetchingSchema: false,
198
+ fetchingSchemaError: '',
199
+ });
200
+
201
+ const action = {
202
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
203
+ entityType: TAG,
204
+ data: {
205
+ metaEntities: {
206
+ standard: [],
207
+ custom: [],
208
+ extended: [],
209
+ },
210
+ },
211
+ };
212
+
213
+ const newState = reducer(initialStateTest, action);
214
+ const metaEntities = newState.get('metaEntities');
215
+
216
+ // Updated assertions to handle plain object
217
+ expect(metaEntities).toBeDefined();
218
+ expect(metaEntities.tagLookupMap).toBeDefined();
219
+ expect(metaEntities.tagLookupMap).toEqual({});
220
+ });
221
+ });