Skip to content

Commit d6fda56

Browse files
fix: add tests for .all() routes
1 parent 1a78ff0 commit d6fda56

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/index.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,31 @@ describe('Swagger', () => {
219219
expect(response.paths['/public']).not.toBeUndefined();
220220
expect(response.paths['/hidden']).toBeUndefined();
221221
})
222+
223+
it('should expand .all routes', async () => {
224+
const app = new Elysia().use(swagger())
225+
.all("/all", "woah")
226+
227+
await app.modules
228+
229+
const res = await app.handle(req('/swagger/json'))
230+
expect(res.status).toBe(200)
231+
const response = await res.json()
232+
expect(Object.keys(response.paths['/all'])).toBeArrayOfSize(8)
233+
})
234+
235+
it('should hide routes that are invalid', async () => {
236+
const app = new Elysia().use(swagger())
237+
.get("/valid", "ok")
238+
.route("LOCK", "/invalid", "nope")
239+
240+
await app.modules
241+
242+
const res = await app.handle(req('/swagger/json'))
243+
expect(res.status).toBe(200)
244+
const response = await res.json()
245+
expect(response.paths['/valid']).not.toBeUndefined();
246+
expect(response.paths['/invalid']).toBeUndefined();
247+
248+
})
222249
})

test/validate-schema.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ it('returns a valid Swagger/OpenAPI json config for many routes', async () => {
7777
)
7878
}
7979
)
80+
.route('LOCK', '/lock', () => 'locked')
8081

8182
await app.modules
8283

0 commit comments

Comments
 (0)