forked from microsoft/CopilotHackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
229 lines (209 loc) · 6.88 KB
/
Copy pathtest.js
File metadata and controls
229 lines (209 loc) · 6.88 KB
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
//write npm command line to install mocha
//npm install --global mocha
//command to run this test file
//mocha test.js
const assert = require('assert');
const http = require('http');
const server = require('./nodeserver');
describe('Node Server', () => {
it('should return "key not passed" if key is not passed', (done) => {
http
.get('http://localhost:3000/get' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'key not passed');
done();
});
});
});
//add test to check get when key is equal to world
it('should return "Hello, world!" if key is equal to "world"', (done) => {
http
.get('http://localhost:3000/get?key=world!' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'Hello, world!');
done();
});
});
});
//add test to check validatephoneNumber
it('should return true if phone number is valid', (done) => {
http
.get('http://localhost:3000/Validatephonenumber?phoneNumber=34666666666' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'valid');
done();
});
})
});
//write test to validate validateSpanishDNI
it('should return true if dni is valid', (done) => {
http
.get('http://localhost:3000/ValidateSpanishDNI?dni=12345678Z' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'valid');
done();
});
})
});
//write test for returnColorCode red should return code #FF0000
it('should return #FF0000 if color is red', (done) => {
http
.get('http://localhost:3000/returnColorCode?color=red' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'red');
done();
});
})
});
//write test for daysBetweenDates
it('should return 1 if date1 is 01/01/2020 and date2 is 02/01/2020', (done) => {
http
.get('http://localhost:3000/daysBetweenDates?date1=01/01/2020&date2=02/01/2020' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, '31');
done();
});
})
});
//write test for TellMeAJoke
it('should return a joke', (done) => {
http
.get('http://localhost:3000/TellMeAJoke' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, '123');
done();
});
})
});
//write test for Receive by querystring a parameter called director
it('should return a movie', (done) => {
http
.get('http://localhost:3000/MoviesByDirector?director=Quentin%20Tarantino' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'Quentin Tarantino');
done();
});
})
});
//write test for receive by querystring a url and return the host
it('should return the host', (done) => {
http
.get('http://localhost:3000/ParseUrl?url=https://www.google.com/' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
assert.equal(data, 'www.google.com');
done();
});
})
});
//write a test for receive by querystring the current directory and return the list of files in a directory
it('should return the list of files in a directory', (done) => {
http
.get('http://localhost:3000/ListFiles?directory=.' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
//validate the response data have got almost one element
assert.equal(data.length > 0, true);
done();
});
})
});
//write a test to invoke GetFullTextFile with query string filename and return return lines that contains the word "Fusce"
it('should return the lines that contains the word "Fusce"', (done) => {
http
.get('http://localhost:3000/GetFullTextFile?filename=sample.txt' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
//validate the response data have got almost one element
assert.equal(data, '5');
done();
});
})
});
//write a test to invoke CalculateMemoryConsumption with query string filename and return the memory consumption
it('should return the memory consumption', (done) => {
http
.get('http://localhost:3000/CalculateMemoryConsumption' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
//validate the response data have got almost one element
assert.equal(data, '0.01');
done();
});
})
});
// write a test to invoke MakeZipFile with query string filename returns the numbers of bytes of the zip file
it('should return the numbers of bytes of the zip file', (done) => {
http
.get('http://localhost:3000/MakeZipFile?filename=sample.txt' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
//validate the response data have got almost one element
assert.equal(data, '29');
done();
});
})
});
//write a test to invoke RandomEuropeanCountry and return a random european country
it('should return a random european country', (done) => {
http
.get('http://localhost:3000/RandomEuropeanCountry' , (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
//validate the response data have got almost one element
assert.equal(data.length = 1, true);
done();
});
})
});
});