@kyyinfinite/zapo-message 0.0.0-stage → 1.0.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/CHANGELOG.md +159 -0
- package/LICENSE +20 -0
- package/README.md +532 -2
- package/build.config.json +28 -0
- package/dist/airich/airich.d.ts +180 -0
- package/dist/airich/airich.js +548 -0
- package/dist/airich/context.d.ts +24 -0
- package/dist/airich/context.js +48 -0
- package/dist/airich/encode.d.ts +3 -0
- package/dist/airich/encode.js +16 -0
- package/dist/airich/index.d.ts +20 -0
- package/dist/airich/index.js +11 -0
- package/dist/airich/inline.d.ts +45 -0
- package/dist/airich/inline.js +152 -0
- package/dist/airich/nodes.d.ts +30 -0
- package/dist/airich/nodes.js +121 -0
- package/dist/airich/primitives.d.ts +144 -0
- package/dist/airich/primitives.js +230 -0
- package/dist/airich/protocol.d.ts +35 -0
- package/dist/airich/protocol.js +65 -0
- package/dist/airich/table.d.ts +22 -0
- package/dist/airich/table.js +35 -0
- package/dist/airich/tokenizer.d.ts +13 -0
- package/dist/airich/tokenizer.js +717 -0
- package/dist/airich/transport.d.ts +15 -0
- package/dist/airich/transport.js +56 -0
- package/dist/branding.d.ts +5 -0
- package/dist/branding.js +9 -0
- package/dist/btn/builders.d.ts +246 -0
- package/dist/btn/builders.js +710 -0
- package/dist/btn/media-slot.d.ts +28 -0
- package/dist/btn/media-slot.js +323 -0
- package/dist/btn/media-source.d.ts +38 -0
- package/dist/btn/media-source.js +116 -0
- package/dist/btn/sharp-loader.d.ts +5 -0
- package/dist/btn/sharp-loader.js +18 -0
- package/dist/btn/thumbnail.d.ts +21 -0
- package/dist/btn/thumbnail.js +124 -0
- package/dist/btn/validators.d.ts +40 -0
- package/dist/btn/validators.js +135 -0
- package/dist/btn.d.ts +1 -0
- package/dist/btn.js +1 -0
- package/dist/core/async-send.d.ts +20 -0
- package/dist/core/async-send.js +1 -0
- package/dist/core/base-builder.d.ts +20 -0
- package/dist/core/base-builder.js +67 -0
- package/dist/core/errors.d.ts +30 -0
- package/dist/core/errors.js +61 -0
- package/dist/download.d.ts +24 -0
- package/dist/download.js +123 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +22 -0
- package/dist/integration/augment.d.ts +97 -0
- package/dist/integration/augment.js +1 -0
- package/dist/integration/auto.d.ts +8 -0
- package/dist/integration/auto.js +79 -0
- package/dist/integration/index.d.ts +4 -0
- package/dist/integration/index.js +2 -0
- package/dist/integration/methods.d.ts +25 -0
- package/dist/integration/methods.js +24 -0
- package/dist/interactive.d.ts +24 -0
- package/dist/interactive.js +121 -0
- package/dist/media-gate.d.ts +99 -0
- package/dist/media-gate.js +322 -0
- package/dist/message/album.d.ts +33 -0
- package/dist/message/album.js +107 -0
- package/dist/message/contact.d.ts +29 -0
- package/dist/message/contact.js +123 -0
- package/dist/message/forward.d.ts +23 -0
- package/dist/message/forward.js +77 -0
- package/dist/message/index.d.ts +26 -0
- package/dist/message/index.js +13 -0
- package/dist/message/link-preview.d.ts +28 -0
- package/dist/message/link-preview.js +98 -0
- package/dist/message/location.d.ts +24 -0
- package/dist/message/location.js +94 -0
- package/dist/message/media.d.ts +90 -0
- package/dist/message/media.js +123 -0
- package/dist/message/poll.d.ts +24 -0
- package/dist/message/poll.js +98 -0
- package/dist/message/reaction.d.ts +20 -0
- package/dist/message/reaction.js +71 -0
- package/dist/message/sticker.d.ts +29 -0
- package/dist/message/sticker.js +44 -0
- package/dist/message/target.d.ts +18 -0
- package/dist/message/target.js +24 -0
- package/dist/message/text.d.ts +17 -0
- package/dist/message/text.js +29 -0
- package/dist/message/vcard.d.ts +9 -0
- package/dist/message/vcard.js +23 -0
- package/dist/message/webp.d.ts +6 -0
- package/dist/message/webp.js +57 -0
- package/dist/payloads.d.ts +180 -0
- package/dist/payloads.js +1 -0
- package/dist/serialize.d.ts +41 -0
- package/dist/serialize.js +93 -0
- package/dist/status.d.ts +3 -0
- package/dist/status.js +21 -0
- package/dist/zapo-client.d.ts +44 -0
- package/dist/zapo-client.js +1 -0
- package/examples/airich.ts +59 -0
- package/examples/buttons.ts +48 -0
- package/examples/client-methods.ts +58 -0
- package/examples/hybrid.ts +133 -0
- package/examples/serialize.ts +61 -0
- package/package.json +271 -4
- package/scripts/check-no-comments.mjs +101 -0
- package/scripts/compare-golden.mjs +461 -0
- package/scripts/lib-config.mjs +9 -0
- package/scripts/smoke-auto.mjs +75 -0
- package/scripts/test-external-consumer.mjs +316 -0
- package/scripts/verify-package.mjs +78 -0
- package/src/airich/airich.ts +970 -0
- package/src/airich/context.ts +96 -0
- package/src/airich/encode.ts +25 -0
- package/src/airich/index.ts +98 -0
- package/src/airich/inline.ts +272 -0
- package/src/airich/nodes.ts +174 -0
- package/src/airich/primitives.ts +474 -0
- package/src/airich/protocol.ts +133 -0
- package/src/airich/table.ts +70 -0
- package/src/airich/tokenizer.ts +799 -0
- package/src/airich/transport.ts +106 -0
- package/src/branding.ts +23 -0
- package/src/btn/builders.ts +1073 -0
- package/src/btn/media-slot.ts +486 -0
- package/src/btn/media-source.ts +189 -0
- package/src/btn/sharp-loader.ts +23 -0
- package/src/btn/thumbnail.ts +182 -0
- package/src/btn/validators.ts +237 -0
- package/src/btn.ts +8 -0
- package/src/core/async-send.ts +28 -0
- package/src/core/base-builder.ts +104 -0
- package/src/core/errors.ts +82 -0
- package/src/download.ts +212 -0
- package/src/index.ts +229 -0
- package/src/integration/augment.ts +262 -0
- package/src/integration/auto.ts +103 -0
- package/src/integration/index.ts +8 -0
- package/src/integration/methods.ts +45 -0
- package/src/interactive.ts +188 -0
- package/src/media-gate.ts +499 -0
- package/src/message/album.ts +187 -0
- package/src/message/contact.ts +170 -0
- package/src/message/forward.ts +123 -0
- package/src/message/index.ts +83 -0
- package/src/message/link-preview.ts +148 -0
- package/src/message/location.ts +150 -0
- package/src/message/media.ts +323 -0
- package/src/message/poll.ts +158 -0
- package/src/message/reaction.ts +133 -0
- package/src/message/sticker.ts +100 -0
- package/src/message/target.ts +38 -0
- package/src/message/text.ts +61 -0
- package/src/message/vcard.ts +36 -0
- package/src/message/webp.ts +78 -0
- package/src/payloads.ts +204 -0
- package/src/serialize.ts +180 -0
- package/src/status.ts +29 -0
- package/src/zapo-client.ts +84 -0
- package/test/airich-inline.test.ts +200 -0
- package/test/airich-primitives.test.ts +226 -0
- package/test/airich-tokenizer.test.ts +145 -0
- package/test/airich.golden.test.ts +406 -0
- package/test/airich.test.ts +1006 -0
- package/test/btn-button.test.ts +416 -0
- package/test/btn-header.test.ts +646 -0
- package/test/btn-legacy.test.ts +342 -0
- package/test/btn-lifecycle.test.ts +295 -0
- package/test/btn-list.test.ts +261 -0
- package/test/btn-media-source.test.ts +150 -0
- package/test/btn-thumbnail.test.ts +160 -0
- package/test/builder-compat.test.ts +264 -0
- package/test/helpers.ts +27 -0
- package/test/hybrid-airich.test.ts +345 -0
- package/test/hybrid-client.test.ts +239 -0
- package/test/hybrid-errors.test.ts +557 -0
- package/test/hybrid-interactive.test.ts +455 -0
- package/test/hybrid.golden.test.ts +349 -0
- package/test/hybrid.test.ts +479 -0
- package/test/integration-auto.test.ts +159 -0
- package/test/integration.fakeserver.test.ts +440 -0
- package/test/media-gate.test.ts +215 -0
- package/test/message-album.test.ts +145 -0
- package/test/message-builders.test.ts +401 -0
- package/test/message-media.test.ts +303 -0
- package/test/message.fakeserver.test.ts +284 -0
- package/test/message.golden.test.ts +254 -0
- package/test/serializer.test.ts +448 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import sharp from "sharp";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
text,
|
|
7
|
+
linkPreview,
|
|
8
|
+
reaction,
|
|
9
|
+
contact,
|
|
10
|
+
poll,
|
|
11
|
+
media,
|
|
12
|
+
sticker,
|
|
13
|
+
album,
|
|
14
|
+
location,
|
|
15
|
+
button,
|
|
16
|
+
legacyButton,
|
|
17
|
+
listMessage,
|
|
18
|
+
airich,
|
|
19
|
+
MessageError,
|
|
20
|
+
ValidationError,
|
|
21
|
+
MediaError,
|
|
22
|
+
type TextConfig,
|
|
23
|
+
type PollConfig,
|
|
24
|
+
type LocationConfig,
|
|
25
|
+
type ButtonConfig,
|
|
26
|
+
type ListMessageConfig,
|
|
27
|
+
type StickerConfig,
|
|
28
|
+
} from "@kyyinfinite/zapo-message";
|
|
29
|
+
import { asClient } from "./helpers.js";
|
|
30
|
+
|
|
31
|
+
const captureClient = (sendImpl?: (to: unknown) => unknown) => {
|
|
32
|
+
const sends: { to: unknown; content: unknown; options: unknown }[] = [];
|
|
33
|
+
const uploads: { source: unknown; options: unknown }[] = [];
|
|
34
|
+
const client = asClient({
|
|
35
|
+
message: {
|
|
36
|
+
upload: async (source: unknown, options: unknown) => {
|
|
37
|
+
uploads.push({ source, options });
|
|
38
|
+
throw new Error("cdn down");
|
|
39
|
+
},
|
|
40
|
+
send: async (to: unknown, content: unknown, options: unknown) => {
|
|
41
|
+
sends.push({ to, content, options });
|
|
42
|
+
if (sendImpl) return sendImpl(to);
|
|
43
|
+
return { id: `ID-${sends.length}`, attempts: 1, ack: {} };
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return { client, sends, uploads };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const captureUploadOkClient = () => {
|
|
51
|
+
const sends: { to: unknown; content: unknown; options: unknown }[] = [];
|
|
52
|
+
const uploads: { source: unknown; options: unknown }[] = [];
|
|
53
|
+
const client = asClient({
|
|
54
|
+
message: {
|
|
55
|
+
upload: async (source: unknown, options: unknown) => {
|
|
56
|
+
uploads.push({ source, options });
|
|
57
|
+
return {
|
|
58
|
+
url: "https://mmg.whatsapp.net/v/t62.7118-24/golden",
|
|
59
|
+
directPath: "/v/t62.7118-24/golden",
|
|
60
|
+
mediaKey: new Uint8Array(32).fill(1),
|
|
61
|
+
fileSha256: new Uint8Array(32).fill(2),
|
|
62
|
+
fileEncSha256: new Uint8Array(32).fill(3),
|
|
63
|
+
fileLength: 1000,
|
|
64
|
+
mediaKeyTimestamp: 1730000000,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
send: async (to: unknown, content: unknown, options: unknown) => {
|
|
68
|
+
sends.push({ to, content, options });
|
|
69
|
+
return { id: `ID-${sends.length}`, attempts: 1, ack: {} };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return { client, sends, uploads };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const rejectsLike = async (
|
|
77
|
+
promise: Promise<unknown>,
|
|
78
|
+
label: string,
|
|
79
|
+
): Promise<MessageError> => {
|
|
80
|
+
try {
|
|
81
|
+
await promise;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
assert.ok(error instanceof MessageError, `${label}: MessageError`);
|
|
84
|
+
return error as MessageError;
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`${label}: seharusnya reject`);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const chainRejectsLike = async (
|
|
90
|
+
fn: () => Promise<unknown>,
|
|
91
|
+
label: string,
|
|
92
|
+
): Promise<MessageError> => rejectsLike(fn(), label);
|
|
93
|
+
|
|
94
|
+
const throwsLike = (fn: () => unknown, label: string): MessageError => {
|
|
95
|
+
try {
|
|
96
|
+
fn();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
assert.ok(error instanceof MessageError, `${label}: MessageError`);
|
|
99
|
+
return error as MessageError;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`${label}: seharusnya throw`);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const PNG_BYTES = await sharp({
|
|
105
|
+
create: { width: 120, height: 90, channels: 3, background: "#3060ff" },
|
|
106
|
+
})
|
|
107
|
+
.png()
|
|
108
|
+
.toBuffer();
|
|
109
|
+
|
|
110
|
+
const INCOMING = {
|
|
111
|
+
key: { remoteJid: "628111@s.whatsapp.net", id: "MSG-1", fromMe: false },
|
|
112
|
+
message: { conversation: "halo" },
|
|
113
|
+
rawNode: {},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
test("error parity: text tanpa body", async () => {
|
|
117
|
+
const { client } = captureClient();
|
|
118
|
+
const asyncError = await rejectsLike(
|
|
119
|
+
text(client, "6281@s.whatsapp.net", {} as TextConfig),
|
|
120
|
+
"async",
|
|
121
|
+
);
|
|
122
|
+
const chainError = throwsLike(
|
|
123
|
+
() => text(client).body(undefined as never),
|
|
124
|
+
"chain",
|
|
125
|
+
);
|
|
126
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
127
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
128
|
+
assert.equal(asyncError.message, chainError.message);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("error parity: tujuan tidak diketahui", async () => {
|
|
132
|
+
const { client } = captureClient();
|
|
133
|
+
const asyncError = await rejectsLike(
|
|
134
|
+
text(client, undefined as unknown as string, { body: "halo" }),
|
|
135
|
+
"async",
|
|
136
|
+
);
|
|
137
|
+
const chainError = await chainRejectsLike(
|
|
138
|
+
() => text(client).body("halo").send(),
|
|
139
|
+
"chain",
|
|
140
|
+
);
|
|
141
|
+
assert.equal(asyncError.code, "NO_TARGET");
|
|
142
|
+
assert.equal(chainError.code, "NO_TARGET");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("error parity: reaction emoji tidak valid", async () => {
|
|
146
|
+
const { client } = captureClient();
|
|
147
|
+
const asyncError = await rejectsLike(
|
|
148
|
+
reaction(client, { target: INCOMING, emoji: 5 as never }),
|
|
149
|
+
"async",
|
|
150
|
+
);
|
|
151
|
+
const chainError = throwsLike(
|
|
152
|
+
() =>
|
|
153
|
+
reaction(client)
|
|
154
|
+
.target(INCOMING)
|
|
155
|
+
.emoji(5 as never),
|
|
156
|
+
"chain",
|
|
157
|
+
);
|
|
158
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
159
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
160
|
+
assert.equal(asyncError.message, chainError.message);
|
|
161
|
+
|
|
162
|
+
const noEmoji = await chainRejectsLike(
|
|
163
|
+
() => reaction(client).target(INCOMING).send(),
|
|
164
|
+
"chain tanpa emoji",
|
|
165
|
+
);
|
|
166
|
+
assert.equal(noEmoji.code, "NO_EMOJI");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("error parity: reaction target tanpa id", async () => {
|
|
170
|
+
const { client } = captureClient();
|
|
171
|
+
const badTarget = { key: { remoteJid: "6281@s.whatsapp.net" } };
|
|
172
|
+
const asyncError = await rejectsLike(
|
|
173
|
+
reaction(client, { target: badTarget, emoji: "🔥" }),
|
|
174
|
+
"async",
|
|
175
|
+
);
|
|
176
|
+
const chainError = throwsLike(
|
|
177
|
+
() => reaction(client).target(badTarget),
|
|
178
|
+
"chain",
|
|
179
|
+
);
|
|
180
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
181
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
182
|
+
assert.equal(asyncError.message, chainError.message);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("error parity: poll konfigurasi tidak valid", async () => {
|
|
186
|
+
const { client } = captureClient();
|
|
187
|
+
const asyncError = await rejectsLike(
|
|
188
|
+
poll(client, "6281@s.whatsapp.net", {
|
|
189
|
+
question: "Q",
|
|
190
|
+
options: [],
|
|
191
|
+
} as PollConfig),
|
|
192
|
+
"async",
|
|
193
|
+
);
|
|
194
|
+
const chainError = throwsLike(
|
|
195
|
+
() => poll(client).question("Q").build(),
|
|
196
|
+
"chain",
|
|
197
|
+
);
|
|
198
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
199
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("error parity: poll selectableCount melebihi opsi", async () => {
|
|
203
|
+
const { client } = captureClient();
|
|
204
|
+
const asyncError = await rejectsLike(
|
|
205
|
+
poll(client, "6281@s.whatsapp.net", {
|
|
206
|
+
question: "Q",
|
|
207
|
+
options: ["A"],
|
|
208
|
+
selectableCount: 2,
|
|
209
|
+
}),
|
|
210
|
+
"async",
|
|
211
|
+
);
|
|
212
|
+
const chainError = throwsLike(
|
|
213
|
+
() => poll(client).question("Q").options(["A"]).selectableCount(2).build(),
|
|
214
|
+
"chain",
|
|
215
|
+
);
|
|
216
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
217
|
+
assert.equal(asyncError.message, chainError.message);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("error parity: contact tanpa nama", async () => {
|
|
221
|
+
const { client } = captureClient();
|
|
222
|
+
const asyncError = await rejectsLike(
|
|
223
|
+
contact(client, "6281@s.whatsapp.net", {}),
|
|
224
|
+
"async",
|
|
225
|
+
);
|
|
226
|
+
const chainError = throwsLike(() => contact(client).build(), "chain");
|
|
227
|
+
assert.equal(asyncError.code, "NO_NAME");
|
|
228
|
+
assert.equal(chainError.code, "NO_NAME");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("error parity: linkPreview url tidak muncul di body", async () => {
|
|
232
|
+
const { client } = captureClient();
|
|
233
|
+
const config = {
|
|
234
|
+
body: "tidak ada link di sini",
|
|
235
|
+
url: "https://example.com/docs",
|
|
236
|
+
};
|
|
237
|
+
const asyncError = await rejectsLike(
|
|
238
|
+
linkPreview(client, "6281@s.whatsapp.net", config),
|
|
239
|
+
"async",
|
|
240
|
+
);
|
|
241
|
+
const chainError = throwsLike(
|
|
242
|
+
() =>
|
|
243
|
+
linkPreview(client)
|
|
244
|
+
.body("tidak ada link di sini")
|
|
245
|
+
.url("https://example.com/docs")
|
|
246
|
+
.build(),
|
|
247
|
+
"chain",
|
|
248
|
+
);
|
|
249
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
250
|
+
assert.equal(asyncError.message, chainError.message);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("error parity: lokasi koordinat tidak valid", async () => {
|
|
254
|
+
const { client } = captureClient();
|
|
255
|
+
const asyncError = await rejectsLike(
|
|
256
|
+
location(client, "6281@s.whatsapp.net", {
|
|
257
|
+
latitude: 999,
|
|
258
|
+
longitude: 0,
|
|
259
|
+
} as LocationConfig),
|
|
260
|
+
"async",
|
|
261
|
+
);
|
|
262
|
+
const chainError = throwsLike(
|
|
263
|
+
() => location(client).coordinates(999, 0),
|
|
264
|
+
"chain",
|
|
265
|
+
);
|
|
266
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
267
|
+
assert.equal(asyncError.message, chainError.message);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("error parity: lokasi koordinat hilang di config", async () => {
|
|
271
|
+
const { client } = captureClient();
|
|
272
|
+
const asyncError = await rejectsLike(
|
|
273
|
+
location(client, "6281@s.whatsapp.net", {} as LocationConfig),
|
|
274
|
+
"async",
|
|
275
|
+
);
|
|
276
|
+
const chainError = throwsLike(
|
|
277
|
+
() => location(client).coordinates(undefined as never, undefined as never),
|
|
278
|
+
"chain",
|
|
279
|
+
);
|
|
280
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
281
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
282
|
+
assert.equal(asyncError.message, chainError.message);
|
|
283
|
+
|
|
284
|
+
const noCoordinates = await chainRejectsLike(
|
|
285
|
+
() => location(client).build(),
|
|
286
|
+
"chain tanpa koordinat",
|
|
287
|
+
);
|
|
288
|
+
assert.equal(noCoordinates.code, "NO_COORDINATES");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("error parity: media upload gagal", async () => {
|
|
292
|
+
const { client } = captureClient();
|
|
293
|
+
const asyncError = await rejectsLike(
|
|
294
|
+
media(client, "6281@s.whatsapp.net", {
|
|
295
|
+
type: "image",
|
|
296
|
+
source: PNG_BYTES,
|
|
297
|
+
}),
|
|
298
|
+
"async",
|
|
299
|
+
);
|
|
300
|
+
const chainError = await rejectsLike(
|
|
301
|
+
media(client).image(PNG_BYTES).send("6281@s.whatsapp.net"),
|
|
302
|
+
"chain",
|
|
303
|
+
);
|
|
304
|
+
assert.ok(asyncError instanceof MediaError);
|
|
305
|
+
assert.ok(chainError instanceof MediaError);
|
|
306
|
+
assert.equal(asyncError.code, chainError.code);
|
|
307
|
+
assert.equal(
|
|
308
|
+
(asyncError as MediaError & { kind?: string }).kind,
|
|
309
|
+
(chainError as MediaError & { kind?: string }).kind,
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("error parity: sticker sumber hilang di config", async () => {
|
|
314
|
+
const { client } = captureClient();
|
|
315
|
+
const asyncError = await rejectsLike(
|
|
316
|
+
sticker(client, "6281@s.whatsapp.net", {} as StickerConfig),
|
|
317
|
+
"async",
|
|
318
|
+
);
|
|
319
|
+
const chainError = await chainRejectsLike(
|
|
320
|
+
() =>
|
|
321
|
+
sticker(client)
|
|
322
|
+
.source(undefined as never)
|
|
323
|
+
.build(),
|
|
324
|
+
"chain",
|
|
325
|
+
);
|
|
326
|
+
assert.equal(asyncError.code, "MEDIA");
|
|
327
|
+
assert.equal(chainError.code, "MEDIA");
|
|
328
|
+
|
|
329
|
+
const noSource = await chainRejectsLike(
|
|
330
|
+
() => sticker(client).build(),
|
|
331
|
+
"chain tanpa sumber",
|
|
332
|
+
);
|
|
333
|
+
assert.equal(noSource.code, "NO_SOURCE");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("error parity: album kosong", async () => {
|
|
337
|
+
const { client } = captureClient();
|
|
338
|
+
const asyncError = await rejectsLike(
|
|
339
|
+
album(client, "6281@s.whatsapp.net", { media: [] }),
|
|
340
|
+
"async",
|
|
341
|
+
);
|
|
342
|
+
const chainError = throwsLike(() => album(client).build(), "chain");
|
|
343
|
+
assert.equal(asyncError.code, "NO_MEDIA");
|
|
344
|
+
assert.equal(chainError.code, "NO_MEDIA");
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test("error parity: button id duplikat", async () => {
|
|
348
|
+
const { client } = captureClient();
|
|
349
|
+
const config = {
|
|
350
|
+
body: "Pilih",
|
|
351
|
+
buttons: [
|
|
352
|
+
{ type: "quick_reply" as const, text: "A", id: "sama" },
|
|
353
|
+
{ type: "quick_reply" as const, text: "B", id: "sama" },
|
|
354
|
+
],
|
|
355
|
+
};
|
|
356
|
+
const asyncError = await rejectsLike(
|
|
357
|
+
button(client, "6281@s.whatsapp.net", config),
|
|
358
|
+
"async",
|
|
359
|
+
);
|
|
360
|
+
const chainError = throwsLike(
|
|
361
|
+
() =>
|
|
362
|
+
button(client)
|
|
363
|
+
.body("Pilih")
|
|
364
|
+
.quick_reply("A", "sama")
|
|
365
|
+
.quick_reply("B", "sama"),
|
|
366
|
+
"chain",
|
|
367
|
+
);
|
|
368
|
+
assert.equal(asyncError.code, "DUPLICATE_ID");
|
|
369
|
+
assert.equal(chainError.code, "DUPLICATE_ID");
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("error parity: button tanpa tombol", async () => {
|
|
373
|
+
const { client } = captureClient();
|
|
374
|
+
const asyncError = await rejectsLike(
|
|
375
|
+
button(client, "6281@s.whatsapp.net", { body: "Pilih" } as ButtonConfig),
|
|
376
|
+
"async",
|
|
377
|
+
);
|
|
378
|
+
const chainError = await chainRejectsLike(
|
|
379
|
+
() => button(client).body("Pilih").build(),
|
|
380
|
+
"chain",
|
|
381
|
+
);
|
|
382
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
383
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test("error parity: legacyButton tombol kelebihan batas", async () => {
|
|
387
|
+
const { client } = captureClient();
|
|
388
|
+
const config = {
|
|
389
|
+
body: "Halo",
|
|
390
|
+
buttons: [
|
|
391
|
+
{ id: "a", text: "A" },
|
|
392
|
+
{ id: "b", text: "B" },
|
|
393
|
+
{ id: "c", text: "C" },
|
|
394
|
+
{ id: "d", text: "D" },
|
|
395
|
+
],
|
|
396
|
+
};
|
|
397
|
+
const asyncError = await rejectsLike(
|
|
398
|
+
legacyButton(client, "6281@s.whatsapp.net", config),
|
|
399
|
+
"async",
|
|
400
|
+
);
|
|
401
|
+
const chainError = throwsLike(
|
|
402
|
+
() =>
|
|
403
|
+
legacyButton(client)
|
|
404
|
+
.body("Halo")
|
|
405
|
+
.button("a", "A")
|
|
406
|
+
.button("b", "B")
|
|
407
|
+
.button("c", "C")
|
|
408
|
+
.button("d", "D"),
|
|
409
|
+
"chain",
|
|
410
|
+
);
|
|
411
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
412
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
413
|
+
assert.equal(asyncError.message, chainError.message);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("error parity: listMessage section kosong", async () => {
|
|
417
|
+
const { client } = captureClient();
|
|
418
|
+
const asyncError = await rejectsLike(
|
|
419
|
+
listMessage(client, "6281@s.whatsapp.net", {
|
|
420
|
+
body: "Pilih",
|
|
421
|
+
buttonText: "Buka",
|
|
422
|
+
sections: [{ title: "Menu", rows: [] }],
|
|
423
|
+
}),
|
|
424
|
+
"async",
|
|
425
|
+
);
|
|
426
|
+
const chainError = throwsLike(
|
|
427
|
+
() => listMessage(client).section("Menu", [] as never),
|
|
428
|
+
"chain",
|
|
429
|
+
);
|
|
430
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
431
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("error parity: listMessage tanpa section", async () => {
|
|
435
|
+
const { client } = captureClient();
|
|
436
|
+
const asyncError = await rejectsLike(
|
|
437
|
+
listMessage(client, "6281@s.whatsapp.net", {
|
|
438
|
+
body: "Pilih",
|
|
439
|
+
buttonText: "Buka",
|
|
440
|
+
sections: [],
|
|
441
|
+
} as ListMessageConfig),
|
|
442
|
+
"async",
|
|
443
|
+
);
|
|
444
|
+
const chainError = throwsLike(
|
|
445
|
+
() => listMessage(client).body("Pilih").buttonText("Buka").build(),
|
|
446
|
+
"chain",
|
|
447
|
+
);
|
|
448
|
+
assert.equal(asyncError.code, "VALIDATION");
|
|
449
|
+
assert.equal(chainError.message, chainError.message);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test("error parity: airich section kosong pada pipeline dua-langkah", async () => {
|
|
453
|
+
const asyncCap = captureClient();
|
|
454
|
+
const chainCap = captureClient();
|
|
455
|
+
const asyncError = await rejectsLike(
|
|
456
|
+
airich(asyncCap.client, "6281@s.whatsapp.net", { sections: [] }),
|
|
457
|
+
"async",
|
|
458
|
+
);
|
|
459
|
+
const chainError = await chainRejectsLike(
|
|
460
|
+
() => airich(chainCap.client).send("6281@s.whatsapp.net"),
|
|
461
|
+
"chain",
|
|
462
|
+
);
|
|
463
|
+
assert.equal(asyncError.code, "PROTOCOL_SEND");
|
|
464
|
+
assert.equal(chainError.code, "PROTOCOL_SEND");
|
|
465
|
+
assert.equal(
|
|
466
|
+
(asyncError as { stage?: string }).stage,
|
|
467
|
+
(chainError as { stage?: string }).stage,
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
const buildError = throwsLike(() => airich(asyncCap.client).build(), "build");
|
|
471
|
+
assert.equal(buildError.code, "VALIDATION");
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("error parity: transport failure diteruskan", async () => {
|
|
475
|
+
const { client } = captureClient(() => {
|
|
476
|
+
throw new Error("boom");
|
|
477
|
+
});
|
|
478
|
+
await assert.rejects(
|
|
479
|
+
text(client, "6281@s.whatsapp.net", { body: "halo" }),
|
|
480
|
+
/boom/,
|
|
481
|
+
);
|
|
482
|
+
await assert.rejects(
|
|
483
|
+
text(client).body("halo").send("6281@s.whatsapp.net"),
|
|
484
|
+
/boom/,
|
|
485
|
+
);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
test("edge: builder reuse chain dan async terisolasi", async () => {
|
|
489
|
+
const { client, sends } = captureClient();
|
|
490
|
+
await text(client, "6281@s.whatsapp.net", { body: "satu" });
|
|
491
|
+
await text(client, "6281@s.whatsapp.net", { body: "dua" });
|
|
492
|
+
assert.equal(sends.length, 2);
|
|
493
|
+
assert.deepEqual(sends[0]?.content, { conversation: "satu" });
|
|
494
|
+
assert.deepEqual(sends[1]?.content, { conversation: "dua" });
|
|
495
|
+
|
|
496
|
+
const builder = text(client);
|
|
497
|
+
await builder.body("tiga").send("6281@s.whatsapp.net");
|
|
498
|
+
await builder.body("empat").send("6281@s.whatsapp.net");
|
|
499
|
+
assert.equal(sends.length, 4);
|
|
500
|
+
assert.deepEqual(sends[2]?.content, { conversation: "tiga" });
|
|
501
|
+
assert.deepEqual(sends[3]?.content, { conversation: "empat" });
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("edge: concurrent async send tidak saling mengganggu", async () => {
|
|
505
|
+
const { client, sends } = captureClient();
|
|
506
|
+
const results = await Promise.all([
|
|
507
|
+
text(client, "6281@s.whatsapp.net", { body: "c1" }),
|
|
508
|
+
text(client, "6281@s.whatsapp.net", { body: "c2" }),
|
|
509
|
+
text(client, "6281@s.whatsapp.net", { body: "c3" }),
|
|
510
|
+
]);
|
|
511
|
+
assert.equal(results.length, 3);
|
|
512
|
+
assert.equal(sends.length, 3);
|
|
513
|
+
const bodies = sends.map(
|
|
514
|
+
(entry) => (entry.content as { conversation: string }).conversation,
|
|
515
|
+
);
|
|
516
|
+
assert.deepEqual([...bodies].sort(), ["c1", "c2", "c3"]);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
test("edge: config object tidak dimutasi library", async () => {
|
|
520
|
+
const { client } = captureUploadOkClient();
|
|
521
|
+
const config = {
|
|
522
|
+
type: "image" as const,
|
|
523
|
+
source: PNG_BYTES,
|
|
524
|
+
caption: "asli",
|
|
525
|
+
};
|
|
526
|
+
await media(client, "6281@s.whatsapp.net", config);
|
|
527
|
+
assert.deepEqual(Object.keys(config).sort(), ["caption", "source", "type"]);
|
|
528
|
+
assert.equal(config.caption, "asli");
|
|
529
|
+
assert.equal(config.source, PNG_BYTES);
|
|
530
|
+
|
|
531
|
+
const pollConfig = {
|
|
532
|
+
question: "Q?",
|
|
533
|
+
options: ["A", "B"],
|
|
534
|
+
selectableCount: 1,
|
|
535
|
+
};
|
|
536
|
+
await poll(client, "6281@s.whatsapp.net", pollConfig);
|
|
537
|
+
assert.deepEqual(pollConfig.options, ["A", "B"]);
|
|
538
|
+
assert.equal(pollConfig.selectableCount, 1);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
test("edge: header async valid, konflik header hanya mungkin di chain", async () => {
|
|
542
|
+
const { client } = captureUploadOkClient();
|
|
543
|
+
await button(client, "6281@s.whatsapp.net", {
|
|
544
|
+
body: "Pilih",
|
|
545
|
+
header: { type: "location", latitude: -6.2, longitude: 106.8 },
|
|
546
|
+
buttons: [{ type: "quick_reply" as const, text: "OK", id: "ok" }],
|
|
547
|
+
});
|
|
548
|
+
const chainError = throwsLike(
|
|
549
|
+
() =>
|
|
550
|
+
button(client)
|
|
551
|
+
.body("Pilih")
|
|
552
|
+
.image(PNG_BYTES)
|
|
553
|
+
.location({ latitude: -6.2, longitude: 106.8 }),
|
|
554
|
+
"chain image+location",
|
|
555
|
+
);
|
|
556
|
+
assert.equal(chainError.code, "VALIDATION");
|
|
557
|
+
});
|