@catalisa/wpp-sdk 0.2.2 → 0.3.0
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/dist/http/client.d.ts +4 -0
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +6 -0
- package/dist/http/client.js.map +1 -1
- package/dist/resources/webhooks.d.ts +19 -0
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +30 -0
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/resources/whatsapp.d.ts +169 -1
- package/dist/resources/whatsapp.d.ts.map +1 -1
- package/dist/resources/whatsapp.js +191 -0
- package/dist/resources/whatsapp.js.map +1 -1
- package/dist/resources/whatsapp.test.d.ts +2 -0
- package/dist/resources/whatsapp.test.d.ts.map +1 -0
- package/dist/resources/whatsapp.test.js +780 -0
- package/dist/resources/whatsapp.test.js.map +1 -0
- package/dist/test/fixtures/webhook-events.d.ts +1197 -0
- package/dist/test/fixtures/webhook-events.d.ts.map +1 -0
- package/dist/test/fixtures/webhook-events.js +737 -0
- package/dist/test/fixtures/webhook-events.js.map +1 -0
- package/dist/test/message-type-filter.test.d.ts +6 -0
- package/dist/test/message-type-filter.test.d.ts.map +1 -0
- package/dist/test/message-type-filter.test.js +368 -0
- package/dist/test/message-type-filter.test.js.map +1 -0
- package/dist/types/webhook.d.ts +31 -0
- package/dist/types/webhook.d.ts.map +1 -1
- package/dist/types/webhook.js +24 -0
- package/dist/types/webhook.js.map +1 -1
- package/dist/types/whatsapp.d.ts +190 -2
- package/dist/types/whatsapp.d.ts.map +1 -1
- package/package.json +14 -3
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const whatsapp_1 = require("./whatsapp");
|
|
5
|
+
// Mock HTTPClient
|
|
6
|
+
vitest_1.vi.mock('../http/client', () => ({
|
|
7
|
+
HTTPClient: vitest_1.vi.fn().mockImplementation(() => ({
|
|
8
|
+
get: vitest_1.vi.fn(),
|
|
9
|
+
post: vitest_1.vi.fn(),
|
|
10
|
+
put: vitest_1.vi.fn(),
|
|
11
|
+
patch: vitest_1.vi.fn(),
|
|
12
|
+
delete: vitest_1.vi.fn(),
|
|
13
|
+
getBaseURL: vitest_1.vi.fn().mockReturnValue('https://api.example.com'),
|
|
14
|
+
})),
|
|
15
|
+
}));
|
|
16
|
+
(0, vitest_1.describe)('WhatsAppResource', () => {
|
|
17
|
+
let whatsapp;
|
|
18
|
+
let mockHttp;
|
|
19
|
+
(0, vitest_1.beforeEach)(() => {
|
|
20
|
+
mockHttp = {
|
|
21
|
+
get: vitest_1.vi.fn(),
|
|
22
|
+
post: vitest_1.vi.fn(),
|
|
23
|
+
getBaseURL: vitest_1.vi.fn().mockReturnValue('https://api.example.com'),
|
|
24
|
+
};
|
|
25
|
+
whatsapp = new whatsapp_1.WhatsAppResource(mockHttp);
|
|
26
|
+
});
|
|
27
|
+
// ===== Session Management =====
|
|
28
|
+
(0, vitest_1.describe)('Session Management', () => {
|
|
29
|
+
(0, vitest_1.it)('should connect with default params', async () => {
|
|
30
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-123' };
|
|
31
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
32
|
+
const result = await whatsapp.connect();
|
|
33
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/connect', {});
|
|
34
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('should connect with driver and callback params', async () => {
|
|
37
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-123' };
|
|
38
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
39
|
+
const result = await whatsapp.connect({
|
|
40
|
+
driver: 'cloud-api',
|
|
41
|
+
callbackUrl: 'https://example.com/callback',
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/connect', {
|
|
44
|
+
driver: 'cloud-api',
|
|
45
|
+
callbackUrl: 'https://example.com/callback',
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('should connect with cloud API credentials', async () => {
|
|
50
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-123' };
|
|
51
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
52
|
+
const result = await whatsapp.connect({
|
|
53
|
+
driver: 'cloud-api',
|
|
54
|
+
cloudApi: {
|
|
55
|
+
phoneNumberId: '123456789',
|
|
56
|
+
accessToken: 'EAAG...',
|
|
57
|
+
businessAccountId: 'waba-id',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/connect', {
|
|
61
|
+
driver: 'cloud-api',
|
|
62
|
+
cloudApi: {
|
|
63
|
+
phoneNumberId: '123456789',
|
|
64
|
+
accessToken: 'EAAG...',
|
|
65
|
+
businessAccountId: 'waba-id',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.it)('should reconnect session', async () => {
|
|
71
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-456' };
|
|
72
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
73
|
+
const result = await whatsapp.reconnect({ force: true });
|
|
74
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/reconnect', { force: true });
|
|
75
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.it)('should reset session', async () => {
|
|
78
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-789' };
|
|
79
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
80
|
+
const result = await whatsapp.reset();
|
|
81
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/reset', {});
|
|
82
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
83
|
+
});
|
|
84
|
+
(0, vitest_1.it)('should logout', async () => {
|
|
85
|
+
const mockResponse = { enqueued: true, correlationId: 'corr-logout' };
|
|
86
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
87
|
+
const result = await whatsapp.logout();
|
|
88
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/logout', {});
|
|
89
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
90
|
+
});
|
|
91
|
+
(0, vitest_1.it)('should ping device', async () => {
|
|
92
|
+
const mockResponse = { enqueued: true, correlationId: 'ping-123' };
|
|
93
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
94
|
+
const result = await whatsapp.ping();
|
|
95
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/ping');
|
|
96
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.it)('should get QR code', async () => {
|
|
99
|
+
const mockResponse = { qr: 'base64-qr-data', status: 'qr', expiresAt: '2024-01-01T00:00:00Z' };
|
|
100
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
101
|
+
const result = await whatsapp.getQR('tenant-123');
|
|
102
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/qr');
|
|
103
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
104
|
+
});
|
|
105
|
+
(0, vitest_1.it)('should get device info', async () => {
|
|
106
|
+
const mockDevice = {
|
|
107
|
+
id: 'device-1',
|
|
108
|
+
tenantId: 'tenant-123',
|
|
109
|
+
deviceId: 'default',
|
|
110
|
+
status: 'open',
|
|
111
|
+
driver: 'baileys',
|
|
112
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
113
|
+
createdAt: '2024-01-01T00:00:00Z',
|
|
114
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
115
|
+
};
|
|
116
|
+
mockHttp.get.mockResolvedValue(mockDevice);
|
|
117
|
+
const result = await whatsapp.getDevice('tenant-123');
|
|
118
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/device');
|
|
119
|
+
(0, vitest_1.expect)(result).toEqual(mockDevice);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
// ===== Driver Configuration =====
|
|
123
|
+
(0, vitest_1.describe)('Driver Configuration', () => {
|
|
124
|
+
(0, vitest_1.it)('should configure driver for Baileys', async () => {
|
|
125
|
+
const mockResponse = {
|
|
126
|
+
tenantId: 'tenant-123',
|
|
127
|
+
deviceId: 'default',
|
|
128
|
+
driver: 'baileys',
|
|
129
|
+
configured: true,
|
|
130
|
+
};
|
|
131
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
132
|
+
const result = await whatsapp.configureDriver('tenant-123', {
|
|
133
|
+
driver: 'baileys',
|
|
134
|
+
});
|
|
135
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/tenant-123/driver/default', {
|
|
136
|
+
driver: 'baileys',
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
139
|
+
});
|
|
140
|
+
(0, vitest_1.it)('should configure driver for Cloud API with credentials', async () => {
|
|
141
|
+
const mockResponse = {
|
|
142
|
+
tenantId: 'tenant-123',
|
|
143
|
+
deviceId: 'default',
|
|
144
|
+
driver: 'cloud-api',
|
|
145
|
+
configured: true,
|
|
146
|
+
cloudApi: {
|
|
147
|
+
phoneNumberId: '123456789',
|
|
148
|
+
businessAccountId: 'waba-id',
|
|
149
|
+
hasAccessToken: true,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
153
|
+
const result = await whatsapp.configureDriver('tenant-123', {
|
|
154
|
+
driver: 'cloud-api',
|
|
155
|
+
cloudApi: {
|
|
156
|
+
phoneNumberId: '123456789',
|
|
157
|
+
accessToken: 'EAAG...',
|
|
158
|
+
businessAccountId: 'waba-id',
|
|
159
|
+
webhookVerifyToken: 'my-verify-token',
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/tenant-123/driver/default', {
|
|
163
|
+
driver: 'cloud-api',
|
|
164
|
+
cloudApi: {
|
|
165
|
+
phoneNumberId: '123456789',
|
|
166
|
+
accessToken: 'EAAG...',
|
|
167
|
+
businessAccountId: 'waba-id',
|
|
168
|
+
webhookVerifyToken: 'my-verify-token',
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
172
|
+
});
|
|
173
|
+
(0, vitest_1.it)('should configure driver with custom deviceId', async () => {
|
|
174
|
+
const mockResponse = {
|
|
175
|
+
tenantId: 'tenant-123',
|
|
176
|
+
deviceId: 'custom-device',
|
|
177
|
+
driver: 'baileys',
|
|
178
|
+
configured: true,
|
|
179
|
+
};
|
|
180
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
181
|
+
const result = await whatsapp.configureDriver('tenant-123', { driver: 'baileys' }, 'custom-device');
|
|
182
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/tenant-123/driver/custom-device', {
|
|
183
|
+
driver: 'baileys',
|
|
184
|
+
});
|
|
185
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
186
|
+
});
|
|
187
|
+
(0, vitest_1.it)('should get driver configuration', async () => {
|
|
188
|
+
const mockResponse = {
|
|
189
|
+
tenantId: 'tenant-123',
|
|
190
|
+
deviceId: 'default',
|
|
191
|
+
driver: 'cloud-api',
|
|
192
|
+
configured: true,
|
|
193
|
+
cloudApi: {
|
|
194
|
+
phoneNumberId: '123456789',
|
|
195
|
+
businessAccountId: 'waba-id',
|
|
196
|
+
hasAccessToken: true,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
200
|
+
const result = await whatsapp.getDriverConfig('tenant-123');
|
|
201
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/driver/default');
|
|
202
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
203
|
+
});
|
|
204
|
+
(0, vitest_1.it)('should get driver configuration for custom deviceId', async () => {
|
|
205
|
+
const mockResponse = {
|
|
206
|
+
tenantId: 'tenant-123',
|
|
207
|
+
deviceId: 'custom-device',
|
|
208
|
+
driver: 'baileys',
|
|
209
|
+
configured: true,
|
|
210
|
+
};
|
|
211
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
212
|
+
const result = await whatsapp.getDriverConfig('tenant-123', 'custom-device');
|
|
213
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/driver/custom-device');
|
|
214
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
// ===== Messaging =====
|
|
218
|
+
(0, vitest_1.describe)('Messaging', () => {
|
|
219
|
+
(0, vitest_1.it)('should send text message', async () => {
|
|
220
|
+
const mockResponse = { enqueued: true, correlationId: 'msg-123' };
|
|
221
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
222
|
+
const result = await whatsapp.sendMessage({
|
|
223
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
224
|
+
text: 'Hello World',
|
|
225
|
+
});
|
|
226
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/send', {
|
|
227
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
228
|
+
text: 'Hello World',
|
|
229
|
+
});
|
|
230
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
231
|
+
});
|
|
232
|
+
(0, vitest_1.it)('should send reaction', async () => {
|
|
233
|
+
const mockResponse = { enqueued: true, correlationId: 'react-123' };
|
|
234
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
235
|
+
const result = await whatsapp.sendReaction({
|
|
236
|
+
key: {
|
|
237
|
+
id: 'msg-id-123',
|
|
238
|
+
remoteJid: '5511999999999@s.whatsapp.net',
|
|
239
|
+
fromMe: false,
|
|
240
|
+
},
|
|
241
|
+
emoji: '👍',
|
|
242
|
+
});
|
|
243
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/reaction', {
|
|
244
|
+
key: {
|
|
245
|
+
id: 'msg-id-123',
|
|
246
|
+
remoteJid: '5511999999999@s.whatsapp.net',
|
|
247
|
+
fromMe: false,
|
|
248
|
+
},
|
|
249
|
+
emoji: '👍',
|
|
250
|
+
});
|
|
251
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
252
|
+
});
|
|
253
|
+
(0, vitest_1.it)('should send media with URL', async () => {
|
|
254
|
+
const mockResponse = { enqueued: true, correlationId: 'media-123' };
|
|
255
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
256
|
+
const result = await whatsapp.sendMedia({
|
|
257
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
258
|
+
type: 'image',
|
|
259
|
+
url: 'https://example.com/image.jpg',
|
|
260
|
+
caption: 'Check this out!',
|
|
261
|
+
});
|
|
262
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/media', {
|
|
263
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
264
|
+
type: 'image',
|
|
265
|
+
url: 'https://example.com/image.jpg',
|
|
266
|
+
caption: 'Check this out!',
|
|
267
|
+
});
|
|
268
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
269
|
+
});
|
|
270
|
+
(0, vitest_1.it)('should send media with base64', async () => {
|
|
271
|
+
const mockResponse = { enqueued: true, correlationId: 'media-456' };
|
|
272
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
273
|
+
const result = await whatsapp.sendMedia({
|
|
274
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
275
|
+
type: 'document',
|
|
276
|
+
base64: 'base64-encoded-content',
|
|
277
|
+
mimetype: 'application/pdf',
|
|
278
|
+
filename: 'document.pdf',
|
|
279
|
+
});
|
|
280
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/media', {
|
|
281
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
282
|
+
type: 'document',
|
|
283
|
+
base64: 'base64-encoded-content',
|
|
284
|
+
mimetype: 'application/pdf',
|
|
285
|
+
filename: 'document.pdf',
|
|
286
|
+
});
|
|
287
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
// ===== Cloud API Features =====
|
|
291
|
+
(0, vitest_1.describe)('Cloud API Features', () => {
|
|
292
|
+
(0, vitest_1.it)('should send template message', async () => {
|
|
293
|
+
const mockResponse = { enqueued: true, correlationId: 'template-123' };
|
|
294
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
295
|
+
const result = await whatsapp.sendTemplate({
|
|
296
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
297
|
+
templateName: 'hello_world',
|
|
298
|
+
languageCode: 'pt_BR',
|
|
299
|
+
components: [
|
|
300
|
+
{
|
|
301
|
+
type: 'body',
|
|
302
|
+
parameters: [{ type: 'text', text: 'João' }],
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
});
|
|
306
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/template', {
|
|
307
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
308
|
+
templateName: 'hello_world',
|
|
309
|
+
languageCode: 'pt_BR',
|
|
310
|
+
components: [
|
|
311
|
+
{
|
|
312
|
+
type: 'body',
|
|
313
|
+
parameters: [{ type: 'text', text: 'João' }],
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
});
|
|
317
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
318
|
+
});
|
|
319
|
+
(0, vitest_1.it)('should send template with header image', async () => {
|
|
320
|
+
const mockResponse = { enqueued: true, correlationId: 'template-456' };
|
|
321
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
322
|
+
const result = await whatsapp.sendTemplate({
|
|
323
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
324
|
+
templateName: 'order_confirmation',
|
|
325
|
+
languageCode: 'en',
|
|
326
|
+
components: [
|
|
327
|
+
{
|
|
328
|
+
type: 'header',
|
|
329
|
+
parameters: [{ type: 'image', image: { link: 'https://example.com/image.jpg' } }],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
type: 'body',
|
|
333
|
+
parameters: [
|
|
334
|
+
{ type: 'text', text: 'Order #12345' },
|
|
335
|
+
{ type: 'currency', currency: { fallback_value: '$10.00', code: 'USD', amount_1000: 10000 } },
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
});
|
|
340
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/template', vitest_1.expect.objectContaining({
|
|
341
|
+
templateName: 'order_confirmation',
|
|
342
|
+
}));
|
|
343
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
344
|
+
});
|
|
345
|
+
(0, vitest_1.it)('should get templates list', async () => {
|
|
346
|
+
const mockResponse = {
|
|
347
|
+
templates: [
|
|
348
|
+
{
|
|
349
|
+
id: 'tmpl-1',
|
|
350
|
+
name: 'hello_world',
|
|
351
|
+
status: 'APPROVED',
|
|
352
|
+
category: 'UTILITY',
|
|
353
|
+
language: 'pt_BR',
|
|
354
|
+
components: [{ type: 'BODY', text: 'Hello {{1}}!' }],
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
id: 'tmpl-2',
|
|
358
|
+
name: 'order_update',
|
|
359
|
+
status: 'APPROVED',
|
|
360
|
+
category: 'UTILITY',
|
|
361
|
+
language: 'en',
|
|
362
|
+
components: [{ type: 'BODY', text: 'Your order {{1}} has been shipped.' }],
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
paging: {
|
|
366
|
+
cursors: { after: 'cursor-123' },
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
370
|
+
const result = await whatsapp.getTemplates('tenant-123');
|
|
371
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/templates?deviceId=default');
|
|
372
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
373
|
+
(0, vitest_1.expect)(result.templates).toHaveLength(2);
|
|
374
|
+
});
|
|
375
|
+
(0, vitest_1.it)('should get templates for specific device', async () => {
|
|
376
|
+
const mockResponse = { templates: [], paging: {} };
|
|
377
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
378
|
+
await whatsapp.getTemplates('tenant-123', 'device-456');
|
|
379
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/tenant-123/templates?deviceId=device-456');
|
|
380
|
+
});
|
|
381
|
+
(0, vitest_1.it)('should send interactive button message', async () => {
|
|
382
|
+
const mockResponse = { enqueued: true, correlationId: 'interactive-123' };
|
|
383
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
384
|
+
const result = await whatsapp.sendInteractive({
|
|
385
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
386
|
+
type: 'button',
|
|
387
|
+
body: { text: 'Choose an option:' },
|
|
388
|
+
action: {
|
|
389
|
+
buttons: [
|
|
390
|
+
{ type: 'reply', reply: { id: 'opt1', title: 'Option 1' } },
|
|
391
|
+
{ type: 'reply', reply: { id: 'opt2', title: 'Option 2' } },
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/interactive', {
|
|
396
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
397
|
+
type: 'button',
|
|
398
|
+
body: { text: 'Choose an option:' },
|
|
399
|
+
action: {
|
|
400
|
+
buttons: [
|
|
401
|
+
{ type: 'reply', reply: { id: 'opt1', title: 'Option 1' } },
|
|
402
|
+
{ type: 'reply', reply: { id: 'opt2', title: 'Option 2' } },
|
|
403
|
+
],
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
407
|
+
});
|
|
408
|
+
(0, vitest_1.it)('should send interactive list message', async () => {
|
|
409
|
+
const mockResponse = { enqueued: true, correlationId: 'interactive-456' };
|
|
410
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
411
|
+
const result = await whatsapp.sendInteractive({
|
|
412
|
+
jid: '5511999999999@s.whatsapp.net',
|
|
413
|
+
type: 'list',
|
|
414
|
+
header: { type: 'text', text: 'Our Menu' },
|
|
415
|
+
body: { text: 'Select from the options below:' },
|
|
416
|
+
footer: { text: 'Powered by Catalisa' },
|
|
417
|
+
action: {
|
|
418
|
+
button: 'View Menu',
|
|
419
|
+
sections: [
|
|
420
|
+
{
|
|
421
|
+
title: 'Drinks',
|
|
422
|
+
rows: [
|
|
423
|
+
{ id: 'coffee', title: 'Coffee', description: 'Fresh brewed' },
|
|
424
|
+
{ id: 'tea', title: 'Tea', description: 'Assorted flavors' },
|
|
425
|
+
],
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
title: 'Snacks',
|
|
429
|
+
rows: [
|
|
430
|
+
{ id: 'cookie', title: 'Cookie', description: 'Chocolate chip' },
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/interactive', vitest_1.expect.objectContaining({
|
|
437
|
+
type: 'list',
|
|
438
|
+
action: vitest_1.expect.objectContaining({
|
|
439
|
+
button: 'View Menu',
|
|
440
|
+
sections: vitest_1.expect.arrayContaining([
|
|
441
|
+
vitest_1.expect.objectContaining({ title: 'Drinks' }),
|
|
442
|
+
]),
|
|
443
|
+
}),
|
|
444
|
+
}));
|
|
445
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
// ===== Cloud API Receiver =====
|
|
449
|
+
(0, vitest_1.describe)('Cloud API Receiver', () => {
|
|
450
|
+
(0, vitest_1.it)('should get Cloud API receiver status', async () => {
|
|
451
|
+
const mockResponse = {
|
|
452
|
+
tenantId: 'tenant-123',
|
|
453
|
+
deviceId: 'default',
|
|
454
|
+
driver: 'cloud-api',
|
|
455
|
+
configured: true,
|
|
456
|
+
cloudApi: {
|
|
457
|
+
phoneNumberId: '123456789',
|
|
458
|
+
businessAccountId: 'waba-id',
|
|
459
|
+
hasAccessToken: true,
|
|
460
|
+
hasWebhookToken: true,
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
464
|
+
const result = await whatsapp.getCloudApiReceiverStatus('tenant-123');
|
|
465
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/cloud-api/receiver/tenant-123/default/status');
|
|
466
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
467
|
+
});
|
|
468
|
+
(0, vitest_1.it)('should get Cloud API receiver status for custom device', async () => {
|
|
469
|
+
const mockResponse = {
|
|
470
|
+
tenantId: 'tenant-123',
|
|
471
|
+
deviceId: 'device-456',
|
|
472
|
+
driver: 'cloud-api',
|
|
473
|
+
configured: true,
|
|
474
|
+
cloudApi: {
|
|
475
|
+
phoneNumberId: '123456789',
|
|
476
|
+
businessAccountId: 'waba-id',
|
|
477
|
+
hasAccessToken: true,
|
|
478
|
+
hasWebhookToken: true,
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
482
|
+
const result = await whatsapp.getCloudApiReceiverStatus('tenant-123', 'device-456');
|
|
483
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/cloud-api/receiver/tenant-123/device-456/status');
|
|
484
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
485
|
+
});
|
|
486
|
+
(0, vitest_1.it)('should get Cloud API receiver status for unconfigured device', async () => {
|
|
487
|
+
const mockResponse = {
|
|
488
|
+
tenantId: 'tenant-123',
|
|
489
|
+
deviceId: 'default',
|
|
490
|
+
driver: 'baileys',
|
|
491
|
+
configured: false,
|
|
492
|
+
cloudApi: null,
|
|
493
|
+
};
|
|
494
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
495
|
+
const result = await whatsapp.getCloudApiReceiverStatus('tenant-123');
|
|
496
|
+
(0, vitest_1.expect)(result.configured).toBe(false);
|
|
497
|
+
(0, vitest_1.expect)(result.cloudApi).toBeNull();
|
|
498
|
+
});
|
|
499
|
+
(0, vitest_1.it)('should get Cloud API webhook URL using default base URL', async () => {
|
|
500
|
+
const mockStatusResponse = {
|
|
501
|
+
tenantId: 'tenant-123',
|
|
502
|
+
deviceId: 'default',
|
|
503
|
+
driver: 'cloud-api',
|
|
504
|
+
configured: true,
|
|
505
|
+
cloudApi: {
|
|
506
|
+
phoneNumberId: '123456789',
|
|
507
|
+
businessAccountId: 'waba-id',
|
|
508
|
+
hasAccessToken: true,
|
|
509
|
+
hasWebhookToken: true,
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
mockHttp.get.mockResolvedValue(mockStatusResponse);
|
|
513
|
+
const result = await whatsapp.getCloudApiWebhookUrl('tenant-123');
|
|
514
|
+
(0, vitest_1.expect)(mockHttp.getBaseURL).toHaveBeenCalled();
|
|
515
|
+
(0, vitest_1.expect)(result.webhookUrl).toBe('https://api.example.com/wpp/cloud-api/receiver/tenant-123/default');
|
|
516
|
+
(0, vitest_1.expect)(result.tenantId).toBe('tenant-123');
|
|
517
|
+
(0, vitest_1.expect)(result.deviceId).toBe('default');
|
|
518
|
+
});
|
|
519
|
+
(0, vitest_1.it)('should get Cloud API webhook URL with custom base URL', async () => {
|
|
520
|
+
const mockStatusResponse = {
|
|
521
|
+
tenantId: 'tenant-123',
|
|
522
|
+
deviceId: 'device-456',
|
|
523
|
+
driver: 'cloud-api',
|
|
524
|
+
configured: true,
|
|
525
|
+
cloudApi: {
|
|
526
|
+
phoneNumberId: '123456789',
|
|
527
|
+
businessAccountId: 'waba-id',
|
|
528
|
+
hasAccessToken: true,
|
|
529
|
+
hasWebhookToken: true,
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
mockHttp.get.mockResolvedValue(mockStatusResponse);
|
|
533
|
+
const result = await whatsapp.getCloudApiWebhookUrl('tenant-123', 'device-456', 'https://custom-api.example.com');
|
|
534
|
+
(0, vitest_1.expect)(result.webhookUrl).toBe('https://custom-api.example.com/wpp/cloud-api/receiver/tenant-123/device-456');
|
|
535
|
+
(0, vitest_1.expect)(result.deviceId).toBe('device-456');
|
|
536
|
+
});
|
|
537
|
+
(0, vitest_1.it)('should indicate when webhook token is not configured', async () => {
|
|
538
|
+
const mockStatusResponse = {
|
|
539
|
+
tenantId: 'tenant-123',
|
|
540
|
+
deviceId: 'default',
|
|
541
|
+
driver: 'cloud-api',
|
|
542
|
+
configured: true,
|
|
543
|
+
cloudApi: {
|
|
544
|
+
phoneNumberId: '123456789',
|
|
545
|
+
businessAccountId: 'waba-id',
|
|
546
|
+
hasAccessToken: true,
|
|
547
|
+
hasWebhookToken: false,
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
mockHttp.get.mockResolvedValue(mockStatusResponse);
|
|
551
|
+
const result = await whatsapp.getCloudApiWebhookUrl('tenant-123');
|
|
552
|
+
(0, vitest_1.expect)(result.verifyToken).toBe('(not configured)');
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
// ===== Group Management =====
|
|
556
|
+
(0, vitest_1.describe)('Group Management', () => {
|
|
557
|
+
(0, vitest_1.it)('should create group', async () => {
|
|
558
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-123' };
|
|
559
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
560
|
+
const result = await whatsapp.createGroup({
|
|
561
|
+
subject: 'Test Group',
|
|
562
|
+
participants: ['5511999999999@s.whatsapp.net'],
|
|
563
|
+
});
|
|
564
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/create', {
|
|
565
|
+
subject: 'Test Group',
|
|
566
|
+
participants: ['5511999999999@s.whatsapp.net'],
|
|
567
|
+
});
|
|
568
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
569
|
+
});
|
|
570
|
+
(0, vitest_1.it)('should update group subject', async () => {
|
|
571
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-subj-123' };
|
|
572
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
573
|
+
const result = await whatsapp.updateGroupSubject({
|
|
574
|
+
gid: '123456789@g.us',
|
|
575
|
+
subject: 'New Group Name',
|
|
576
|
+
});
|
|
577
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/subject', {
|
|
578
|
+
gid: '123456789@g.us',
|
|
579
|
+
subject: 'New Group Name',
|
|
580
|
+
});
|
|
581
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
582
|
+
});
|
|
583
|
+
(0, vitest_1.it)('should update group description', async () => {
|
|
584
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-desc-123' };
|
|
585
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
586
|
+
const result = await whatsapp.updateGroupDescription({
|
|
587
|
+
gid: '123456789@g.us',
|
|
588
|
+
description: 'This is a test group',
|
|
589
|
+
});
|
|
590
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/description', {
|
|
591
|
+
gid: '123456789@g.us',
|
|
592
|
+
description: 'This is a test group',
|
|
593
|
+
});
|
|
594
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
595
|
+
});
|
|
596
|
+
(0, vitest_1.it)('should add participants', async () => {
|
|
597
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-add-123' };
|
|
598
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
599
|
+
const result = await whatsapp.addGroupParticipants({
|
|
600
|
+
gid: '123456789@g.us',
|
|
601
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
602
|
+
});
|
|
603
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/add', {
|
|
604
|
+
gid: '123456789@g.us',
|
|
605
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
606
|
+
});
|
|
607
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
608
|
+
});
|
|
609
|
+
(0, vitest_1.it)('should remove participants', async () => {
|
|
610
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-rm-123' };
|
|
611
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
612
|
+
const result = await whatsapp.removeGroupParticipants({
|
|
613
|
+
gid: '123456789@g.us',
|
|
614
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
615
|
+
});
|
|
616
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/remove', {
|
|
617
|
+
gid: '123456789@g.us',
|
|
618
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
619
|
+
});
|
|
620
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
621
|
+
});
|
|
622
|
+
(0, vitest_1.it)('should promote participants', async () => {
|
|
623
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-promo-123' };
|
|
624
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
625
|
+
const result = await whatsapp.promoteGroupParticipants({
|
|
626
|
+
gid: '123456789@g.us',
|
|
627
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
628
|
+
});
|
|
629
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/promote', {
|
|
630
|
+
gid: '123456789@g.us',
|
|
631
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
632
|
+
});
|
|
633
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
634
|
+
});
|
|
635
|
+
(0, vitest_1.it)('should demote participants', async () => {
|
|
636
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-demo-123' };
|
|
637
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
638
|
+
const result = await whatsapp.demoteGroupParticipants({
|
|
639
|
+
gid: '123456789@g.us',
|
|
640
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
641
|
+
});
|
|
642
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/demote', {
|
|
643
|
+
gid: '123456789@g.us',
|
|
644
|
+
participants: ['5511888888888@s.whatsapp.net'],
|
|
645
|
+
});
|
|
646
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
647
|
+
});
|
|
648
|
+
(0, vitest_1.it)('should leave group', async () => {
|
|
649
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-leave-123' };
|
|
650
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
651
|
+
const result = await whatsapp.leaveGroup({
|
|
652
|
+
gid: '123456789@g.us',
|
|
653
|
+
});
|
|
654
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/leave', {
|
|
655
|
+
gid: '123456789@g.us',
|
|
656
|
+
});
|
|
657
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
658
|
+
});
|
|
659
|
+
(0, vitest_1.it)('should delete group', async () => {
|
|
660
|
+
const mockResponse = { enqueued: true, correlationId: 'grp-del-123' };
|
|
661
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
662
|
+
const result = await whatsapp.deleteGroup({
|
|
663
|
+
gid: '123456789@g.us',
|
|
664
|
+
removeAll: true,
|
|
665
|
+
});
|
|
666
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/group/delete', {
|
|
667
|
+
gid: '123456789@g.us',
|
|
668
|
+
removeAll: true,
|
|
669
|
+
});
|
|
670
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
// ===== Query Endpoints =====
|
|
674
|
+
(0, vitest_1.describe)('Query Endpoints', () => {
|
|
675
|
+
(0, vitest_1.it)('should list groups', async () => {
|
|
676
|
+
const mockGroups = [
|
|
677
|
+
{ gid: '123@g.us', subject: 'Group 1' },
|
|
678
|
+
{ gid: '456@g.us', subject: 'Group 2' },
|
|
679
|
+
];
|
|
680
|
+
mockHttp.get.mockResolvedValue(mockGroups);
|
|
681
|
+
const result = await whatsapp.listGroups('tenant-123');
|
|
682
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/groups?tenantId=tenant-123&force=false');
|
|
683
|
+
(0, vitest_1.expect)(result).toEqual(mockGroups);
|
|
684
|
+
});
|
|
685
|
+
(0, vitest_1.it)('should list groups with force refresh', async () => {
|
|
686
|
+
mockHttp.get.mockResolvedValue([]);
|
|
687
|
+
await whatsapp.listGroups('tenant-123', true);
|
|
688
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/groups?tenantId=tenant-123&force=true');
|
|
689
|
+
});
|
|
690
|
+
(0, vitest_1.it)('should list chats', async () => {
|
|
691
|
+
const mockChats = [
|
|
692
|
+
{ jid: '5511999999999@s.whatsapp.net', name: 'Contact 1' },
|
|
693
|
+
];
|
|
694
|
+
mockHttp.get.mockResolvedValue(mockChats);
|
|
695
|
+
const result = await whatsapp.listChats('tenant-123');
|
|
696
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/chats?tenantId=tenant-123&force=false');
|
|
697
|
+
(0, vitest_1.expect)(result).toEqual(mockChats);
|
|
698
|
+
});
|
|
699
|
+
(0, vitest_1.it)('should list contacts', async () => {
|
|
700
|
+
const mockContacts = [
|
|
701
|
+
{ jid: '5511999999999@s.whatsapp.net', name: 'John' },
|
|
702
|
+
];
|
|
703
|
+
mockHttp.get.mockResolvedValue(mockContacts);
|
|
704
|
+
const result = await whatsapp.listContacts('tenant-123');
|
|
705
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/contacts?tenantId=tenant-123&force=false');
|
|
706
|
+
(0, vitest_1.expect)(result).toEqual(mockContacts);
|
|
707
|
+
});
|
|
708
|
+
(0, vitest_1.it)('should get operation result', async () => {
|
|
709
|
+
const mockOperation = {
|
|
710
|
+
correlationId: 'corr-123',
|
|
711
|
+
status: 'completed',
|
|
712
|
+
result: { messageId: 'msg-id' },
|
|
713
|
+
};
|
|
714
|
+
mockHttp.get.mockResolvedValue(mockOperation);
|
|
715
|
+
const result = await whatsapp.getOperation('corr-123');
|
|
716
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/operation/corr-123');
|
|
717
|
+
(0, vitest_1.expect)(result).toEqual(mockOperation);
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
// ===== QR Link Support =====
|
|
721
|
+
(0, vitest_1.describe)('QR Link Support', () => {
|
|
722
|
+
(0, vitest_1.it)('should generate QR link', async () => {
|
|
723
|
+
const mockResponse = {
|
|
724
|
+
token: 'abc123',
|
|
725
|
+
url: 'https://example.com/qr/abc123',
|
|
726
|
+
expiresAt: '2024-01-02T00:00:00Z',
|
|
727
|
+
};
|
|
728
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
729
|
+
const result = await whatsapp.generateQRLink({
|
|
730
|
+
tenantId: 'tenant-123',
|
|
731
|
+
expirationHours: 24,
|
|
732
|
+
});
|
|
733
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/generate-qr-link', {
|
|
734
|
+
tenantId: 'tenant-123',
|
|
735
|
+
expirationHours: 24,
|
|
736
|
+
});
|
|
737
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
738
|
+
});
|
|
739
|
+
(0, vitest_1.it)('should send QR link', async () => {
|
|
740
|
+
const mockResponse = { enqueued: true, correlationId: 'qrlink-123' };
|
|
741
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
742
|
+
const result = await whatsapp.sendQRLink({
|
|
743
|
+
senderTenantId: 'tenant-1',
|
|
744
|
+
recipientTenantId: 'tenant-2',
|
|
745
|
+
recipientJid: '5511999999999@s.whatsapp.net',
|
|
746
|
+
});
|
|
747
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/send-qr-link', {
|
|
748
|
+
senderTenantId: 'tenant-1',
|
|
749
|
+
recipientTenantId: 'tenant-2',
|
|
750
|
+
recipientJid: '5511999999999@s.whatsapp.net',
|
|
751
|
+
});
|
|
752
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
753
|
+
});
|
|
754
|
+
(0, vitest_1.it)('should get public QR', async () => {
|
|
755
|
+
const mockResponse = {
|
|
756
|
+
qr: 'base64-qr',
|
|
757
|
+
status: 'qr',
|
|
758
|
+
tenant: { name: 'Test Tenant' },
|
|
759
|
+
expiresAt: '2024-01-02T00:00:00Z',
|
|
760
|
+
};
|
|
761
|
+
mockHttp.get.mockResolvedValue(mockResponse);
|
|
762
|
+
const result = await whatsapp.getPublicQR('token-abc');
|
|
763
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/wpp/public/qr/token-abc');
|
|
764
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
765
|
+
});
|
|
766
|
+
(0, vitest_1.it)('should regenerate public QR', async () => {
|
|
767
|
+
const mockResponse = {
|
|
768
|
+
qr: 'new-base64-qr',
|
|
769
|
+
status: 'qr',
|
|
770
|
+
tenant: { name: 'Test Tenant' },
|
|
771
|
+
expiresAt: '2024-01-02T00:00:00Z',
|
|
772
|
+
};
|
|
773
|
+
mockHttp.post.mockResolvedValue(mockResponse);
|
|
774
|
+
const result = await whatsapp.regeneratePublicQR('token-abc');
|
|
775
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/wpp/public/qr/token-abc/regenerate');
|
|
776
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
//# sourceMappingURL=whatsapp.test.js.map
|