Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
carmine committed Dec 28, 2024
1 parent ecba075 commit 97158fd
Showing 1 changed file with 52 additions and 19 deletions.
71 changes: 52 additions & 19 deletions test/1022.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as request from 'supertest';
import { createApp } from './common/app';
import * as packageJson from '../package.json';
import { OpenAPIV3 } from '../src/framework/types';
import {expect} from "chai";
import { expect } from 'chai';

describe(packageJson.name, () => {
let app = null;
Expand Down Expand Up @@ -63,12 +63,12 @@ describe(packageJson.name, () => {
required: ['id'],
properties: {
id: {
type: 'integer'
}
}
}
}
}
type: 'integer',
},
},
},
},
},
},
responses: {
'200': {
Expand All @@ -88,6 +88,26 @@ describe(packageJson.name, () => {
},
},
},

'/some/{wildcard}*': {
parameters: [
{
name: 'wildcard',
in: 'path',
required: true,
schema: {
type: 'string',
},
},
],
get: {
responses: {
'200': {
description: 'OK',
},
},
},
},
},
};

Expand All @@ -102,8 +122,17 @@ describe(packageJson.name, () => {
app.use(
express
.Router()
.get(`/api/test/:id`, (req, res) => res.status(200).json({ id: 'id-test', label: 'label'}))
.post(`/api/test/:id:clone`, (req, res) => res.status(200).json({...req.body, id: 'id-test'})),
.get(`/api/test/:id`, (req, res) =>
res.status(200).json({ id: 'id-test', label: 'label' }),
)
.post(`/api/test/:id:clone`, (req, res) =>
res.status(200).json({ ...req.body, id: 'id-test' }),
)
.get('/api/some/:wildcard(*)', (req, res) => {
const wildcard = req.params.wildcard;
console.log(`Wildcard: ${wildcard}`);
res.status(200).send(`Matched wildcard: ${wildcard}`);
}),
),
);
});
Expand All @@ -112,19 +141,23 @@ describe(packageJson.name, () => {
app.server.close();
});

it('get /test/{id} should return 200', async () =>
it('GET /test/{id} should return 200', async () =>
request(app).get(`/api/test/abc123`).expect(200));

it('POST /test/{id}:clone should return 200', async () =>
request(app).post(`/api/test/abc123:clone`)
.send({ id: 10 })
.expect(200));
request(app).post(`/api/test/abc123:clone`).send({ id: 10 }).expect(200));

it('POST /test/{id}:clone should return 400', async () =>
request(app).post(`/api/test/abc123:clone`)
.send({ id: 'abc123' })
.expect(400)
.then(r => {
expect(r.body.message).to.include('id must be integer');
}));
request(app)
.post(`/api/test/abc123:clone`)
.send({ id: 'abc123' })
.expect(400)
.then((r) => {
expect(r.body.message).to.include('id must be integer');
}));

it('GET /some/test with wildcard should return 200', async () =>
request(app)
.get(`/api/some/test/stuff`)
.expect(200));
});

0 comments on commit 97158fd

Please sign in to comment.