-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for undocumented endpoint on Router
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as express from 'express'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { OpenApiValidator } from '../src'; | ||
|
||
describe('security.defaults', () => { | ||
let app = express(); | ||
let basePath = '/api'; | ||
let server = null; | ||
|
||
before(async () => { | ||
const router = express.Router(); | ||
await new OpenApiValidator({ | ||
apiSpec: { | ||
openapi: '3.0.0', | ||
info: { version: '1.0.0', title: 'test bug OpenApiValidator' }, | ||
servers: [{ url: 'http://localhost:8080/api/' }], | ||
paths: { | ||
'/': { get: { responses: { 200: { description: 'home api' } } } }, | ||
}, | ||
}, | ||
}).install(router); | ||
|
||
router.get('/', (req, res) => res.status(200).send('home api\n')); | ||
router.get('/notDefined', (req, res) => | ||
res.status(200).send('url api not defined\n'), | ||
); | ||
|
||
app.get('/', (req, res) => res.status(200).send('home\n')); | ||
app.use(basePath, router); | ||
|
||
app.use((err, req, res, next) => { | ||
// console.error(err); | ||
res.status(err.status ?? 500).json({ | ||
message: err.message, | ||
errors: err.errors, | ||
}); | ||
}); | ||
|
||
server = app.listen(3000); | ||
console.log('server start port 3000'); | ||
}); | ||
|
||
after(async () => server.close()); | ||
|
||
it('should return 404 for undocumented route when using Router', async () => { | ||
return request(app) | ||
.get(`${basePath}/notDefined`) | ||
.expect(404) | ||
.then((r) => { | ||
expect(r.body).to.have.property('message').that.equals('not found'); | ||
}); | ||
}); | ||
}); |