-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.spec.ts
40 lines (35 loc) · 1.11 KB
/
index.spec.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
import * as request from 'supertest';
import { Controller, Get } from '@nestjs/common';
import { RealIP } from '../src';
import { createServer } from './helpers/utils';
import { headers, platforms } from './helpers/data';
describe.each(platforms)('Main %s platform', (platformName, platformClass) => {
let app;
let server;
beforeEach(async () => {
@Controller('/')
class TestController {
@Get('my-ip')
get(@RealIP() ip: string): string {
return ip;
}
}
app = await createServer(TestController, platformClass);
server = app.getHttpServer();
});
afterEach(async () => {
await app.close();
});
it('Default IP address', async () => {
const { statusCode, text } = await request(server).get('/my-ip');
expect(statusCode).toEqual(200);
expect(text).toEqual('::ffff:127.0.0.1');
});
it.each(headers)('With header "%s": "%s" ', async (header, value, expected) => {
const { statusCode, text } = await request(server)
.get('/my-ip')
.set({ [header]: value });
expect(statusCode).toEqual(200);
expect(text).toEqual(expected);
});
});