This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d7a133
commit d91ae38
Showing
8 changed files
with
343 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Router from "../src"; | ||
|
||
it("should return the empty options", () => { | ||
const router = new Router(); | ||
|
||
const method = "GET"; | ||
const path = "/"; | ||
const handler = jest.fn(); | ||
|
||
router.on(method, path, handler); | ||
|
||
const params = {}; | ||
|
||
const { handlers, allowHeader, options } = router.find("POST", path, params); | ||
|
||
expect(handlers).toBeUndefined(); | ||
expect(allowHeader).toBe(method); | ||
expect(options).toBeUndefined(); | ||
expect(params).toEqual({}); | ||
}); | ||
|
||
it("should return the default options", () => { | ||
const router = new Router(); | ||
|
||
const method = "GET"; | ||
const path = "/"; | ||
const handler = jest.fn(); | ||
|
||
router.on(method, path, handler); | ||
|
||
const params = {}; | ||
|
||
const { handlers, allowHeader, options } = router.find(method, path, params); | ||
|
||
expect(handlers).toEqual([handler]); | ||
expect(allowHeader).toBe(method); | ||
expect(options).toEqual({ schema: { response: {} } }); | ||
expect(params).toEqual({}); | ||
}); | ||
|
||
it("should return the correct options", () => { | ||
const router = new Router(); | ||
|
||
const method = "GET"; | ||
const path = "/"; | ||
const handler = jest.fn(); | ||
|
||
router.on( | ||
method, | ||
path, | ||
{ | ||
schema: { | ||
response: { | ||
200: { | ||
type: "string", | ||
title: "Example Schema with string date-time field", | ||
}, | ||
}, | ||
}, | ||
}, | ||
handler, | ||
); | ||
|
||
const params = {}; | ||
|
||
const { handlers, allowHeader, options } = router.find(method, path, params); | ||
|
||
expect(handlers).toEqual([handler]); | ||
expect(allowHeader).toBe(method); | ||
expect(typeof options!.schema.response["200"]).toBe("function"); | ||
expect(params).toEqual({}); | ||
}); | ||
|
||
it("should respect sub-router options", () => { | ||
const router = new Router(); | ||
const subRouter = new Router(); | ||
|
||
const method = "GET"; | ||
const path = "/"; | ||
const handler = jest.fn(); | ||
|
||
subRouter.on( | ||
method, | ||
path, | ||
{ | ||
schema: { | ||
response: { | ||
200: { | ||
type: "string", | ||
title: "Example Schema with string date-time field", | ||
}, | ||
}, | ||
}, | ||
}, | ||
handler, | ||
); | ||
|
||
router.use(subRouter); | ||
|
||
const params = {}; | ||
|
||
const { handlers, allowHeader, options } = router.find(method, path, params); | ||
|
||
expect(handlers).toEqual([handler]); | ||
expect(allowHeader).toBe(method); | ||
expect(typeof options!.schema.response["200"]).toBe("function"); | ||
expect(params).toEqual({}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.