generated from jfadev/jfa-whatsapp-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversation.test.js
89 lines (88 loc) · 2.68 KB
/
conversation.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import conversation from "./conversation";
describe("Conversation Flow", () => {
for (const reply of conversation) {
it(`Reply ${reply.id}: Check [id] field`, () => {
expect(reply.id).toBeDefined();
expect(reply.id).toBeGreaterThan(0);
});
it(`Reply ${reply.id}: Check [parent] field`, () => {
expect(reply.parent).toBeDefined();
expect(
Number.isInteger(reply.parent) ||
reply.parent instanceof Array
).toBeTruthy()
});
it(`Reply ${reply.id}: Check [pattern] field`, () => {
expect(reply.pattern).toBeDefined();
expect(reply.pattern instanceof RegExp).toBeTruthy();
});
it(`Reply ${reply.id}: Check [message] field`, () => {
expect(
!reply.hasOwnProperty("message") ||
typeof reply.message === "string"
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [buttons] field`, () => {
expect(
!reply.hasOwnProperty("buttons") ||
(
reply.buttons instanceof Array &&
reply.hasOwnProperty("description") &&
typeof reply.description === "string"
)
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [list] field`, () => {
expect(
!reply.hasOwnProperty("list") ||
(
reply.list instanceof Array &&
reply.hasOwnProperty("button") &&
typeof reply.button === "string" &&
reply.hasOwnProperty("description") &&
typeof reply.description === "string"
)
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [link] field`, () => {
expect(
!reply.hasOwnProperty("link") ||
(
typeof reply.link === "string" &&
/^http/.test(reply.link) &&
reply.hasOwnProperty("message") &&
typeof reply.message === "string"
)
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [image] field`, () => {
expect(
!reply.hasOwnProperty("image") ||
(
typeof reply.image === "string" ||
reply.image.hasOwnProperty("base64")
)
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [audio] field`, () => {
expect(
!reply.hasOwnProperty("audio") ||
(
typeof reply.audio === "string" ||
reply.audio.hasOwnProperty("base64")
)
).toBeTruthy();
});
it(`Reply ${reply.id}: Check [forward] field`, () => {
expect(
!reply.hasOwnProperty("forward") ||
(
typeof reply.forward === "string" &&
/^\d+\@c\.us/.test(reply.link) &&
reply.hasOwnProperty("message") &&
typeof reply.message === "string"
)
).toBeTruthy();
});
}
});