Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu committed Jan 17, 2022
1 parent 5fdbe7d commit 6219268
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/controllers/tests/generator.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('GeneratorController', () => {
const app = new App([new GenerateController()]);

return await request(app.getServer())
.post('/generate')
.post('/v1/generate')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand All @@ -33,7 +33,7 @@ describe('GeneratorController', () => {
const app = new App([new GenerateController()]);

return await request(app.getServer())
.post('/generate')
.post('/v1/generate')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand All @@ -52,7 +52,7 @@ describe('GeneratorController', () => {
const app = new App([new GenerateController()]);

return await request(app.getServer())
.post('/generate')
.post('/v1/generate')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand Down
4 changes: 3 additions & 1 deletion src/middlewares/request-body-validation.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const ajv = new Ajv({
* Retrieve proper AJV's validator function, create or reuse it.
*/
async function getValidator(req: Request) {
const { path: reqPath, method } = req;
const method = req.method;
let reqPath = req.path;
reqPath = reqPath.startsWith('/v1') ? reqPath.replace('/v1', '') : reqPath;
const schemaName = `${reqPath}->${method}`;

const validate = ajv.getSchema(schemaName);
Expand Down
6 changes: 3 additions & 3 deletions src/middlewares/tests/document-validation.middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('documentValidationMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/test')
.post('/v1/test')
.send({})
.expect(200, {
success: true,
Expand All @@ -40,7 +40,7 @@ describe('documentValidationMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/test')
.post('/v1/test')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('documentValidationMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/test')
.post('/v1/test')
.send({
// without title, version and channels
asyncapi: {
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/tests/problem.middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('problemMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/test')
.post('/v1/test')
.send({})
.expect(422, {
type: ProblemException.createType('custom-problem'),
Expand All @@ -43,7 +43,7 @@ describe('problemMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/test')
.post('/v1/test')
.send({})
.expect(200, {
success: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('requestBodyValidationMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/generate')
.post('/v1/generate')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand All @@ -39,7 +39,7 @@ describe('requestBodyValidationMiddleware', () => {

it('should throw error when request body is invalid', async () => {
const TestController = createTestController({
path: '/test',
path: '/generate',
method: 'post',
callback: (_, res) => {
res.status(200).send({ success: true });
Expand All @@ -48,7 +48,7 @@ describe('requestBodyValidationMiddleware', () => {
const app = new App([new TestController()]);

return await request(app.getServer())
.post('/generate')
.post('/v1/generate')
.send({
asyncapi: {
asyncapi: '2.2.0',
Expand Down

0 comments on commit 6219268

Please sign in to comment.