-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
229 lines (203 loc) · 7.82 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import { statement, htmlStatement } from './index';
import plays from './plays.json';
import invoices from './invoices.json';
describe('Tests of tests', () => {
test('1 should equal 1', () => {
expect(1).toBe(1);
});
});
describe('Tests of statement() with full set of test data', () => {
const sttResult = statement(invoices[0], plays);
console.log(sttResult)
test('verify the full output', () => {
expect(sttResult).toBeDefined();
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/Hamlet: \$650.00 \(55 seats\)/);
expect(sttResult).toMatch(/As You Like It: \$580.00 \(35 seats\)/);
expect(sttResult).toMatch(/Othello: \$500.00 \(40 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$1,730.00/);
expect(sttResult).toMatch(/You earned 47 credits/);
});
});
describe('Tests of statement() with only one tragedy play', () => {
test('verify tragedy with 30 audience', () => {
const playTragedy = {
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 30
}
]
};
const sttResult = statement(playTragedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/Hamlet: \$400.00 \(30 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$400.00/);
expect(sttResult).toMatch(/You earned 0 credits/);
});
test('verify tragedy with 31 audience', () => {
const playTragedy = {
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 31
}
]
};
const sttResult = statement(playTragedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/Hamlet: \$410.00 \(31 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$410.00/);
expect(sttResult).toMatch(/You earned 1 credits/);
});
});
describe('Tests of statement() with only one comedy play', () => {
test('verify comedy with 20 audience', () => {
const playComedy = {
"customer": "BigCo",
"performances": [
{
"playID": "as-like",
"audience": 20
}
]
};
const sttResult = statement(playComedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/As You Like It: \$360.00 \(20 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$360.00/);
expect(sttResult).toMatch(/You earned 4 credits/);
});
test('verify comedy with 21 audience', () => {
const playComedy = {
"customer": "BigCo",
"performances": [
{
"playID": "as-like",
"audience": 21
}
]
};
const sttResult = statement(playComedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/As You Like It: \$468.00 \(21 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$468.00/);
expect(sttResult).toMatch(/You earned 4 credits/);
});
test('verify comedy with 31 audience', () => {
const playComedy = {
"customer": "BigCo",
"performances": [
{
"playID": "as-like",
"audience": 31
}
]
};
const sttResult = statement(playComedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/As You Like It: \$548.00 \(31 seats\)/);
expect(sttResult).toMatch(/Amount owed is \$548.00/);
expect(sttResult).toMatch(/You earned 7 credits/);
});
});
describe('Tests of statement() with invalid play type', () => {
test('invalid play type should cause Error', () => {
const playUnknown = {
"customer": "BigCo",
"performances": [
{
"playID": "unknownId",
"audience": 1
}
]
};
const mockPlays = {
"unknownId": {"name": "unknownName", "type": "unknownType"},
}
expect(() => statement(playUnknown, mockPlays)).toThrow(Error);
});
});
describe('Tests of htmlStatement() with full set of test data', () => {
const sttResult = htmlStatement(invoices[0], plays);
console.log(sttResult)
test('verify the full output', () => {
expect(sttResult).toBeDefined();
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/<td>Hamlet<\/td><td>55<\/td><td>\$650.00<\/td>/);
expect(sttResult).toMatch(/<td>As You Like It<\/td><td>35<\/td><td>\$580.00<\/td>/);
expect(sttResult).toMatch(/<td>Othello<\/td><td>40<\/td><td>\$500.00<\/td>/);
expect(sttResult).toMatch(/Amount owed is <em>\$1,730.00<\/em>/);
expect(sttResult).toMatch(/You earned <em>47<\/em> credits/);
});
});
describe('Tests of htmlStatement() with only one comedy play', () => {
test('verify comedy with 1 audience', () => {
const playComedy = {
"customer": "BigCo",
"performances": [
{
"playID": "as-like",
"audience": 1
}
]
};
const sttResult = htmlStatement(playComedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/<td>As You Like It<\/td><td>1<\/td><td>\$303.00<\/td>/);
expect(sttResult).toMatch(/Amount owed is <em>\$303.00<\/em>/);
expect(sttResult).toMatch(/You earned <em>0<\/em> credits/);
});
test('verify comedy with 5 audience', () => {
const playComedy = {
"customer": "BigCo",
"performances": [
{
"playID": "as-like",
"audience": 5
}
]
};
const sttResult = htmlStatement(playComedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/<td>As You Like It<\/td><td>5<\/td><td>\$315.00<\/td>/);
expect(sttResult).toMatch(/Amount owed is <em>\$315.00<\/em>/);
expect(sttResult).toMatch(/You earned <em>1<\/em> credits/);
});
});
describe('Tests of htmlStatement() with only one tragedy play', () => {
test('verify tragedy with 1 audience', () => {
const playTragedy = {
"customer": "BigCo",
"performances": [
{
"playID": "othello",
"audience": 1
}
]
};
const sttResult = htmlStatement(playTragedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/<td>Othello<\/td><td>1<\/td><td>\$400.00<\/td>/);
expect(sttResult).toMatch(/Amount owed is <em>\$400.00<\/em>/);
expect(sttResult).toMatch(/You earned <em>0<\/em> credits/);
});
test('verify tragedy with 5 audience', () => {
const playTragedy = {
"customer": "BigCo",
"performances": [
{
"playID": "othello",
"audience": 5
}
]
};
const sttResult = htmlStatement(playTragedy, plays);
expect(sttResult).toMatch(/Statement for BigCo/);
expect(sttResult).toMatch(/<td>Othello<\/td><td>5<\/td><td>\$400.00<\/td>/);
expect(sttResult).toMatch(/Amount owed is <em>\$400.00<\/em>/);
expect(sttResult).toMatch(/You earned <em>0<\/em> credits/);
});
});