-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.test.ts
44 lines (41 loc) · 1.07 KB
/
timer.test.ts
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
import { HttpApp } from '../http/app';
import { Route } from '../interfaces';
import { Timer } from './timer';
import { IncomingMessage } from 'http';
import { OutgoingMessage } from 'http';
const routes: Route[] = [
{
path: '',
middlewares: [Timer],
children: [
{
methods: ['GET'],
path: '/foo/bar'
}
]
}
];
describe('Timer unit tests', () => {
test('sets appropriate headers', (done) => {
const app = new HttpApp(routes);
const listener = app.listen();
const now = Date.now();
app['response$'].subscribe((response) => {
expect(
Number(response.headers['X-Request-Timein'])
).toBeGreaterThanOrEqual(now);
expect(
Number(response.headers['X-Request-Timeout'])
).toBeGreaterThanOrEqual(now);
expect(
Number(response.headers['X-Response-Time'])
).toBeGreaterThanOrEqual(0);
expect(response.statusCode).toEqual(200);
done();
});
listener(
{ method: 'GET', url: '/foo/bar' } as IncomingMessage,
{} as OutgoingMessage
);
});
});