@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,416 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { button } from "@kyyinfinite/zapo-message";
|
|
4
|
+
import { ValidationError, DuplicateIdError } from "@kyyinfinite/zapo-message";
|
|
5
|
+
import type { NativeSection } from "@kyyinfinite/zapo-message";
|
|
6
|
+
import { asClient, first } from "./helpers.js";
|
|
7
|
+
|
|
8
|
+
const noopClient = asClient({
|
|
9
|
+
message: {
|
|
10
|
+
async send() {
|
|
11
|
+
return { id: "X" };
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const SECTIONS: NativeSection[] = [
|
|
16
|
+
{
|
|
17
|
+
title: "Utama",
|
|
18
|
+
rows: [{ id: "row1", title: "Baris Satu", description: "desc" }],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const flowButtons = (result: {
|
|
23
|
+
interactiveMessage: {
|
|
24
|
+
nativeFlowMessage: {
|
|
25
|
+
buttons: { name: string; buttonParamsJson: string }[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}) => result.interactiveMessage.nativeFlowMessage.buttons;
|
|
29
|
+
|
|
30
|
+
test("button: quick_reply — param JSON valid dan identitas id dipertahankan", async () => {
|
|
31
|
+
const result = await button(noopClient)
|
|
32
|
+
.quick_reply("Kirim", "btn_qr_1")
|
|
33
|
+
.build();
|
|
34
|
+
const btn = first(
|
|
35
|
+
result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
36
|
+
name: string;
|
|
37
|
+
buttonParamsJson: string;
|
|
38
|
+
}[],
|
|
39
|
+
);
|
|
40
|
+
assert.equal(btn.name, "quick_reply");
|
|
41
|
+
assert.deepEqual(JSON.parse(btn.buttonParamsJson), {
|
|
42
|
+
display_text: "Kirim",
|
|
43
|
+
id: "btn_qr_1",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("button: cta_url — URL valid diterima", async () => {
|
|
48
|
+
const result = await button(noopClient)
|
|
49
|
+
.cta_url("Buka", "https://example.com/path?x=1")
|
|
50
|
+
.build();
|
|
51
|
+
const btn = first(
|
|
52
|
+
result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
53
|
+
name: string;
|
|
54
|
+
buttonParamsJson: string;
|
|
55
|
+
}[],
|
|
56
|
+
);
|
|
57
|
+
assert.equal(btn.name, "cta_url");
|
|
58
|
+
assert.deepEqual(JSON.parse(btn.buttonParamsJson), {
|
|
59
|
+
display_text: "Buka",
|
|
60
|
+
url: "https://example.com/path?x=1",
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("button: cta_url — URL tidak valid ditolak", async () => {
|
|
65
|
+
await assert.rejects(
|
|
66
|
+
async () => button(noopClient).cta_url("Buka", "bukan url").build(),
|
|
67
|
+
(error: Error) =>
|
|
68
|
+
error instanceof ValidationError && /bukan URL valid/.test(error.message),
|
|
69
|
+
);
|
|
70
|
+
await assert.rejects(
|
|
71
|
+
async () => button(noopClient).cta_url("Buka", "ftp://example.com").build(),
|
|
72
|
+
/harus http\/https/,
|
|
73
|
+
);
|
|
74
|
+
await assert.rejects(
|
|
75
|
+
async () =>
|
|
76
|
+
button(noopClient)
|
|
77
|
+
.cta_url("Buka", undefined as unknown as string)
|
|
78
|
+
.build(),
|
|
79
|
+
ValidationError,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("button: cta_copy — kode disimpan", async () => {
|
|
84
|
+
const result = await button(noopClient).cta_copy("Salin", "ZAPO123").build();
|
|
85
|
+
const btn = first(
|
|
86
|
+
result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
87
|
+
name: string;
|
|
88
|
+
buttonParamsJson: string;
|
|
89
|
+
}[],
|
|
90
|
+
);
|
|
91
|
+
assert.deepEqual(JSON.parse(btn.buttonParamsJson), {
|
|
92
|
+
display_text: "Salin",
|
|
93
|
+
copy_code: "ZAPO123",
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("button: cta_copy — kode kosong/melebihi batas ditolak", async () => {
|
|
98
|
+
await assert.rejects(
|
|
99
|
+
async () => button(noopClient).cta_copy("Salin", "").build(),
|
|
100
|
+
/copy_code/,
|
|
101
|
+
);
|
|
102
|
+
await assert.rejects(
|
|
103
|
+
async () => button(noopClient).cta_copy("Salin", "x".repeat(51)).build(),
|
|
104
|
+
/batas 50/,
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("button: cta_call — nomor E.164 valid", async () => {
|
|
109
|
+
const result = await button(noopClient)
|
|
110
|
+
.cta_call("Hubungi", "+628123456789")
|
|
111
|
+
.build();
|
|
112
|
+
const btn = first(
|
|
113
|
+
result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
114
|
+
name: string;
|
|
115
|
+
buttonParamsJson: string;
|
|
116
|
+
}[],
|
|
117
|
+
);
|
|
118
|
+
assert.equal(btn.name, "cta_call");
|
|
119
|
+
assert.deepEqual(JSON.parse(btn.buttonParamsJson), {
|
|
120
|
+
display_text: "Hubungi",
|
|
121
|
+
phone_number: "+628123456789",
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("button: cta_call — nomor tidak valid ditolak", async () => {
|
|
126
|
+
await assert.rejects(
|
|
127
|
+
async () => button(noopClient).cta_call("Hubungi", "abc").build(),
|
|
128
|
+
/E\.164/,
|
|
129
|
+
);
|
|
130
|
+
await assert.rejects(
|
|
131
|
+
async () => button(noopClient).cta_call("Hubungi", "12345").build(),
|
|
132
|
+
/E\.164/,
|
|
133
|
+
);
|
|
134
|
+
await assert.rejects(
|
|
135
|
+
async () =>
|
|
136
|
+
button(noopClient)
|
|
137
|
+
.cta_call("Hubungi", undefined as unknown as string)
|
|
138
|
+
.build(),
|
|
139
|
+
ValidationError,
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("button: send_location — tanpa dan dengan display_text", async () => {
|
|
144
|
+
const empty = await button(noopClient).send_location().build();
|
|
145
|
+
assert.deepEqual(
|
|
146
|
+
JSON.parse(
|
|
147
|
+
first(
|
|
148
|
+
empty.interactiveMessage.nativeFlowMessage.buttons as {
|
|
149
|
+
buttonParamsJson: string;
|
|
150
|
+
}[],
|
|
151
|
+
).buttonParamsJson,
|
|
152
|
+
),
|
|
153
|
+
{},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const labeled = await button(noopClient)
|
|
157
|
+
.send_location("Kirim lokasi")
|
|
158
|
+
.build();
|
|
159
|
+
assert.deepEqual(
|
|
160
|
+
JSON.parse(
|
|
161
|
+
first(
|
|
162
|
+
labeled.interactiveMessage.nativeFlowMessage.buttons as {
|
|
163
|
+
buttonParamsJson: string;
|
|
164
|
+
}[],
|
|
165
|
+
).buttonParamsJson,
|
|
166
|
+
),
|
|
167
|
+
{ display_text: "Kirim lokasi" },
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("button: single_select — section/row valid dipertahankan bentuknya", async () => {
|
|
172
|
+
const result = await button(noopClient)
|
|
173
|
+
.single_select("Pilih", SECTIONS)
|
|
174
|
+
.build();
|
|
175
|
+
const btn = first(
|
|
176
|
+
result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
177
|
+
name: string;
|
|
178
|
+
buttonParamsJson: string;
|
|
179
|
+
}[],
|
|
180
|
+
);
|
|
181
|
+
assert.equal(btn.name, "single_select");
|
|
182
|
+
const params = JSON.parse(btn.buttonParamsJson);
|
|
183
|
+
assert.equal(params.title, "Pilih");
|
|
184
|
+
assert.equal(params.sections[0].title, "Utama");
|
|
185
|
+
assert.deepEqual(params.sections[0].rows[0], {
|
|
186
|
+
id: "row1",
|
|
187
|
+
title: "Baris Satu",
|
|
188
|
+
description: "desc",
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("button: single_select — section tidak valid ditolak", async () => {
|
|
193
|
+
await assert.rejects(
|
|
194
|
+
async () => button(noopClient).single_select("Pilih", []).build(),
|
|
195
|
+
/minimal satu section/,
|
|
196
|
+
);
|
|
197
|
+
await assert.rejects(
|
|
198
|
+
async () =>
|
|
199
|
+
button(noopClient)
|
|
200
|
+
.single_select("Pilih", [{ title: "S", rows: [] }] as NativeSection[])
|
|
201
|
+
.build(),
|
|
202
|
+
/minimal satu row/,
|
|
203
|
+
);
|
|
204
|
+
await assert.rejects(
|
|
205
|
+
async () =>
|
|
206
|
+
button(noopClient)
|
|
207
|
+
.single_select("Pilih", [
|
|
208
|
+
{ title: "S", rows: [{ title: "tanpa id" }] },
|
|
209
|
+
] as unknown as NativeSection[])
|
|
210
|
+
.build(),
|
|
211
|
+
/id/,
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("button: single_select — row id duplikat antar section ditolak", async () => {
|
|
216
|
+
await assert.rejects(
|
|
217
|
+
async () =>
|
|
218
|
+
button(noopClient)
|
|
219
|
+
.single_select("Pilih", [
|
|
220
|
+
{ title: "S1", rows: [{ id: "dup", title: "A" }] },
|
|
221
|
+
{ title: "S2", rows: [{ id: "dup", title: "B" }] },
|
|
222
|
+
])
|
|
223
|
+
.build(),
|
|
224
|
+
(error: Error) => error instanceof DuplicateIdError,
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("button: quick_reply id duplikat → DuplicateIdError", async () => {
|
|
229
|
+
await assert.rejects(
|
|
230
|
+
async () =>
|
|
231
|
+
button(noopClient)
|
|
232
|
+
.quick_reply("A", "same")
|
|
233
|
+
.quick_reply("B", "same")
|
|
234
|
+
.build(),
|
|
235
|
+
(error: Error & { id?: string }) =>
|
|
236
|
+
error instanceof DuplicateIdError && error.id === "same",
|
|
237
|
+
);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("button: tanpa button → ValidationError", async () => {
|
|
241
|
+
await assert.rejects(
|
|
242
|
+
async () => button(noopClient).body("tanpa tombol").build(),
|
|
243
|
+
/minimal satu button/,
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("button: bottom_sheet param masuk messageParamsJson, bukan buttonParamsJson", async () => {
|
|
248
|
+
const result = await button(noopClient)
|
|
249
|
+
.quick_reply("Opsi", "opt1")
|
|
250
|
+
.bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" })
|
|
251
|
+
.build();
|
|
252
|
+
|
|
253
|
+
const flow = result.interactiveMessage.nativeFlowMessage;
|
|
254
|
+
const params = JSON.parse(flow.messageParamsJson as string);
|
|
255
|
+
assert.deepEqual(params.bottom_sheet, {
|
|
256
|
+
in_thread_buttons_limit: 2,
|
|
257
|
+
list_title: "Daftar",
|
|
258
|
+
button_title: "Buka",
|
|
259
|
+
});
|
|
260
|
+
assert.equal(
|
|
261
|
+
JSON.parse(
|
|
262
|
+
first(flow.buttons as { buttonParamsJson: string }[]).buttonParamsJson,
|
|
263
|
+
).bottom_sheet,
|
|
264
|
+
undefined,
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("button: limited_time_offer — expiration_time dihitung sekali (stabil antar build)", async () => {
|
|
269
|
+
const builder = button(noopClient)
|
|
270
|
+
.quick_reply("QR", "qr1")
|
|
271
|
+
.limited_time_offer({ copyCode: "OFFER", expiresIn: 120 });
|
|
272
|
+
const first = await builder.build();
|
|
273
|
+
const second = await builder.build();
|
|
274
|
+
|
|
275
|
+
const p1 = JSON.parse(
|
|
276
|
+
first.interactiveMessage.nativeFlowMessage.messageParamsJson as string,
|
|
277
|
+
).limited_time_offer;
|
|
278
|
+
const p2 = JSON.parse(
|
|
279
|
+
second.interactiveMessage.nativeFlowMessage.messageParamsJson as string,
|
|
280
|
+
).limited_time_offer;
|
|
281
|
+
assert.equal(p1.expiration_time, p2.expiration_time);
|
|
282
|
+
assert.ok(Number.isInteger(p1.expiration_time));
|
|
283
|
+
assert.equal(p1.copy_code, "OFFER");
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("button: limited_time_offer — url tidak valid ditolak", async () => {
|
|
287
|
+
await assert.rejects(
|
|
288
|
+
async () =>
|
|
289
|
+
button(noopClient)
|
|
290
|
+
.limited_time_offer({ url: "javascript:alert(1)" })
|
|
291
|
+
.build(),
|
|
292
|
+
/harus http\/https/,
|
|
293
|
+
);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("button: metadata internal tidak bocor ke buttonParamsJson", async () => {
|
|
297
|
+
const result = await button(noopClient)
|
|
298
|
+
.quick_reply("QR", "qr1")
|
|
299
|
+
.cta_copy("Copy", "CODE")
|
|
300
|
+
.single_select("Pilih", SECTIONS)
|
|
301
|
+
.bottom_sheet({ limit: 1 })
|
|
302
|
+
.limited_time_offer({ copyCode: "OFF" })
|
|
303
|
+
.build();
|
|
304
|
+
|
|
305
|
+
const flow = result.interactiveMessage.nativeFlowMessage;
|
|
306
|
+
for (const btn of flow.buttons as { buttonParamsJson: string }[]) {
|
|
307
|
+
const parsed = JSON.parse(btn.buttonParamsJson);
|
|
308
|
+
assert.equal(parsed.__id, undefined);
|
|
309
|
+
assert.equal(parsed._id, undefined);
|
|
310
|
+
assert.equal(
|
|
311
|
+
parsed.id ?? "",
|
|
312
|
+
typeof parsed.id === "string" ? parsed.id : "",
|
|
313
|
+
);
|
|
314
|
+
const flat = JSON.stringify(parsed);
|
|
315
|
+
assert.ok(!flat.includes("__id"));
|
|
316
|
+
assert.ok(!flat.includes('"_internal"'));
|
|
317
|
+
assert.ok(!flat.includes("undefined"));
|
|
318
|
+
}
|
|
319
|
+
if (flow.messageParamsJson) {
|
|
320
|
+
assert.ok(!flow.messageParamsJson.includes("__id"));
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("button: buttonParamsJson selalu JSON string valid", async () => {
|
|
325
|
+
const result = await button(noopClient)
|
|
326
|
+
.quick_reply("QR", "qr1")
|
|
327
|
+
.cta_url("U", "https://example.com")
|
|
328
|
+
.cta_call("C", "+62812345678")
|
|
329
|
+
.send_location()
|
|
330
|
+
.single_select("P", SECTIONS)
|
|
331
|
+
.build();
|
|
332
|
+
|
|
333
|
+
for (const btn of result.interactiveMessage.nativeFlowMessage.buttons as {
|
|
334
|
+
buttonParamsJson: string;
|
|
335
|
+
}[]) {
|
|
336
|
+
assert.equal(typeof btn.buttonParamsJson, "string");
|
|
337
|
+
assert.doesNotThrow(() => JSON.parse(btn.buttonParamsJson));
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("button: display text melebihi batas karakter ditolak", async () => {
|
|
342
|
+
await assert.rejects(
|
|
343
|
+
async () => button(noopClient).quick_reply("x".repeat(201), "qr1").build(),
|
|
344
|
+
/batas 200 karakter/,
|
|
345
|
+
);
|
|
346
|
+
await assert.rejects(
|
|
347
|
+
async () => button(noopClient).quick_reply("", "qr1").build(),
|
|
348
|
+
/display_text/,
|
|
349
|
+
);
|
|
350
|
+
await assert.rejects(
|
|
351
|
+
async () =>
|
|
352
|
+
button(noopClient)
|
|
353
|
+
.quick_reply("OK", undefined as unknown as string)
|
|
354
|
+
.build(),
|
|
355
|
+
/id/,
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("button: body/footer validasi", async () => {
|
|
360
|
+
await assert.rejects(
|
|
361
|
+
async () =>
|
|
362
|
+
button(noopClient)
|
|
363
|
+
.body(123 as unknown as string)
|
|
364
|
+
.quick_reply("x", "x1")
|
|
365
|
+
.build(),
|
|
366
|
+
/body harus string/,
|
|
367
|
+
);
|
|
368
|
+
await assert.rejects(
|
|
369
|
+
async () =>
|
|
370
|
+
button(noopClient)
|
|
371
|
+
.footer(42 as unknown as string)
|
|
372
|
+
.quick_reply("x", "x1")
|
|
373
|
+
.build(),
|
|
374
|
+
/footer harus string/,
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("button: toCard() menghasilkan kartu tanpa wrapper interactiveMessage", async () => {
|
|
379
|
+
const card = (
|
|
380
|
+
await button(noopClient)
|
|
381
|
+
.title("Judul")
|
|
382
|
+
.body("Isi")
|
|
383
|
+
.footer("F")
|
|
384
|
+
.quick_reply("QR", "qr1")
|
|
385
|
+
.build()
|
|
386
|
+
).interactiveMessage;
|
|
387
|
+
assert.equal((card.body as { text: string }).text, "Isi");
|
|
388
|
+
assert.equal((card.footer as { text: string }).text, "F");
|
|
389
|
+
assert.equal((card.header as { title: string }).title, "Judul");
|
|
390
|
+
assert.equal((card.nativeFlowMessage.buttons as unknown[]).length, 1);
|
|
391
|
+
assert.equal(
|
|
392
|
+
(card as { interactiveMessage?: unknown }).interactiveMessage,
|
|
393
|
+
undefined,
|
|
394
|
+
);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("button: urutan dan jumlah tombol dipertahankan", async () => {
|
|
398
|
+
const result = await button(noopClient)
|
|
399
|
+
.quick_reply("Satu", "b1")
|
|
400
|
+
.cta_url("Dua", "https://example.com")
|
|
401
|
+
.cta_copy("Tiga", "C3")
|
|
402
|
+
.cta_call("Empat", "+62812345678")
|
|
403
|
+
.send_location("Lima")
|
|
404
|
+
.build();
|
|
405
|
+
|
|
406
|
+
const names = (
|
|
407
|
+
result.interactiveMessage.nativeFlowMessage.buttons as { name: string }[]
|
|
408
|
+
).map((b) => b.name);
|
|
409
|
+
assert.deepEqual(names, [
|
|
410
|
+
"quick_reply",
|
|
411
|
+
"cta_url",
|
|
412
|
+
"cta_copy",
|
|
413
|
+
"cta_call",
|
|
414
|
+
"send_location",
|
|
415
|
+
]);
|
|
416
|
+
});
|