From 97158fd070620e328c9d43fcdb3fb5c01010946c Mon Sep 17 00:00:00 2001 From: carmine Date: Fri, 27 Dec 2024 19:26:43 -0500 Subject: [PATCH] fix test --- test/1022.spec.ts | 71 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/test/1022.spec.ts b/test/1022.spec.ts index a28cac8a..0c770fa9 100644 --- a/test/1022.spec.ts +++ b/test/1022.spec.ts @@ -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; @@ -63,12 +63,12 @@ describe(packageJson.name, () => { required: ['id'], properties: { id: { - type: 'integer' - } - } - } - } - } + type: 'integer', + }, + }, + }, + }, + }, }, responses: { '200': { @@ -88,6 +88,26 @@ describe(packageJson.name, () => { }, }, }, + + '/some/{wildcard}*': { + parameters: [ + { + name: 'wildcard', + in: 'path', + required: true, + schema: { + type: 'string', + }, + }, + ], + get: { + responses: { + '200': { + description: 'OK', + }, + }, + }, + }, }, }; @@ -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}`); + }), ), ); }); @@ -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)); });