-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
wildcard.path.params.spec.ts
86 lines (77 loc) 路 2.27 KB
/
wildcard.path.params.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
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
import * as path from 'path';
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './common/app';
describe('wildcard path params', () => {
let app = null;
before(async () => {
const apiSpec = path.join('test', 'resources', 'wildcard.path.params.yaml');
app = await createApp(
{
apiSpec,
},
3001,
(app) => {
app
.get(`${app.basePath}/d1/:id`, (req, res) =>
res.json({
...req.params,
}),
)
.get(`${app.basePath}/d2/:path(*)`, (req, res) =>
res.json({
...req.params,
}),
)
.get(`${app.basePath}/d3/:path(*)`, (req, res) =>
res.json({
...req.params,
}),
)
.get(`${app.basePath}/d3`, (req, res) =>
res.json({
success: true,
}),
);
},
);
});
after(() => app.server.close());
it('should allow path param without wildcard', async () =>
request(app)
.get(`${app.basePath}/d1/my-id`)
.expect(200)
.then((r) => {
expect(r.body.id).to.equal('my-id');
}));
it('should allow path param with slashes "/" using wildcard', async () =>
request(app)
.get(`${app.basePath}/d2/some/long/path`)
.expect(200)
.then((r) => {
expect(r.body.path).to.equal('some/long/path');
}));
it('should return not found if no path is specified', async () =>
request(app).get(`${app.basePath}/d2`).expect(404));
it('should return 200 when wildcard path includes all required params', async () =>
request(app)
.get(`${app.basePath}/d3/long/path/file.csv`)
.query({
qp: 'present',
})
.expect(200));
it('should 400 when wildcard path is missing a required query param', async () =>
request(app)
.get(`${app.basePath}/d3/long/path/file.csv`)
.expect(400)
.then((r) => {
expect(r.body.message).to.include('required');
}));
it('should return 200 if root of an existing wildcard route is defined', async () =>
request(app)
.get(`${app.basePath}/d3`)
.expect(200)
.then((r) => {
expect(r.body.success).to.be.true;
}));
});