@capillarytech/creatives-library 7.17.108-alpha.0 → 7.17.108

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.108-alpha.0",
4
+ "version": "7.17.108",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/services/api.js CHANGED
@@ -84,7 +84,7 @@ function checkStatus(response) {
84
84
  statusCode: status,
85
85
  });
86
86
  }
87
- if ((status >= 200 && status < 300) || [500, 409, 413].includes(response.status)) {
87
+ if ((status >= 200 && status < 300) || [400, 409, 413, 500].includes(response.status)) {
88
88
  return response;
89
89
  }
90
90
  const isLoginPage = window.location.pathname.indexOf('/login') !== -1;
@@ -17,7 +17,7 @@ import { formatString } from '../../utils/Formatter';
17
17
  import {
18
18
  CAP_SPACE_12,
19
19
  } from '@capillarytech/cap-ui-library/styled/variables';
20
- import { WHATSAPP_HELP_DOC_LINK, JOURNEY } from './constants';
20
+ import { WHATSAPP_HELP_DOC_LINK } from './constants';
21
21
 
22
22
  const { CapLabelInline } = CapLabel;
23
23
  const StyledLabel = styled(CapLabelInline)`
@@ -33,7 +33,7 @@ const renderData = (type, value, channel) => (
33
33
  );
34
34
 
35
35
  export function SlideBoxHeader(props) {
36
- const { slidBoxContent, templateData, onShowTemplates, creativesMode, isFullMode, showPrefix, shouldShowTemplateName, channel, templateNameRenderProp, weChatTemplateType, onWeChatMaptemplateStepChange, weChatMaptemplateStep, templateStep, smsRegister, handleClose, moduleType } = props;
36
+ const { slidBoxContent, templateData, onShowTemplates, creativesMode, isFullMode, showPrefix, shouldShowTemplateName, channel, templateNameRenderProp, weChatTemplateType, onWeChatMaptemplateStepChange, weChatMaptemplateStep, templateStep, smsRegister } = props;
37
37
  const showTemplateNameHeader = isFullMode && shouldShowTemplateName;
38
38
  const mapTemplateCreate = !showTemplateNameHeader && slidBoxContent === 'createTemplate' && weChatTemplateType === MAP_TEMPLATE && templateStep !== 'modeSelection';
39
39
  const isTraiDlt = isTraiDLTEnable(isFullMode, smsRegister);
@@ -86,11 +86,6 @@ export function SlideBoxHeader(props) {
86
86
  description={![NO_COMMUNICATION, FTP].includes(channel) &&
87
87
  <FormattedMessage {...messages.creativeTemplatesDesc} />
88
88
  }
89
- prefix={!isFullMode && moduleType === JOURNEY &&
90
- <PrefixWrapper>
91
- <CapIcons.backIcon onClick={handleClose} />
92
- </PrefixWrapper>
93
- }
94
89
  />
95
90
  )}
96
91
  {showTemplateNameHeader && templateNameRenderProp()}
@@ -22,7 +22,6 @@ export const ZALO = "ZALO";
22
22
  export const INAPP = "INAPP";
23
23
  export const PREVIEW = "preview";
24
24
  export const EDIT_TEMPLATE = "editTemplate";
25
- export const JOURNEY = "journey";
26
25
 
27
26
  export const SHOW_CONTANER_LOADER = "app/CreativesContainer/SHOW_CONTANER_LOADER";
28
27
  export const HIDE_CONTAINER_LOADER = "app/CreativesContainer/HIDE_CONTAINER_LOADER";
@@ -1199,8 +1199,6 @@ export class Creatives extends React.Component {
1199
1199
  showPrefix={!isUploading} // not show back button when email template is being uploaded
1200
1200
  templateStep={this.creativesTemplateSteps[templateStep]}
1201
1201
  smsRegister={smsRegister}
1202
- handleClose={this.handleCloseSlideBox}
1203
- moduleType={this.props.messageDetails?.type}
1204
1202
  />}
1205
1203
  content={
1206
1204
  <SlideBoxContent
@@ -23,7 +23,6 @@ describe('Test SlideBoxHeader container', () => {
23
23
  templateData={templateData}
24
24
  onCreateComplete={onCreateComplete}
25
25
  isFullMode={isFullMode}
26
- moduleType="journey"
27
26
  />
28
27
  );
29
28
  };
@@ -98,11 +98,6 @@ exports[`Test SlideBoxHeader container Should render correct component for rcs c
98
98
  }
99
99
  descriptionClass=""
100
100
  inline={false}
101
- prefix={
102
- <SlideBoxHeader__PrefixWrapper>
103
- <SvgBack />
104
- </SlideBoxHeader__PrefixWrapper>
105
- }
106
101
  size="large"
107
102
  title={
108
103
  <FormattedMessage
@@ -308,11 +303,6 @@ exports[`Test SlideBoxHeader container Should render correct component for whats
308
303
  }
309
304
  descriptionClass=""
310
305
  inline={false}
311
- prefix={
312
- <SlideBoxHeader__PrefixWrapper>
313
- <SvgBack />
314
- </SlideBoxHeader__PrefixWrapper>
315
- }
316
306
  size="large"
317
307
  title={
318
308
  <FormattedMessage
@@ -50,7 +50,6 @@ exports[`Test SlideBoxContent container campaign message, add creative click rcs
50
50
  header={
51
51
  <SlideBoxHeader
52
52
  channel="RCS"
53
- handleClose={[Function]}
54
53
  isLoadingContent={true}
55
54
  onShowTemplates={[Function]}
56
55
  onWeChatMaptemplateStepChange={[Function]}
@@ -124,7 +123,6 @@ exports[`Test SlideBoxContent container campaign message, add creative click wha
124
123
  header={
125
124
  <SlideBoxHeader
126
125
  channel="WHATSAPP"
127
- handleClose={[Function]}
128
126
  isLoadingContent={true}
129
127
  onShowTemplates={[Function]}
130
128
  onWeChatMaptemplateStepChange={[Function]}
@@ -205,7 +203,6 @@ exports[`Test SlideBoxContent container campaign message, whatsapp edit all data
205
203
  header={
206
204
  <SlideBoxHeader
207
205
  channel="WHATSAPP"
208
- handleClose={[Function]}
209
206
  isLoadingContent={true}
210
207
  onShowTemplates={[Function]}
211
208
  onWeChatMaptemplateStepChange={[Function]}
@@ -281,7 +278,6 @@ exports[`Test SlideBoxContent container campaign message, whatsapp edit min data
281
278
  header={
282
279
  <SlideBoxHeader
283
280
  channel="WHATSAPP"
284
- handleClose={[Function]}
285
281
  isLoadingContent={true}
286
282
  onShowTemplates={[Function]}
287
283
  onWeChatMaptemplateStepChange={[Function]}
@@ -357,7 +353,6 @@ exports[`Test SlideBoxContent container it should clear the url, on channel chan
357
353
  header={
358
354
  <SlideBoxHeader
359
355
  channel="WHATSAPP"
360
- handleClose={[Function]}
361
356
  isLoadingContent={true}
362
357
  onShowTemplates={[Function]}
363
358
  onWeChatMaptemplateStepChange={[Function]}
@@ -1,5 +1,7 @@
1
1
  import { take, cancel, call, put, takeLatest } from 'redux-saga/effects';
2
2
  import { LOCATION_CHANGE } from 'react-router-redux';
3
+ import isEmpty from 'lodash/isEmpty';
4
+ import get from 'lodash/get';
3
5
  import * as Api from '../../services/api';
4
6
  import {
5
7
  TEMPLATE_CREATE_REQUEST,
@@ -44,7 +46,19 @@ export function* sendForApprovalCreate({ payload, callback, gupshupMediaFile })
44
46
  try {
45
47
  const result = yield call(Api.createWhatsappTemplate, { payload, gupshupMediaFile });
46
48
  if (result?.status?.code && result.status.code >= 400) {
47
- errorMsg = result?.message || result.status.code;
49
+ const { message, status } = result || {};
50
+ const errorMessageObj = get(message?.error, 'errorMessage', {});
51
+ if (!isEmpty(errorMessageObj)) {
52
+ try {
53
+ // If the errorMessageObj is plain JS and JSON.parse fails, catch block will assign the error msg
54
+ const parsedErrorMsgObj = JSON.parse(errorMessageObj);
55
+ errorMsg = parsedErrorMsgObj?.error?.message;
56
+ } catch (error) {
57
+ errorMsg = message;
58
+ }
59
+ } else {
60
+ errorMsg = message || status.code;
61
+ }
48
62
  throw errorMsg;
49
63
  }
50
64
  yield put({
@@ -251,4 +251,75 @@ export const mockData = {
251
251
  description: 'sample',
252
252
  url: "https://capillarytech.com",
253
253
  },
254
+ sendForApprovalCreatePayload: {
255
+ name: 'dffdf',
256
+ versions: {
257
+ base: {
258
+ content: {
259
+ whatsapp: {
260
+ category: 'UTILITY',
261
+ languages: [
262
+ {
263
+ language: 'sq',
264
+ content: 'fdfd',
265
+ },
266
+ ],
267
+ buttonType: 'CTA',
268
+ buttons: [
269
+ {
270
+ index: 0,
271
+ type: 'PHONE_NUMBER',
272
+ text: 'tt',
273
+ phone_number: '+913333333333333',
274
+ },
275
+ ],
276
+ mediaType: 'TEXT',
277
+ varMapped: {},
278
+ templateEditor: false,
279
+ accountId: '123456789',
280
+ accessToken: '12345',
281
+ hostName: 'karixwhatsappbulk',
282
+ whatsappMedia: {
283
+ header: '',
284
+ headerVarMapped: {},
285
+ headerTemplate: false,
286
+ footer: '',
287
+ },
288
+ },
289
+ },
290
+ },
291
+ },
292
+ type: "WHATSAPP",
293
+ },
294
+ sendForApprovalCreateResult1: {
295
+ success: false,
296
+ status: {
297
+ isError: true,
298
+ code: 400,
299
+ },
300
+ message: {
301
+ name: "StatusCodeError",
302
+ statusCode: 500,
303
+ error: {
304
+ errorCode: "1004",
305
+ errorMessage: "{\"error\":{\"message\":\"(#192) Param components[1]['buttons'][0]['phone_number'] is not a valid phone number.\",\"type\":\"OAuthException\",\"code\":192,\"fbtrace_id\":\"12345\"}}",
306
+ },
307
+ },
308
+ },
309
+ sendForApprovalCreateResult2: {
310
+ success: false,
311
+ status: {
312
+ isError: true,
313
+ code: 400,
314
+ },
315
+ message: {
316
+ name: "StatusCodeError",
317
+ statusCode: 500,
318
+ message: "500 - Invalid params",
319
+ error: {
320
+ errorCode: "1004",
321
+ errorMessage: 'Invalid params',
322
+ },
323
+ },
324
+ },
254
325
  };
@@ -1,13 +1,16 @@
1
1
  import { expectSaga, testSaga } from "redux-saga-test-plan";
2
2
  import * as matchers from "redux-saga-test-plan/matchers";
3
3
  import { takeLatest } from "redux-saga/effects";
4
- import { getMetaTagsDetails, watchGetMetaTagsDetails } from "../sagas";
4
+ import { getMetaTagsDetails, watchGetMetaTagsDetails, sendForApprovalCreate } from "../sagas";
5
5
  import {
6
6
  URL_META_TAGS_REQUEST,
7
7
  URL_META_TAGS_SUCCESS,
8
8
  URL_META_TAGS_FAILURE,
9
+ TEMPLATE_CREATE_SUCCESS,
10
+ TEMPLATE_CREATE_FAILURE,
9
11
  } from "../constants";
10
12
  import * as Api from "../../../services/api";
13
+ import { mockData } from "./mockData";
11
14
 
12
15
  describe("Whatsapp saga", () => {
13
16
  const error = new Error("error");
@@ -26,11 +29,11 @@ describe("Whatsapp saga", () => {
26
29
  },
27
30
  ],
28
31
  ])
29
- .put({
30
- type: URL_META_TAGS_SUCCESS,
31
- result: {},
32
- })
33
- .run();
32
+ .put({
33
+ type: URL_META_TAGS_SUCCESS,
34
+ result: {},
35
+ })
36
+ .run();
34
37
  });
35
38
 
36
39
  it("handle success false response from getMetaTagsDetails", () => {
@@ -47,11 +50,11 @@ describe("Whatsapp saga", () => {
47
50
  },
48
51
  ],
49
52
  ])
50
- .put({
51
- type: URL_META_TAGS_FAILURE,
52
- error: 'error',
53
- })
54
- .run();
53
+ .put({
54
+ type: URL_META_TAGS_FAILURE,
55
+ error: 'error',
56
+ })
57
+ .run();
55
58
  });
56
59
 
57
60
  it("handle success false response from getMetaTagsDetails when callback not present", () => {
@@ -67,11 +70,11 @@ describe("Whatsapp saga", () => {
67
70
  },
68
71
  ],
69
72
  ])
70
- .put({
71
- type: URL_META_TAGS_FAILURE,
72
- error: 'error',
73
- })
74
- .run();
73
+ .put({
74
+ type: URL_META_TAGS_FAILURE,
75
+ error: 'error',
76
+ })
77
+ .run();
75
78
  });
76
79
 
77
80
  it("handles error thrown", () => {
@@ -87,4 +90,112 @@ describe("Whatsapp saga", () => {
87
90
  );
88
91
  });
89
92
  });
93
+
94
+ describe("whatsapp test saga for sendForApprovalCreate", () => {
95
+ // const callBack = jest.fn();
96
+ it("handle success response from sendForApprovalCreate", () => {
97
+ expectSaga(sendForApprovalCreate, {
98
+ payload: mockData.sendForApprovalCreatePayload,
99
+ callBack,
100
+ }).provide([
101
+ [
102
+ matchers.call.fn(Api.createWhatsappTemplate),
103
+ {
104
+ success: true,
105
+ result: { response: "Test data"},
106
+ },
107
+ ],
108
+ ])
109
+ .put({
110
+ type: TEMPLATE_CREATE_SUCCESS,
111
+ result: {},
112
+ })
113
+ .run();
114
+ });
115
+
116
+ it("handle error response with json string for sendForApprovalCreate", () => {
117
+ expectSaga(sendForApprovalCreate, {
118
+ payload: mockData.sendForApprovalCreatePayload,
119
+ callBack,
120
+ }).provide([
121
+ [
122
+ matchers.call.fn(Api.createWhatsappTemplate),
123
+ mockData.sendForApprovalCreateResult1,
124
+ ],
125
+ ])
126
+ .put({
127
+ type: TEMPLATE_CREATE_FAILURE,
128
+ error: "(#192) Param components[1]['buttons'][0]['phone_number'] is not a valid phone number.",
129
+ })
130
+ .run();
131
+ });
132
+
133
+ it("handle error response for sendForApprovalCreate even if json parsing fails", () => {
134
+ expectSaga(sendForApprovalCreate, {
135
+ payload: mockData.sendForApprovalCreatePayload,
136
+ callBack,
137
+ }).provide([
138
+ [
139
+ matchers.call.fn(Api.createWhatsappTemplate),
140
+ mockData.sendForApprovalCreateResult2,
141
+ ],
142
+ ])
143
+ .put({
144
+ type: TEMPLATE_CREATE_FAILURE,
145
+ error: 'Invalid params',
146
+ })
147
+ .run();
148
+ });
149
+
150
+ it("handle error response for sendForApprovalCreate", () => {
151
+ expectSaga(sendForApprovalCreate, {
152
+ payload: mockData.sendForApprovalCreatePayload,
153
+ callBack,
154
+ }).provide([
155
+ [
156
+ matchers.call.fn(Api.createWhatsappTemplate),
157
+ {
158
+ success: false,
159
+ status: {
160
+ isError: true,
161
+ code: 500,
162
+ },
163
+ message: 'error',
164
+ },
165
+ ],
166
+ ])
167
+ .put({
168
+ type: TEMPLATE_CREATE_FAILURE,
169
+ error: 'error',
170
+ })
171
+ .run();
172
+ });
173
+
174
+ it("handle error response for sendForApprovalCreate with status code if error message empty", () => {
175
+ expectSaga(sendForApprovalCreate, {
176
+ payload: mockData.sendForApprovalCreatePayload,
177
+ callBack,
178
+ }).provide([
179
+ [
180
+ matchers.call.fn(Api.createWhatsappTemplate),
181
+ {
182
+ success: false,
183
+ status: {
184
+ isError: true,
185
+ code: 500,
186
+ },
187
+ },
188
+ ],
189
+ ])
190
+ .put({
191
+ type: TEMPLATE_CREATE_FAILURE,
192
+ error: 500,
193
+ })
194
+ .run();
195
+ });
196
+
197
+ it("handles error thrown", () => {
198
+ testSaga(sendForApprovalCreate, { callBack }).next().throw(error).next().isDone();
199
+ });
200
+ });
90
201
  });