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
93 lines (84 loc) · 3.23 KB
/
Copy pathtest.js
File metadata and controls
93 lines (84 loc) · 3.23 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
// To run tests locally:
// 1. From `exercisefiles/node` run: `npm install --save-dev mocha`
// 2. Run tests with: `npx mocha test.js`
const assert = require('assert');
const http = require('http');
// Require the server so it starts before tests run.
require('./nodeserver');
describe('Node Server', function () {
// allow a small timeout for server startup and external calls
this.timeout(5000);
before((done) => {
// small delay to allow server.listen callback to complete
setTimeout(done, 200);
});
it('GET /get without key -> "key not passed"', (done) => {
http.get('http://localhost:3000/get', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
assert.strictEqual(data, 'key not passed');
done();
});
}).on('error', done);
});
it('GET /get?key=world -> "hello world"', (done) => {
http.get('http://localhost:3000/get?key=world', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
assert.strictEqual(data, 'hello world');
done();
});
}).on('error', done);
});
it('GET /Validatephonenumber -> valid', (done) => {
http.get('http://localhost:3000/Validatephonenumber?phoneNumber=34666666666', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
assert.strictEqual(data, 'valid');
done();
});
}).on('error', done);
});
it('GET /ValidateSpanishDNI valid and invalid', (done) => {
// valid DNI
http.get('http://localhost:3000/ValidateSpanishDNI?dni=86471508H', (res) => {
let d1 = '';
res.on('data', (c) => { d1 += c; });
res.on('end', () => {
assert.strictEqual(d1, 'valid');
// invalid DNI
http.get('http://localhost:3000/ValidateSpanishDNI?dni=12345678A', (res2) => {
let d2 = '';
res2.on('data', (c) => { d2 += c; });
res2.on('end', () => {
assert.strictEqual(d2, 'invalid');
done();
});
}).on('error', done);
});
}).on('error', done);
});
it('GET /ReturnColorCode?color=red -> #FF0000', (done) => {
http.get('http://localhost:3000/ReturnColorCode?color=red', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
assert.strictEqual(data, '#FF0000');
done();
});
}).on('error', done);
});
it('GET /DaysBetweenDates returns days', (done) => {
http.get('http://localhost:3000/DaysBetweenDates?date1=2020-01-01&date2=2020-01-02', (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
assert.strictEqual(data, '1 days');
done();
});
}).on('error', done);
});
});