-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
129 lines (115 loc) · 4.28 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const {buildConversationalTree, readChat} = require('.');
const conversationTree = {
messages: [
{text: 'Hello, John! It looks like you booked a Basic Economy flight.'},
{text: 'Are you aware that this flight doesn\'t have any storage for carry-on luggage?'}
],
left: {
messages: [
{text: "Some other limitations you may want to consider is that you will not be able to pick a seat."},
{text: "We're happy to let you know that we can upgrade you today for just $25!", label: 1},
{text: "Would you like to do that now?"}
],
left: {
messages: [{text: 'Okay, please let our customer service team know if you change your mind.'}]
},
right: {
messages: [
{text: "Okay, you've been upgraded!"}
]
}
},
right: {
goto: 1
}
};
test('should build conversational tree', () => {
// Arrange
const text = `Hello, John! It looks like you booked a Basic Economy flight.
Are you aware that this flight doesn't have any storage for carry-on luggage?
-No
Some other limitations you may want to consider is that you will not be able to pick a seat.
1:We're happy to let you know that we can upgrade you today for just $25!
Would you like to do that now?
-Not right now
=Okay, please let our customer service team know if you change your mind.
-Yes, please upgrade
=Okay, you've been upgraded!
-Yes
>1`;
// Act
const tree = buildConversationalTree(text);
// Assert
expect(tree).toEqual({
"messages": [{"text": "Hello, John! It looks like you booked a Basic Economy flight."}, {"text": "Are you aware that this flight doesn't have any storage for carry-on luggage?"}],
"left": {
"messages": [{"text": "Some other limitations you may want to consider is that you will not be able to pick a seat."}, {
"text": "1:We're happy to let you know that we can upgrade you today for just $25!",
"label": "1"
}, {"text": "Would you like to do that now?"}],
"left": {
"messages": [{"text": "=Okay, please let our customer service team know if you change your mind."}],
"right": {"messages": [{"text": "=Okay, you've been upgraded!"}], "right": {"messages": [], "goto": ""}}
}
}
}
);
});
test('node tree two, no, and not right now', () => {
// Arrange
const userAnswers = ['No', 'Not right now'];
// Act
const result = readChat(conversationTree, userAnswers);
// Assert
expect(result).toEqual(
`Hello, John! It looks like you booked a Basic Economy flight.
Are you aware that this flight doesn't have any storage for carry-on luggage?
-No
Some other limitations you may want to consider is that you will not be able to pick a seat.
1:We're happy to let you know that we can upgrade you today for just $25!
Would you like to do that now?
-Not right now
=Okay, please let our customer service team know if you change your mind.
`
);
});
/*
test('I did not, Yes, please upgrade', () => {
// Arrange
const userAnswers = ['No', 'Yes, please upgrade'];
// Act
const result = readChat(conversationTree, userAnswers);
// Assert
console.log(result);
expect(result).toEqual(
`Hello, John! It looks like you booked a Basic Economy flight.
Are you aware that this flight doesn't have any storage for carry-on luggage?
-No
Some other limitations you may want to consider is that you will not be able to pick a seat.
1:We're happy to let you know that we can upgrade you today for just $25!
Would you like to do that now?
-Yes, please upgrade
=Okay, you've been upgraded!
`
);
})
test('I did not, Yes', () => {
// Arrange
const userAnswers = ['No', 'Yes >1'];
// Act
const result = readChat(conversationTree, userAnswers);
// Assert
console.log(result);
expect(result).toEqual(
`Hello, John! It looks like you booked a Basic Economy flight.
Are you aware that this flight doesn't have any storage for carry-on luggage?
-No
Some other limitations you may want to consider is that you will not be able to pick a seat.
1:We're happy to let you know that we can upgrade you today for just $25!
Would you like to do that now?
-Yes, please upgrade
=Okay, you've been upgraded!
`
);
})
*/