From 4dbba4cfc51c1d0281c47105a9d4d520574910cf Mon Sep 17 00:00:00 2001 From: Taehyun Lee <0417taehyun@gmail.com> Date: Wed, 13 Nov 2024 19:32:04 +0900 Subject: [PATCH] Remove idNumberMiddleware --- .../middleware/id-number-middleware.test.ts | 32 ------------------- src/lib/middleware/id-number-middleware.ts | 16 ---------- 2 files changed, 48 deletions(-) delete mode 100644 src/lib/middleware/id-number-middleware.test.ts delete mode 100644 src/lib/middleware/id-number-middleware.ts diff --git a/src/lib/middleware/id-number-middleware.test.ts b/src/lib/middleware/id-number-middleware.test.ts deleted file mode 100644 index f3310799c726..000000000000 --- a/src/lib/middleware/id-number-middleware.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import express from 'express'; -import supertest from 'supertest'; -import idNumberMiddleware from './id-number-middleware'; - -describe('idNumberMiddleware', () => { - it('should pass when id is a valid integer', async () => { - const app = express(); - app.use('/:id', idNumberMiddleware()); - app.get('/:id', (req, res) => { - res.status(200).send('Valid ID'); - }); - - await supertest(app) - .get('/123') - .expect(200) - .expect((res) => { - expect(res.text).toBe('Valid ID'); - }); - }); - it('should throw BadDataError when id is not a valid integer', async () => { - const app = express(); - app.use('/:id', idNumberMiddleware()); - app.get('/:id', (req, res) => { - res.status(200).send('This should not be executed'); - }); - - const { body } = await supertest(app).get('/abc').expect(400); - expect(body).toMatchObject({ - details: [{ message: 'ID should be an integer' }], - }); - }); -}); diff --git a/src/lib/middleware/id-number-middleware.ts b/src/lib/middleware/id-number-middleware.ts deleted file mode 100644 index c5200e07927c..000000000000 --- a/src/lib/middleware/id-number-middleware.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { BadDataError } from '../error'; - -const idNumberMiddleware = (): any => { - return async (req, res, next) => { - const { id } = req.params; - if (!Number.isInteger(Number(id))) { - res.status(400).send( - new BadDataError('ID should be an integer').toJSON(), - ); - return; - } - next(); - }; -}; - -export default idNumberMiddleware;