-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
67 lines (45 loc) · 1.62 KB
/
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
const express = require('express');
const request = require('supertest');
const resolvePath = require('./');
describe('express-resolve-path', () => {
it('should treat multiple slashes as single slashes.', done => {
const app = express();
app.use(resolvePath());
app.get('/foo/bar', (req, res) => res.end(req.url));
request(app)
.get('///foo///bar///?val=test')
.expect('/foo/bar?val=test', done);
});
it('should support the allowed methods.', done => {
const app = express();
app.use(resolvePath({ methods: 'POST' }));
app.post('/foo', (req, res) => res.send(req.url));
request(app)
.post('/foo//')
.expect('/foo', done);
});
it('should not be case sensitive in the allow method.', done => {
const app = express();
app.use(resolvePath({ methods: 'get' }));
app.get('/not-sensitive', (req, res) => res.send(req.url));
request(app)
.get('/not-sensitive//')
.expect('/not-sensitive', done);
});
it('should support multiple methods settings as a string.', done => {
const app = express();
app.use(resolvePath({ methods: 'GET POST' }));
app.post('/method', (req, res) => res.send(req.url));
request(app)
.post('//method//?type=string&multiple=true')
.expect('/method?type=string&multiple=true', done);
});
it('should support an array of allowed methods.', done => {
const app = express();
app.use(resolvePath({ methods: ['GET', 'POST'] }));
app.post('/method', (req, res) => res.send(req.url));
request(app)
.post('//method//?type=array')
.expect('/method?type=array', done);
});
});