@capillarytech/creatives-library 8.0.308 → 8.0.309

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.
Files changed (54) hide show
  1. package/constants/unified.js +5 -1
  2. package/initialState.js +0 -2
  3. package/package.json +1 -1
  4. package/utils/common.js +5 -8
  5. package/utils/commonUtils.js +36 -93
  6. package/utils/tagValidations.js +83 -223
  7. package/utils/tests/commonUtil.test.js +147 -124
  8. package/utils/tests/tagValidations.test.js +441 -358
  9. package/v2Components/ErrorInfoNote/index.js +2 -5
  10. package/v2Components/FormBuilder/index.js +137 -203
  11. package/v2Components/FormBuilder/messages.js +0 -8
  12. package/v2Components/HtmlEditor/HTMLEditor.js +0 -5
  13. package/v2Components/HtmlEditor/__tests__/HTMLEditor.apiErrors.test.js +0 -1
  14. package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +0 -15
  15. package/v2Components/HtmlEditor/components/CodeEditorPane/index.js +1 -2
  16. package/v2Containers/Cap/mockData.js +0 -14
  17. package/v2Containers/Cap/reducer.js +3 -55
  18. package/v2Containers/Cap/tests/reducer.test.js +0 -102
  19. package/v2Containers/CreativesContainer/SlideBoxContent.js +5 -1
  20. package/v2Containers/CreativesContainer/SlideBoxFooter.js +13 -5
  21. package/v2Containers/CreativesContainer/constants.js +6 -0
  22. package/v2Containers/CreativesContainer/index.js +47 -7
  23. package/v2Containers/Email/index.js +1 -5
  24. package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +23 -70
  25. package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +20 -120
  26. package/v2Containers/FTP/index.js +2 -51
  27. package/v2Containers/FTP/messages.js +0 -4
  28. package/v2Containers/InApp/index.js +35 -107
  29. package/v2Containers/InApp/tests/index.test.js +17 -6
  30. package/v2Containers/InappAdvance/index.js +4 -112
  31. package/v2Containers/InappAdvance/tests/index.test.js +2 -0
  32. package/v2Containers/Line/Container/Text/index.js +0 -1
  33. package/v2Containers/MobilePush/Create/index.js +59 -19
  34. package/v2Containers/MobilePush/Edit/index.js +48 -20
  35. package/v2Containers/MobilePushNew/index.js +12 -32
  36. package/v2Containers/MobilepushWrapper/index.js +3 -1
  37. package/v2Containers/Rcs/index.js +12 -37
  38. package/v2Containers/Sms/Create/index.js +39 -3
  39. package/v2Containers/Sms/Create/messages.js +4 -0
  40. package/v2Containers/Sms/Edit/index.js +35 -3
  41. package/v2Containers/Sms/commonMethods.js +3 -6
  42. package/v2Containers/Sms/tests/commonMethods.test.js +122 -0
  43. package/v2Containers/SmsTrai/Edit/index.js +11 -47
  44. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +6 -6
  45. package/v2Containers/SmsWrapper/index.js +2 -0
  46. package/v2Containers/TemplatesV2/index.js +28 -13
  47. package/v2Containers/Viber/index.js +0 -1
  48. package/v2Containers/WebPush/Create/hooks/useTagManagement.js +1 -3
  49. package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +0 -7
  50. package/v2Containers/WebPush/Create/index.js +2 -2
  51. package/v2Containers/WebPush/Create/utils/validation.js +17 -8
  52. package/v2Containers/WebPush/Create/utils/validation.test.js +44 -24
  53. package/v2Containers/Whatsapp/index.js +9 -17
  54. package/v2Containers/Zalo/index.js +3 -11
@@ -1,7 +1,7 @@
1
1
  import '@testing-library/jest-dom';
2
2
  import {
3
- checkSupport,
4
- extractNames,
3
+ hasUnsubscribeTag,
4
+ validateTagsCore,
5
5
  getTagMapValue,
6
6
  getLoyaltyTagsMapValue,
7
7
  getForwardedMapValues,
@@ -9,10 +9,160 @@ import {
9
9
  validateIfTagClosed,
10
10
  validateTags,
11
11
  skipTags,
12
- isInsideLiquidBlock,
12
+ checkIfSupportedTag,
13
+ transformInjectedTags,
13
14
  } from '../tagValidations';
14
15
  import { containsBase64Images } from '../content';
15
- import { eventContextTags } from '../../v2Containers/TagList/tests/mockdata';
16
+
17
+ describe('hasUnsubscribeTag', () => {
18
+ it('should return false when content is not a string', () => {
19
+ expect(hasUnsubscribeTag(null)).toBe(false);
20
+ expect(hasUnsubscribeTag(undefined)).toBe(false);
21
+ expect(hasUnsubscribeTag(123)).toBe(false);
22
+ expect(hasUnsubscribeTag({})).toBe(false);
23
+ });
24
+
25
+ it('should return false when content has no unsubscribe tag', () => {
26
+ expect(hasUnsubscribeTag('Hello world')).toBe(false);
27
+ expect(hasUnsubscribeTag('{{ name }}')).toBe(false);
28
+ });
29
+
30
+ it('should return true when content has {{ unsubscribe }}', () => {
31
+ expect(hasUnsubscribeTag('Click {{ unsubscribe }} here')).toBe(true);
32
+ expect(hasUnsubscribeTag('{{ unsubscribe }}')).toBe(true);
33
+ });
34
+ });
35
+
36
+ describe('validateTagsCore', () => {
37
+ it('should include isContentEmpty: false when includeIsContentEmpty is true', () => {
38
+ const result = validateTagsCore({
39
+ contentForBraceCheck: '{{a}}',
40
+ contentForUnsubscribeScan: '{{a}}',
41
+ tags: null,
42
+ currentModule: 'default',
43
+ isFullMode: true,
44
+ includeIsContentEmpty: true,
45
+ });
46
+ expect(result.isContentEmpty).toBe(false);
47
+ expect(result.valid).toBe(true);
48
+ });
49
+
50
+ it('should use initialMissingTags when provided', () => {
51
+ const result = validateTagsCore({
52
+ contentForBraceCheck: '{{a}}',
53
+ contentForUnsubscribeScan: '{{a}}',
54
+ tags: [{ definition: { supportedModules: [], value: 'x' } }],
55
+ currentModule: 'default',
56
+ isFullMode: false,
57
+ initialMissingTags: ['requiredTag'],
58
+ });
59
+ expect(result.missingTags).toEqual(['requiredTag']);
60
+ expect(result.valid).toBe(false);
61
+ });
62
+
63
+ it('should use custom skipTagsFn when provided', () => {
64
+ const customSkip = jest.fn(() => true);
65
+ const result = validateTagsCore({
66
+ contentForBraceCheck: '{{ unsubscribe }}',
67
+ contentForUnsubscribeScan: '{{ unsubscribe }}',
68
+ tags: [
69
+ {
70
+ definition: {
71
+ supportedModules: [{ context: 'DEFAULT', mandatory: true }],
72
+ value: 'unsubscribe',
73
+ },
74
+ },
75
+ ],
76
+ currentModule: 'DEFAULT',
77
+ isFullMode: false,
78
+ skipTagsFn: customSkip,
79
+ });
80
+ expect(customSkip).toHaveBeenCalled();
81
+ expect(result.valid).toBe(true);
82
+ });
83
+ });
84
+
85
+ describe('checkIfSupportedTag', () => {
86
+ it('should return false for empty or no injected tags', () => {
87
+ expect(checkIfSupportedTag('someTag', {})).toBe(false);
88
+ expect(checkIfSupportedTag('someTag', undefined)).toBe(false);
89
+ });
90
+
91
+ it('should return true when tag matches a top-level key', () => {
92
+ const injectedTags = { name: { name: 'Name' }, unsubscribe: { name: 'Unsubscribe' } };
93
+ expect(checkIfSupportedTag('name', injectedTags)).toBe(true);
94
+ expect(checkIfSupportedTag('unsubscribe', injectedTags)).toBe(true);
95
+ });
96
+
97
+ it('should return false when tag does not match any key', () => {
98
+ const injectedTags = { name: { name: 'Name' } };
99
+ expect(checkIfSupportedTag('other', injectedTags)).toBe(false);
100
+ });
101
+
102
+ it('should return true when tag matches a nested subtag', () => {
103
+ const injectedTags = {
104
+ customer: {
105
+ name: 'Customer',
106
+ subtags: {
107
+ first_name: { name: 'First Name' },
108
+ last_name: { name: 'Last Name' },
109
+ },
110
+ },
111
+ };
112
+ expect(checkIfSupportedTag('first_name', injectedTags)).toBe(true);
113
+ expect(checkIfSupportedTag('last_name', injectedTags)).toBe(true);
114
+ });
115
+
116
+ it('should return false when tag is in neither top-level nor subtags', () => {
117
+ const injectedTags = {
118
+ customer: {
119
+ name: 'Customer',
120
+ subtags: { first_name: { name: 'First Name' } },
121
+ },
122
+ };
123
+ expect(checkIfSupportedTag('unknown', injectedTags)).toBe(false);
124
+ });
125
+ });
126
+
127
+ describe('transformInjectedTags', () => {
128
+ it('should add tag-header and normalize subtags when key contains "subtags"', () => {
129
+ const tags = [
130
+ {
131
+ name: 'Customer',
132
+ subtags: {
133
+ first_name: { name: 'First Name' },
134
+ },
135
+ },
136
+ ];
137
+ const result = transformInjectedTags(tags);
138
+ expect(result).toBe(tags);
139
+ expect(tags[0]['tag-header']).toBe(true);
140
+ expect(tags[0].subtags).toEqual({ first_name: { name: 'First Name' } });
141
+ });
142
+
143
+ it('should recursively transform nested subtags', () => {
144
+ const tags = [
145
+ {
146
+ name: 'Parent',
147
+ subtags: {
148
+ child: {
149
+ name: 'Child',
150
+ subtags: { grandchild: { name: 'Grandchild' } },
151
+ },
152
+ },
153
+ },
154
+ ];
155
+ transformInjectedTags(tags);
156
+ expect(tags[0].subtags.child.subtags).toEqual({ grandchild: { name: 'Grandchild' } });
157
+ });
158
+
159
+ it('should return tags unchanged when no subtag keys exist', () => {
160
+ const tags = [{ name: 'Simple', desc: 'No subtags' }];
161
+ const result = transformInjectedTags(tags);
162
+ expect(result).toBe(tags);
163
+ expect(tags[0]).toEqual({ name: 'Simple', desc: 'No subtags' });
164
+ });
165
+ });
16
166
 
17
167
  describe("check if curly brackets are balanced", () => {
18
168
  it("test for balanced curly brackets", () => {
@@ -22,6 +172,9 @@ describe("check if curly brackets are balanced", () => {
22
172
  value += "}}"
23
173
  let result = validateIfTagClosed(value);
24
174
  expect(result).toEqual(true);
175
+ // no braces or empty string: match returns null, l1/l2/l3 undefined -> true
176
+ expect(validateIfTagClosed("")).toEqual(true);
177
+ expect(validateIfTagClosed("plain text no braces")).toEqual(true);
25
178
  //valid cases
26
179
  expect(validateIfTagClosed("{{{Hello}}}")).toEqual(true);
27
180
  expect(validateIfTagClosed("{{{Hello}}")).toEqual(true);
@@ -64,53 +217,41 @@ describe("validateTags", () => {
64
217
  it("should return valid response when all tags are present", () => {
65
218
  const content = "Hello {{tag1}}, {{tag2}}, {{tag3}} {{entryTrigger.lifetimePurchases}}";
66
219
 
67
- const injectedTagsParams = [];
68
220
  const location = { query: { module: "DEFAULT" } };
69
221
  const tagModule = null;
70
222
 
71
223
  const result = validateTags({
72
224
  content,
73
225
  tagsParam,
74
- injectedTagsParams,
75
226
  location,
76
227
  tagModule,
77
- eventContextTags,
78
228
  });
79
229
 
80
230
  expect(result.valid).toEqual(true);
81
231
  expect(result.missingTags).toEqual([]);
82
- expect(result.unsupportedTags).toEqual([]);
83
232
  expect(result.isBraceError).toEqual(false);
84
233
  });
85
234
 
86
- it("should return invalid response when a mandatory tag is missing", () => {
235
+ it("should return valid response when content has balanced braces and all tags present", () => {
87
236
  const content = "Hello {{tag1}}, {{tag2}}, {{tag3}}";
88
- const updatedTagsParam = [...tagsParam, {
89
- definition: {
90
- supportedModules: [{ context: "DEFAULT", mandatory: true }],
91
- value: "tag4",
92
- },
93
- },];
94
- const injectedTagsParams = [];
95
237
  const location = { query: { module: "DEFAULT" } };
96
238
  const tagModule = null;
97
239
 
98
240
  const result = validateTags({
99
241
  content,
100
- updatedTagsParam,
101
- injectedTagsParams,
242
+ tagsParam,
102
243
  location,
103
244
  tagModule,
104
245
  });
105
246
 
106
247
  expect(result.valid).toEqual(true);
107
- expect(result.unsupportedTags).toEqual(["tag1", "tag2", "tag3"]);
248
+ expect(result.missingTags).toEqual([]);
108
249
  expect(result.isBraceError).toEqual(false);
109
250
  });
110
251
 
111
- it("should return invalid response when an unsupported tag is present", () => {
252
+ it("should return valid response when content has balanced braces with missingEventContextTags and partial tagsParam", () => {
112
253
  const content = "Hello {{tag1}}, {{tag2}}, {{tag3}} {{missingEventContextTags}}";
113
- const tagsParam = [
254
+ const tagsParamLocal = [
114
255
  {
115
256
  definition: {
116
257
  supportedModules: [{ context: "DEFAULT", mandatory: true }],
@@ -124,27 +265,24 @@ describe("validateTags", () => {
124
265
  },
125
266
  },
126
267
  ];
127
- const injectedTagsParams = [];
128
268
  const location = { query: { module: "DEFAULT" } };
129
269
  const tagModule = null;
130
270
 
131
271
  const result = validateTags({
132
272
  content,
133
- tagsParam,
134
- injectedTagsParams,
273
+ tagsParam: tagsParamLocal,
135
274
  location,
136
275
  tagModule,
137
276
  });
138
277
 
139
278
  expect(result.valid).toEqual(true);
140
279
  expect(result.missingTags).toEqual([]);
141
- expect(result.unsupportedTags).toEqual(["tag3", "missingEventContextTags"]);
142
280
  expect(result.isBraceError).toEqual(false);
143
281
  });
144
282
 
145
283
  it("should return invalid response when there is an unbalanced bracket error", () => {
146
284
  const content = "Hello {{tag1}, {{tag2}}, {{tag3}}";
147
- const tagsParam = [
285
+ const tagsParamLocal = [
148
286
  {
149
287
  definition: {
150
288
  supportedModules: [{ context: "DEFAULT", mandatory: true }],
@@ -164,26 +302,23 @@ describe("validateTags", () => {
164
302
  },
165
303
  },
166
304
  ];
167
- const injectedTagsParams = [];
168
305
  const location = { query: { module: "DEFAULT" } };
169
306
  const tagModule = null;
170
307
 
171
308
  const result = validateTags({
172
309
  content,
173
- tagsParam,
174
- injectedTagsParams,
310
+ tagsParam: tagsParamLocal,
175
311
  location,
176
312
  tagModule,
177
313
  });
178
314
 
179
315
  expect(result.valid).toEqual(false);
180
- expect(result.missingTags).toEqual(["tag1"]);
181
- expect(result.unsupportedTags).toEqual([]);
316
+ expect(result.missingTags).toEqual([]);
182
317
  expect(result.isBraceError).toEqual(true);
183
318
  });
184
319
 
185
- it("should remove 'unsubscribe' from missingTags if skipTags logic is triggered", () => {
186
- const tagsParam = [
320
+ it("should require unsubscribe when mandatory and missing, and accept skipped unsubscribe variant", () => {
321
+ const tagsParamUnsubscribe = [
187
322
  {
188
323
  definition: {
189
324
  supportedModules: [{ context: "DEFAULT", mandatory: true }],
@@ -191,288 +326,310 @@ describe("validateTags", () => {
191
326
  },
192
327
  },
193
328
  ];
194
- // Content does not include {{unsubscribe}}, so it would be missing
195
- const contentMissing = "Hello {{tag1}}";
196
- const injectedTagsParams = [];
197
329
  const location = { query: { module: "DEFAULT" } };
198
330
  const tagModule = null;
199
331
 
200
- // First, verify unsubscribe is missing if not present
332
+ const contentMissing = "Hello world";
201
333
  const resultMissing = validateTags({
202
334
  content: contentMissing,
203
- tagsParam,
204
- injectedTagsParams,
335
+ tagsParam: tagsParamUnsubscribe,
205
336
  location,
206
337
  tagModule,
207
338
  });
208
339
  expect(resultMissing.missingTags).toContain("unsubscribe");
340
+ expect(resultMissing.valid).toBe(false);
209
341
 
210
- // Now, content includes a tag that triggers skipTags logic for unsubscribe
211
- // e.g., {{unsubscribe(#123456)}} matches the skipTags regex
212
342
  const contentWithSkippedUnsubscribe = "Hello {{unsubscribe(#123456)}}";
213
343
  const resultSkipped = validateTags({
214
344
  content: contentWithSkippedUnsubscribe,
215
- tagsParam,
216
- injectedTagsParams,
345
+ tagsParam: tagsParamUnsubscribe,
217
346
  location,
218
347
  tagModule,
219
348
  });
220
349
  expect(resultSkipped.missingTags).not.toContain("unsubscribe");
221
350
  expect(resultSkipped.valid).toBe(true);
222
- });
223
- });
224
351
 
225
- describe("extractNames", () => {
226
- it("should return an empty array when data is empty", () => {
227
- const data = [];
228
- const result = extractNames(data);
229
- expect(result).toEqual([]);
352
+ const contentWithWhitespaceUnsubscribe = "Hello {{ unsubscribe }}";
353
+ const resultWhitespace = validateTags({
354
+ content: contentWithWhitespaceUnsubscribe,
355
+ tagsParam: tagsParamUnsubscribe,
356
+ location,
357
+ tagModule,
358
+ });
359
+ expect(resultWhitespace.missingTags).not.toContain("unsubscribe");
360
+ expect(resultWhitespace.valid).toBe(true);
361
+ expect(resultWhitespace.unsupportedTags ?? []).toEqual([]);
230
362
  });
363
+ });
231
364
 
232
- it("should return an array of names when data contains nodes with names", () => {
233
- const data = [
234
- {
235
- name: "Node 1",
236
- children: [
237
- {
238
- name: "Node 1.1",
239
- children: [],
240
- },
241
- {
242
- name: "Node 1.2",
243
- children: [],
244
- },
245
- ],
246
- },
247
- {
248
- name: "Node 2",
249
- children: [
250
- {
251
- name: "Node 2.1",
252
- children: [],
253
- },
254
- ],
365
+ describe('validateTags wrapper (v2 consumers)', () => {
366
+ const tagsWithUnsubscribe = [
367
+ {
368
+ definition: {
369
+ supportedModules: [{ context: 'DEFAULT', mandatory: true }],
370
+ value: 'unsubscribe',
255
371
  },
256
- ];
257
- const result = extractNames(data);
258
- expect(result).toEqual([
259
- "Node 1",
260
- "Node 1.1",
261
- "Node 1.2",
262
- "Node 2",
263
- "Node 2.1",
264
- ]);
265
- });
266
-
267
- it("should ignore nodes without names", () => {
268
- const data = [
269
- {
270
- name: "Node 1",
271
- children: [
272
- {
273
- name: "Node 1.1",
274
- children: [],
275
- },
276
- {
277
- children: [],
278
- },
279
- ],
372
+ },
373
+ ];
374
+ const tagsOutboundUnsubscribe = [
375
+ {
376
+ definition: {
377
+ supportedModules: [{ context: 'outbound', mandatory: true }],
378
+ value: 'unsubscribe',
280
379
  },
281
- {
282
- name: "Node 2",
283
- children: [
284
- {
285
- name: "Node 2.1",
286
- children: [],
287
- },
288
- {
289
- name: "Node 2.2",
290
- },
291
- ],
380
+ },
381
+ ];
382
+ const tagsDefaultLowercase = [
383
+ {
384
+ definition: {
385
+ supportedModules: [{ context: 'default', mandatory: true }],
386
+ value: 'unsubscribe',
292
387
  },
293
- ];
294
- const result = extractNames(data);
295
- expect(result).toEqual([
296
- "Node 1",
297
- "Node 1.1",
298
- "Node 2",
299
- "Node 2.1",
300
- "Node 2.2",
301
- ]);
302
- });
303
- });
388
+ },
389
+ ];
304
390
 
391
+ describe('module selection (location.query.module vs tagModule vs DEFAULT)', () => {
392
+ it('uses location.query.module when set and tagModule not provided', () => {
393
+ const content = 'Hello world';
394
+ const result = validateTags({
395
+ content,
396
+ tagsParam: tagsWithUnsubscribe,
397
+ location: { query: { module: 'DEFAULT' } },
398
+ tagModule: null,
399
+ });
400
+ expect(result.missingTags).toContain('unsubscribe');
401
+ expect(result.valid).toBe(false);
402
+ });
305
403
 
306
- describe("checkSupport", () => {
307
- it("should return an empty array when args are empty", () => {
308
- const result = checkSupport();
309
- expect(result).toEqual([]);
310
- });
311
- it("should return an empty array when response data is empty", () => {
312
- const response = { data: [] };
313
- const tagObject = {};
314
- const result = checkSupport(response, tagObject);
315
- expect(result).toEqual([]);
316
- });
404
+ it('uses tagModule override when provided (overrides location.query.module)', () => {
405
+ const content = 'Hello world';
406
+ const resultWithOutbound = validateTags({
407
+ content,
408
+ tagsParam: tagsOutboundUnsubscribe,
409
+ location: { query: { module: 'DEFAULT' } },
410
+ tagModule: 'outbound',
411
+ });
412
+ expect(resultWithOutbound.missingTags).toContain('unsubscribe');
413
+ expect(resultWithOutbound.valid).toBe(false);
414
+
415
+ const resultWithDefault = validateTags({
416
+ content,
417
+ tagsParam: tagsWithUnsubscribe,
418
+ location: { query: { module: 'outbound' } },
419
+ tagModule: 'DEFAULT',
420
+ });
421
+ expect(resultWithDefault.missingTags).toContain('unsubscribe');
422
+ expect(resultWithDefault.valid).toBe(false);
423
+ });
317
424
 
318
- it("should return an empty array when tagObject is empty", () => {
319
- const response = {
320
- data: [{ name: "tag1" }, { name: "tag2" }, { name: "tag3" }],
321
- };
322
- const tagObject = {};
323
- const result = checkSupport(response, tagObject);
324
- expect(result).toEqual([]);
325
- });
425
+ it('uses DEFAULT (lowercase) when location is undefined', () => {
426
+ const content = 'Hello world';
427
+ const result = validateTags({
428
+ content,
429
+ tagsParam: tagsDefaultLowercase,
430
+ location: undefined,
431
+ tagModule: null,
432
+ });
433
+ expect(result.missingTags).toContain('unsubscribe');
434
+ expect(result.valid).toBe(false);
435
+ });
326
436
 
327
- it("should return event context tags even if tagObject is empty", () => {
328
- const response = {
329
- data: [{ name: "tag1" }, { name: "entryTrigger.lifetimePurchases" }],
330
- };
331
- const tagObject = {};
332
- const result = checkSupport(response, tagObject, eventContextTags);
333
- expect(result).toEqual(['entryTrigger.lifetimePurchases']);
437
+ it('uses DEFAULT when location.query is undefined', () => {
438
+ const content = 'Hello world';
439
+ const result = validateTags({
440
+ content,
441
+ tagsParam: tagsDefaultLowercase,
442
+ location: {},
443
+ tagModule: null,
444
+ });
445
+ expect(result.missingTags).toContain('unsubscribe');
446
+ expect(result.valid).toBe(false);
447
+ });
448
+
449
+ it('uses DEFAULT when location.query.module is falsy', () => {
450
+ const content = 'Hello world';
451
+ const result = validateTags({
452
+ content,
453
+ tagsParam: tagsDefaultLowercase,
454
+ location: { query: { module: '' } },
455
+ tagModule: null,
456
+ });
457
+ expect(result.missingTags).toContain('unsubscribe');
458
+ expect(result.valid).toBe(false);
459
+ });
334
460
  });
335
461
 
336
- it("should return an array of supported tags", () => {
337
- const response = {
338
- data: [{ name: "tag1" }, { name: "tag2" }, { name: "tag3" }],
339
- };
340
- const tagObject = {
341
- tag1: { definition: { subtags: ["tag1.1", "tag1.2"] } },
342
- tag2: { definition: { subtags: ["tag2.1", "tag2.2"] } },
343
- tag3: { definition: { subtags: ["tag3.1", "tag3.2"] } },
344
- };
345
- const result = checkSupport(response, tagObject);
346
- expect(result).toEqual(["tag1", "tag2", "tag3"]);
462
+ describe('content passed to contentForBraceCheck and contentForUnsubscribeScan', () => {
463
+ it('uses same content for brace check (isBraceError when unbalanced)', () => {
464
+ const content = 'Hello {{tag1}, {{tag2}}';
465
+ const result = validateTags({
466
+ content,
467
+ tagsParam: [],
468
+ location: { query: { module: 'DEFAULT' } },
469
+ });
470
+ expect(result.isBraceError).toBe(true);
471
+ expect(result.valid).toBe(false);
472
+ });
473
+
474
+ it('uses same content for unsubscribe scan (missing unsubscribe when required)', () => {
475
+ const content = 'Hello {{other}}';
476
+ const result = validateTags({
477
+ content,
478
+ tagsParam: tagsWithUnsubscribe,
479
+ location: { query: { module: 'DEFAULT' } },
480
+ });
481
+ expect(result.missingTags).toContain('unsubscribe');
482
+ expect(result.valid).toBe(false);
483
+ });
484
+
485
+ it('content with {{ unsubscribe }} satisfies unsubscribe requirement', () => {
486
+ const content = 'Hello {{ unsubscribe }}';
487
+ const result = validateTags({
488
+ content,
489
+ tagsParam: tagsWithUnsubscribe,
490
+ location: { query: { module: 'DEFAULT' } },
491
+ });
492
+ expect(result.missingTags).not.toContain('unsubscribe');
493
+ expect(result.valid).toBe(true);
494
+ });
347
495
  });
348
496
 
349
- it("should return an array of supported tags with subtags", () => {
350
- const response = {
351
- data: [{ name: "tag1" }, { name: "tag2" }, { name: "tag3" }],
352
- };
353
- const tagObject = {
354
- tag1: { definition: { subtags: ["tag1.1", "tag1.2"] } },
355
- tag2: { definition: { subtags: ["tag2.1", "tag2.2"] } },
356
- tag3: { definition: { subtags: ["tag3.1", "tag3.2"] } },
357
- "tag1.1": {},
358
- "tag2.1": {},
359
- "tag3.1": {},
360
- };
361
- const result = checkSupport(response, tagObject);
362
- expect(result).toEqual(["tag1", "tag2", "tag3"]);
497
+ describe('isFullMode', () => {
498
+ it('when true skips unsubscribe check (no missingTags for mandatory unsubscribe)', () => {
499
+ const content = 'Hello world';
500
+ const result = validateTags({
501
+ content,
502
+ tagsParam: tagsWithUnsubscribe,
503
+ location: { query: { module: 'DEFAULT' } },
504
+ isFullMode: true,
505
+ });
506
+ expect(result.missingTags).toEqual([]);
507
+ expect(result.valid).toBe(true);
508
+ });
509
+
510
+ it('when true still runs brace check', () => {
511
+ const content = 'Hello {{tag1}';
512
+ const result = validateTags({
513
+ content,
514
+ tagsParam: tagsWithUnsubscribe,
515
+ location: { query: { module: 'DEFAULT' } },
516
+ isFullMode: true,
517
+ });
518
+ expect(result.isBraceError).toBe(true);
519
+ expect(result.valid).toBe(false);
520
+ });
363
521
  });
364
522
 
365
- it("should return an empty array when no tags are supported", () => {
366
- const response = {
367
- data: [{ name: "tag1" }, { name: "tag2" }, { name: "tag3" }],
368
- };
369
- const tagObject = {
370
- tag4: {},
371
- tag5: {},
372
- tag6: {},
373
- };
374
- const result = checkSupport(response, tagObject);
375
- expect(result).toEqual([]);
523
+ describe('tagsParam null or empty', () => {
524
+ it('when null: only brace check runs, no missing-tag logic', () => {
525
+ const content = 'Hello {{a}}';
526
+ const result = validateTags({
527
+ content,
528
+ tagsParam: null,
529
+ location: { query: { module: 'DEFAULT' } },
530
+ });
531
+ expect(result.missingTags).toEqual([]);
532
+ expect(result.isBraceError).toBe(false);
533
+ expect(result.valid).toBe(true);
534
+ });
535
+
536
+ it('when empty array: only brace check runs', () => {
537
+ const content = 'Hello {{a}}';
538
+ const result = validateTags({
539
+ content,
540
+ tagsParam: [],
541
+ location: { query: { module: 'DEFAULT' } },
542
+ });
543
+ expect(result.missingTags).toEqual([]);
544
+ expect(result.valid).toBe(true);
545
+ });
546
+
547
+ it('when null with unbalanced braces: returns isBraceError', () => {
548
+ const content = 'Hello {{a}';
549
+ const result = validateTags({
550
+ content,
551
+ tagsParam: null,
552
+ location: { query: { module: 'DEFAULT' } },
553
+ });
554
+ expect(result.isBraceError).toBe(true);
555
+ expect(result.valid).toBe(false);
556
+ expect(result.missingTags).toEqual([]);
557
+ });
376
558
  });
377
- it("should return an array of supported tags with subtags", () => {
378
- const response = {
379
- data: [
380
- {
381
- name: "tag1",
382
- children: [{ name: "tag1.1", children: [{ name: "tag1.2" }] }],
383
- },
384
- { name: "tag2", children: [] },
385
- { name: "tag3" },
386
- ],
387
- };
388
- const tagObject = {
389
- tag1: { definition: { subtags: [".1", "tag1.2"] } },
390
- tag2: { definition: { subtags: ["tag2.1", "tag2.2"] } },
391
- tag3: { definition: { subtags: ["tag3.1", "tag3.2"] } },
392
- "tag1.1": {},
393
- "tag2.1": {},
394
- "tag3.1": {},
395
- };
396
- const result = checkSupport(response, tagObject);
397
- expect(result).toEqual(["tag1", "tag1.1", "tag2", "tag3"]);
398
- });
399
- it("should return an array of supported tags children as an object", () => {
400
- const response = {
401
- data: [
402
- { name: "tag1", children: [{ name: "tag" }] },
403
- { name: "tag2", children: [] },
404
- { name: "tag3" },
405
- ],
406
- };
407
- const tagObject = {
408
- tag1: { definition: { subtags: [".1", "tag1.2"] } },
409
- tag2: { definition: { subtags: ["tag2.1", "tag2.2"] } },
410
- tag3: { definition: { subtags: ["tag3.1", "tag3.2"] } },
411
- "tag1.1": {},
412
- "tag2.1": {},
413
- "tag3.1": {},
414
- };
415
- const result = checkSupport(response, tagObject);
416
- expect(result).toEqual(["tag1", "tag2", "tag3"]);
417
- });
418
- it("should return an empty array if tagObject is empty", () => {
419
- const response = {
420
- data: [
421
- { name: "tag1", children: [{ name: "tag" }] },
422
- { name: "tag2", children: [] },
423
- { name: "tag3" },
424
- ],
425
- };
426
- const result = checkSupport(response, {});
427
- expect(result).toEqual([]);
428
- });
429
-
430
- it("should add childName to supportedList if it is a subtag of parentTag in eventContextTags", () => {
431
- const response = { data: [{ name: "leaderboard", children: [{name: "person.userId"}]}]};
432
- const tagObject = {};
433
- const eventContextTags = [{ tagName: "leaderboard", subTags: ["userId"]}];
434
- const isLiquidFlow = true;
435
- const result = checkSupport(response, tagObject, eventContextTags, isLiquidFlow);
436
- expect(result).toEqual( [ 'leaderboard', 'person.userId' ]);
437
- });
438
-
439
- it("should not add childName to supportedList which does not have dot in eventContextTags", () => {
440
- // This case is unlikely to happen as we are not supporting tags without dot in eventContextTags
441
- const response = { data: [{ name: "entryTrigger.lifetimePoints", children: [{name: "userId"}] }]};
442
- const tagObject = {};
443
- const eventContextTags = [{ tagName: "entryTrigger.lifetimePoints", children: [{name: "userId"}] }];
444
- const isLiquidFlow = true;
445
- const result = checkSupport(response, tagObject, eventContextTags, isLiquidFlow);
446
- expect(result).toEqual( [ "entryTrigger.lifetimePoints" ]);
447
- });
448
-
449
- it("should add only parent tag to supportedList if isLiquidFlow false", () => {
450
- const response = { data: [{ name: "leaderboard", children: [{name: "person.userId"}]}]};
451
- const tagObject = {};
452
- const eventContextTags = [{ tagName: "leaderboard", subTags: ["userId"]}];
453
- const isLiquidFlow = false;
454
- const result = checkSupport(response, tagObject, eventContextTags, isLiquidFlow);
455
- expect(result).toEqual( [ 'leaderboard' ]);
456
- });
457
-
458
- it("test for checking loyalty tags in that are coming in forwardedTags", () => {
459
- const response = { data: [{ name: "leaderboard", children: [{name: "person.userId"}]}]};
460
- const tagObject = {};
461
- const isLiquidFlow = true;
462
- // forwardedTags contains tag hierarchy with parent tags and their subtags
463
- // needed for loyalty email liquid tag resolution
464
- const forwardedTags = {
465
- leaderboard: {
466
- name: "Leaderboard",
467
- subtags: {
468
- "person.userId": {
469
- name: "User ID",
470
- },
471
- },
472
- },
473
- };
474
- const result = checkSupport(response, tagObject, [], isLiquidFlow, forwardedTags);
475
- expect(result).toEqual( [ 'leaderboard', 'person.userId' ]);
559
+
560
+ describe('v2 consumer call patterns', () => {
561
+ it('Whatsapp-style: content, tagsParam, location, tagModule (getDefaultTags), isFullMode', () => {
562
+ const content = 'Hello {{ unsubscribe }}';
563
+ const result = validateTags({
564
+ content: content,
565
+ tagsParam: tagsWithUnsubscribe,
566
+ location: { query: { module: 'DEFAULT' } },
567
+ tagModule: 'DEFAULT',
568
+ isFullMode: false,
569
+ });
570
+ expect(result.valid).toBe(true);
571
+ expect(result.isBraceError).toBe(false);
572
+ });
573
+
574
+ it('Zalo / Rcs / MobilePushNew / EmailWrapper: same pattern as Whatsapp', () => {
575
+ const result = validateTags({
576
+ content: 'Hi {{ unsubscribe }}',
577
+ tagsParam: tagsWithUnsubscribe,
578
+ location: { query: { module: 'DEFAULT' } },
579
+ tagModule: 'DEFAULT',
580
+ isFullMode: false,
581
+ });
582
+ expect(result.valid).toBe(true);
583
+ });
584
+
585
+ it('Line / Viber: tagModule "outbound"', () => {
586
+ const contentMissing = 'Hello';
587
+ const resultMissing = validateTags({
588
+ content: contentMissing,
589
+ tagsParam: tagsOutboundUnsubscribe,
590
+ location: { query: { module: 'inbound' } },
591
+ tagModule: 'outbound',
592
+ isFullMode: false,
593
+ });
594
+ expect(resultMissing.missingTags).toContain('unsubscribe');
595
+ expect(resultMissing.valid).toBe(false);
596
+
597
+ const resultOk = validateTags({
598
+ content: 'Hello {{ unsubscribe }}',
599
+ tagsParam: tagsOutboundUnsubscribe,
600
+ location: {},
601
+ tagModule: 'outbound',
602
+ isFullMode: false,
603
+ });
604
+ expect(resultOk.valid).toBe(true);
605
+ });
606
+
607
+ it('WebPush: validationConfig spread (content + tagsParam, location, tagModule, isFullMode)', () => {
608
+ const validationConfig = {
609
+ tagsParam: tagsWithUnsubscribe,
610
+ location: { query: { module: 'DEFAULT' } },
611
+ tagModule: 'DEFAULT',
612
+ };
613
+ const result = validateTags({
614
+ content: 'Hello {{ unsubscribe }}',
615
+ ...validationConfig,
616
+ isFullMode: false,
617
+ });
618
+ expect(result.valid).toBe(true);
619
+ expect(result.isBraceError).toBe(false);
620
+ });
621
+
622
+ it('WebPush with isFullMode: only brace check', () => {
623
+ const result = validateTags({
624
+ content: 'Hello world',
625
+ tagsParam: tagsWithUnsubscribe,
626
+ location: { query: { module: 'DEFAULT' } },
627
+ tagModule: 'DEFAULT',
628
+ isFullMode: true,
629
+ });
630
+ expect(result.valid).toBe(true);
631
+ expect(result.missingTags).toEqual([]);
632
+ });
476
633
  });
477
634
  });
478
635
 
@@ -1048,6 +1205,10 @@ describe('getForwardedMapValues', () => {
1048
1205
  expect(getForwardedMapValues(input)).toEqual(expected);
1049
1206
  });
1050
1207
 
1208
+ test('should return empty object when called with no argument (default param)', () => {
1209
+ expect(getForwardedMapValues()).toEqual({});
1210
+ });
1211
+
1051
1212
  test('should correctly process objects with subtags', () => {
1052
1213
  const input = {
1053
1214
  customer: {
@@ -1309,84 +1470,6 @@ describe('getForwardedMapValues', () => {
1309
1470
  });
1310
1471
  });
1311
1472
 
1312
- describe('isInsideLiquidBlock', () => {
1313
- it('returns true for index inside a single block', () => {
1314
- const content = 'Hello {% assign foo = 1 %} World';
1315
- // Index of 'a' in 'assign' inside the block
1316
- const tagIndex = content.indexOf('assign');
1317
- expect(isInsideLiquidBlock(content, tagIndex)).toBe(true);
1318
- });
1319
-
1320
- it('returns false for index outside any block', () => {
1321
- const content = 'Hello {% assign foo = 1 %} World';
1322
- // Index of 'H' in 'Hello'
1323
- expect(isInsideLiquidBlock(content, 0)).toBe(false);
1324
- // Index of 'W' in 'World'
1325
- expect(isInsideLiquidBlock(content, content.indexOf('World'))).toBe(false);
1326
- });
1327
-
1328
- it('returns true for index at the start of a block', () => {
1329
- const content = 'Hello {% assign foo = 1 %} World';
1330
- // Index of '{' in '{%'
1331
- const tagIndex = content.indexOf('{%');
1332
- expect(isInsideLiquidBlock(content, tagIndex)).toBe(true);
1333
- });
1334
-
1335
- it('returns false for index at the end of a block (exclusive)', () => {
1336
- const content = 'Hello {% assign foo = 1 %} World';
1337
- // Index just after the closing '%}'
1338
- const blockEnd = content.indexOf('%}') + 2;
1339
- expect(isInsideLiquidBlock(content, blockEnd)).toBe(false);
1340
- });
1341
-
1342
- it('returns true for index inside the second of multiple blocks', () => {
1343
- const content = 'A {% first %} B {% second %} C';
1344
- const tagIndex = content.indexOf('second');
1345
- expect(isInsideLiquidBlock(content, tagIndex)).toBe(true);
1346
- });
1347
-
1348
- it('returns false for index between blocks', () => {
1349
- const content = 'A {% first %} B {% second %} C';
1350
- // Index of 'B' (between blocks)
1351
- const tagIndex = content.indexOf('B');
1352
- expect(isInsideLiquidBlock(content, tagIndex)).toBe(false);
1353
- });
1354
-
1355
- it('returns false for empty string', () => {
1356
- expect(isInsideLiquidBlock('', 0)).toBe(false);
1357
- });
1358
-
1359
- it('returns false if there are no blocks', () => {
1360
- const content = 'Just some text with no blocks';
1361
- expect(isInsideLiquidBlock(content, 5)).toBe(false);
1362
- });
1363
-
1364
- it('returns false for negative index', () => {
1365
- const content = 'Hello {% assign foo = 1 %} World';
1366
- expect(isInsideLiquidBlock(content, -1)).toBe(false);
1367
- });
1368
-
1369
- it('returns false for index beyond string length', () => {
1370
- const content = 'Hello {% assign foo = 1 %} World';
1371
- expect(isInsideLiquidBlock(content, 100)).toBe(false);
1372
- });
1373
-
1374
- it('works for nested-like blocks (not truly nested)', () => {
1375
- const content = 'A {% outer {% inner %} outer %} B';
1376
- // Index of 'inner' (should be inside the first block)
1377
- const tagIndex = content.indexOf('inner');
1378
- expect(isInsideLiquidBlock(content, tagIndex)).toBe(true);
1379
- });
1380
-
1381
- it('returns true for index at last char inside block', () => {
1382
- const content = 'A {% foo %} B';
1383
- // Index of last char inside block (just before %})
1384
- const blockStart = content.indexOf('{%');
1385
- const blockEnd = content.indexOf('%}');
1386
- expect(isInsideLiquidBlock(content, blockEnd - 1)).toBe(true);
1387
- });
1388
- });
1389
-
1390
1473
  describe('containsBase64Images', () => {
1391
1474
  let mockCapNotification;
1392
1475
  let mockCallback;