@capillarytech/creatives-library 8.0.128 → 8.0.129-alpha.5

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.
@@ -0,0 +1,405 @@
1
+ import {
2
+ HOST_HAPTIC,
3
+ HAPTIC_CATEGORY_OPTIONS,
4
+ CATEGORY_OPTIONS_MAP,
5
+ mediaTypeOptions,
6
+ } from '../constants';
7
+
8
+ // Mock API calls
9
+ jest.mock('../../../services/api', () => ({
10
+ createWhatsappTemplate: jest.fn(),
11
+ uploadFile: jest.fn(),
12
+ getAllTemplates: jest.fn(),
13
+ }));
14
+
15
+ describe('HAPTIC WhatsApp Vendor Integration', () => {
16
+ beforeEach(() => {
17
+ jest.clearAllMocks();
18
+ });
19
+
20
+ describe('Constants and Configuration', () => {
21
+ it('should import HOST_HAPTIC constant', () => {
22
+ expect(HOST_HAPTIC).toBe('hapticwhatsappbulk');
23
+ });
24
+
25
+ it('should have HAPTIC_CATEGORY_OPTIONS defined', () => {
26
+ expect(HAPTIC_CATEGORY_OPTIONS).toBeDefined();
27
+ expect(Array.isArray(HAPTIC_CATEGORY_OPTIONS)).toBe(true);
28
+ expect(HAPTIC_CATEGORY_OPTIONS.length).toBeGreaterThan(0);
29
+ });
30
+
31
+ it('should include HAPTIC vendor in CATEGORY_OPTIONS_MAP', () => {
32
+ expect(CATEGORY_OPTIONS_MAP[HOST_HAPTIC]).toBeDefined();
33
+ expect(CATEGORY_OPTIONS_MAP[HOST_HAPTIC]).toBe(HAPTIC_CATEGORY_OPTIONS);
34
+ });
35
+
36
+ it('should have correct HAPTIC category options', () => {
37
+ const hapticOptions = CATEGORY_OPTIONS_MAP[HOST_HAPTIC];
38
+ expect(hapticOptions).toContainEqual(
39
+ expect.objectContaining({
40
+ value: 'MARKETING',
41
+ })
42
+ );
43
+ expect(hapticOptions).toContainEqual(
44
+ expect.objectContaining({
45
+ value: 'UTILITY',
46
+ })
47
+ );
48
+ });
49
+ });
50
+
51
+ describe('Utility Functions', () => {
52
+ it('should create HAPTIC payload with correct field names', () => {
53
+ const createHapticPayload = (templateData, accountData) => {
54
+ const { selectedWhatsappAccount } = accountData || {};
55
+
56
+ if (!selectedWhatsappAccount) {
57
+ return templateData;
58
+ }
59
+
60
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
61
+ const { accessToken, promotionalMessagingSSID } = configs;
62
+
63
+ const payload = { ...templateData };
64
+
65
+ if (hostName === HOST_HAPTIC) {
66
+ // HAPTIC uses different field names
67
+ payload.wabaId = sourceAccountIdentifier;
68
+ payload.access_token = accessToken;
69
+ payload.PhoneId = promotionalMessagingSSID;
70
+ payload.hostName = hostName;
71
+ } else {
72
+ // Standard vendors
73
+ payload.accountId = sourceAccountIdentifier;
74
+ payload.accessToken = accessToken;
75
+ payload.phoneId = promotionalMessagingSSID;
76
+ payload.hostName = hostName;
77
+ }
78
+
79
+ // Add default status for new templates
80
+ payload.status = payload.status || 'unsubmitted';
81
+
82
+ return payload;
83
+ };
84
+
85
+ const mockHapticAccount = {
86
+ selectedWhatsappAccount: {
87
+ sourceAccountIdentifier: 'waba-123',
88
+ configs: {
89
+ accessToken: 'haptic-token',
90
+ promotionalMessagingSSID: 'phone-456',
91
+ },
92
+ hostName: HOST_HAPTIC,
93
+ },
94
+ };
95
+
96
+ const templateData = {
97
+ name: 'Test Template',
98
+ category: 'MARKETING',
99
+ content: 'Hello {{1}}',
100
+ language: 'en',
101
+ };
102
+
103
+ const payload = createHapticPayload(templateData, mockHapticAccount);
104
+
105
+ expect(payload).toEqual({
106
+ name: 'Test Template',
107
+ category: 'MARKETING',
108
+ content: 'Hello {{1}}',
109
+ language: 'en',
110
+ wabaId: 'waba-123',
111
+ access_token: 'haptic-token',
112
+ PhoneId: 'phone-456',
113
+ hostName: HOST_HAPTIC,
114
+ status: 'unsubmitted',
115
+ });
116
+ });
117
+
118
+ it('should create standard payload with correct field names', () => {
119
+ const createHapticPayload = (templateData, accountData) => {
120
+ const { selectedWhatsappAccount } = accountData || {};
121
+
122
+ if (!selectedWhatsappAccount) {
123
+ return templateData;
124
+ }
125
+
126
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
127
+ const { accessToken, promotionalMessagingSSID } = configs;
128
+
129
+ const payload = { ...templateData };
130
+
131
+ if (hostName === HOST_HAPTIC) {
132
+ // HAPTIC uses different field names
133
+ payload.wabaId = sourceAccountIdentifier;
134
+ payload.access_token = accessToken;
135
+ payload.PhoneId = promotionalMessagingSSID;
136
+ payload.hostName = hostName;
137
+ } else {
138
+ // Standard vendors
139
+ payload.accountId = sourceAccountIdentifier;
140
+ payload.accessToken = accessToken;
141
+ payload.phoneId = promotionalMessagingSSID;
142
+ payload.hostName = hostName;
143
+ }
144
+
145
+ // Add default status for new templates
146
+ payload.status = payload.status || 'unsubmitted';
147
+
148
+ return payload;
149
+ };
150
+
151
+ const mockStandardAccount = {
152
+ selectedWhatsappAccount: {
153
+ sourceAccountIdentifier: 'account-123',
154
+ configs: {
155
+ accessToken: 'standard-token',
156
+ promotionalMessagingSSID: 'phone-456',
157
+ },
158
+ hostName: 'gupshupwhatsappbulk',
159
+ },
160
+ };
161
+
162
+ const templateData = {
163
+ name: 'Test Template',
164
+ category: 'MARKETING',
165
+ content: 'Hello {{1}}',
166
+ language: 'en',
167
+ };
168
+
169
+ const payload = createHapticPayload(templateData, mockStandardAccount);
170
+
171
+ expect(payload).toEqual({
172
+ name: 'Test Template',
173
+ category: 'MARKETING',
174
+ content: 'Hello {{1}}',
175
+ language: 'en',
176
+ accountId: 'account-123',
177
+ accessToken: 'standard-token',
178
+ phoneId: 'phone-456',
179
+ hostName: 'gupshupwhatsappbulk',
180
+ status: 'unsubmitted',
181
+ });
182
+ });
183
+
184
+ it('should handle missing account data', () => {
185
+ const createHapticPayload = (templateData, accountData) => {
186
+ const { selectedWhatsappAccount } = accountData || {};
187
+
188
+ if (!selectedWhatsappAccount) {
189
+ return templateData;
190
+ }
191
+
192
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
193
+ const { accessToken, promotionalMessagingSSID } = configs;
194
+
195
+ const payload = { ...templateData };
196
+
197
+ if (hostName === HOST_HAPTIC) {
198
+ // HAPTIC uses different field names
199
+ payload.wabaId = sourceAccountIdentifier;
200
+ payload.access_token = accessToken;
201
+ payload.PhoneId = promotionalMessagingSSID;
202
+ payload.hostName = hostName;
203
+ } else {
204
+ // Standard vendors
205
+ payload.accountId = sourceAccountIdentifier;
206
+ payload.accessToken = accessToken;
207
+ payload.phoneId = promotionalMessagingSSID;
208
+ payload.hostName = hostName;
209
+ }
210
+
211
+ // Add default status for new templates
212
+ payload.status = payload.status || 'unsubmitted';
213
+
214
+ return payload;
215
+ };
216
+
217
+ const templateData = {
218
+ name: 'Test Template',
219
+ category: 'MARKETING',
220
+ content: 'Hello {{1}}',
221
+ };
222
+
223
+ const payload = createHapticPayload(templateData, null);
224
+
225
+ expect(payload).toEqual({
226
+ name: 'Test Template',
227
+ category: 'MARKETING',
228
+ content: 'Hello {{1}}',
229
+ });
230
+ });
231
+ });
232
+
233
+ describe('Edge Cases', () => {
234
+ it('should handle empty string values', () => {
235
+ const createHapticPayload = (templateData, accountData) => {
236
+ const { selectedWhatsappAccount } = accountData || {};
237
+
238
+ if (!selectedWhatsappAccount) {
239
+ return templateData;
240
+ }
241
+
242
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
243
+ const { accessToken, promotionalMessagingSSID } = configs;
244
+
245
+ const payload = { ...templateData };
246
+
247
+ if (hostName === HOST_HAPTIC) {
248
+ // HAPTIC uses different field names
249
+ payload.wabaId = sourceAccountIdentifier;
250
+ payload.access_token = accessToken;
251
+ payload.PhoneId = promotionalMessagingSSID;
252
+ payload.hostName = hostName;
253
+ } else {
254
+ // Standard vendors
255
+ payload.accountId = sourceAccountIdentifier;
256
+ payload.accessToken = accessToken;
257
+ payload.phoneId = promotionalMessagingSSID;
258
+ payload.hostName = hostName;
259
+ }
260
+
261
+ // Add default status for new templates
262
+ payload.status = payload.status || 'unsubmitted';
263
+
264
+ return payload;
265
+ };
266
+
267
+ const accountDataWithEmptyStrings = {
268
+ selectedWhatsappAccount: {
269
+ sourceAccountIdentifier: '',
270
+ configs: {
271
+ accessToken: '',
272
+ promotionalMessagingSSID: '',
273
+ },
274
+ hostName: HOST_HAPTIC,
275
+ },
276
+ };
277
+
278
+ const templateData = {
279
+ name: 'Test Template',
280
+ category: 'MARKETING',
281
+ content: 'Hello {{1}}',
282
+ };
283
+
284
+ const payload = createHapticPayload(templateData, accountDataWithEmptyStrings);
285
+
286
+ expect(payload.wabaId).toBe('');
287
+ expect(payload.access_token).toBe('');
288
+ expect(payload.PhoneId).toBe('');
289
+ });
290
+
291
+ it('should handle null values', () => {
292
+ const createHapticPayload = (templateData, accountData) => {
293
+ const { selectedWhatsappAccount } = accountData || {};
294
+
295
+ if (!selectedWhatsappAccount) {
296
+ return templateData;
297
+ }
298
+
299
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
300
+ const { accessToken, promotionalMessagingSSID } = configs;
301
+
302
+ const payload = { ...templateData };
303
+
304
+ if (hostName === HOST_HAPTIC) {
305
+ // HAPTIC uses different field names
306
+ payload.wabaId = sourceAccountIdentifier;
307
+ payload.access_token = accessToken;
308
+ payload.PhoneId = promotionalMessagingSSID;
309
+ payload.hostName = hostName;
310
+ } else {
311
+ // Standard vendors
312
+ payload.accountId = sourceAccountIdentifier;
313
+ payload.accessToken = accessToken;
314
+ payload.phoneId = promotionalMessagingSSID;
315
+ payload.hostName = hostName;
316
+ }
317
+
318
+ // Add default status for new templates
319
+ payload.status = payload.status || 'unsubmitted';
320
+
321
+ return payload;
322
+ };
323
+
324
+ const accountDataWithNulls = {
325
+ selectedWhatsappAccount: {
326
+ sourceAccountIdentifier: null,
327
+ configs: {
328
+ accessToken: null,
329
+ promotionalMessagingSSID: null,
330
+ },
331
+ hostName: HOST_HAPTIC,
332
+ },
333
+ };
334
+
335
+ const templateData = {
336
+ name: 'Test Template',
337
+ category: 'MARKETING',
338
+ content: 'Hello {{1}}',
339
+ };
340
+
341
+ const payload = createHapticPayload(templateData, accountDataWithNulls);
342
+
343
+ expect(payload.wabaId).toBeNull();
344
+ expect(payload.access_token).toBeNull();
345
+ expect(payload.PhoneId).toBeNull();
346
+ });
347
+
348
+ it('should handle undefined values', () => {
349
+ const createHapticPayload = (templateData, accountData) => {
350
+ const { selectedWhatsappAccount } = accountData || {};
351
+
352
+ if (!selectedWhatsappAccount) {
353
+ return templateData;
354
+ }
355
+
356
+ const { sourceAccountIdentifier, configs = {}, hostName } = selectedWhatsappAccount;
357
+ const { accessToken, promotionalMessagingSSID } = configs;
358
+
359
+ const payload = { ...templateData };
360
+
361
+ if (hostName === HOST_HAPTIC) {
362
+ // HAPTIC uses different field names
363
+ payload.wabaId = sourceAccountIdentifier;
364
+ payload.access_token = accessToken;
365
+ payload.PhoneId = promotionalMessagingSSID;
366
+ payload.hostName = hostName;
367
+ } else {
368
+ // Standard vendors
369
+ payload.accountId = sourceAccountIdentifier;
370
+ payload.accessToken = accessToken;
371
+ payload.phoneId = promotionalMessagingSSID;
372
+ payload.hostName = hostName;
373
+ }
374
+
375
+ // Add default status for new templates
376
+ payload.status = payload.status || 'unsubmitted';
377
+
378
+ return payload;
379
+ };
380
+
381
+ const accountDataWithUndefined = {
382
+ selectedWhatsappAccount: {
383
+ sourceAccountIdentifier: undefined,
384
+ configs: {
385
+ accessToken: undefined,
386
+ promotionalMessagingSSID: undefined,
387
+ },
388
+ hostName: HOST_HAPTIC,
389
+ },
390
+ };
391
+
392
+ const templateData = {
393
+ name: 'Test Template',
394
+ category: 'MARKETING',
395
+ content: 'Hello {{1}}',
396
+ };
397
+
398
+ const payload = createHapticPayload(templateData, accountDataWithUndefined);
399
+
400
+ expect(payload.wabaId).toBeUndefined();
401
+ expect(payload.access_token).toBeUndefined();
402
+ expect(payload.PhoneId).toBeUndefined();
403
+ });
404
+ });
405
+ });