Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit d91ae38

Browse files
committed
feat: Add route options
1 parent 0d7a133 commit d91ae38

File tree

8 files changed

+343
-127
lines changed

8 files changed

+343
-127
lines changed

__tests__/options.test.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import Router from "../src";
2+
3+
it("should return the empty options", () => {
4+
const router = new Router();
5+
6+
const method = "GET";
7+
const path = "/";
8+
const handler = jest.fn();
9+
10+
router.on(method, path, handler);
11+
12+
const params = {};
13+
14+
const { handlers, allowHeader, options } = router.find("POST", path, params);
15+
16+
expect(handlers).toBeUndefined();
17+
expect(allowHeader).toBe(method);
18+
expect(options).toBeUndefined();
19+
expect(params).toEqual({});
20+
});
21+
22+
it("should return the default options", () => {
23+
const router = new Router();
24+
25+
const method = "GET";
26+
const path = "/";
27+
const handler = jest.fn();
28+
29+
router.on(method, path, handler);
30+
31+
const params = {};
32+
33+
const { handlers, allowHeader, options } = router.find(method, path, params);
34+
35+
expect(handlers).toEqual([handler]);
36+
expect(allowHeader).toBe(method);
37+
expect(options).toEqual({ schema: { response: {} } });
38+
expect(params).toEqual({});
39+
});
40+
41+
it("should return the correct options", () => {
42+
const router = new Router();
43+
44+
const method = "GET";
45+
const path = "/";
46+
const handler = jest.fn();
47+
48+
router.on(
49+
method,
50+
path,
51+
{
52+
schema: {
53+
response: {
54+
200: {
55+
type: "string",
56+
title: "Example Schema with string date-time field",
57+
},
58+
},
59+
},
60+
},
61+
handler,
62+
);
63+
64+
const params = {};
65+
66+
const { handlers, allowHeader, options } = router.find(method, path, params);
67+
68+
expect(handlers).toEqual([handler]);
69+
expect(allowHeader).toBe(method);
70+
expect(typeof options!.schema.response["200"]).toBe("function");
71+
expect(params).toEqual({});
72+
});
73+
74+
it("should respect sub-router options", () => {
75+
const router = new Router();
76+
const subRouter = new Router();
77+
78+
const method = "GET";
79+
const path = "/";
80+
const handler = jest.fn();
81+
82+
subRouter.on(
83+
method,
84+
path,
85+
{
86+
schema: {
87+
response: {
88+
200: {
89+
type: "string",
90+
title: "Example Schema with string date-time field",
91+
},
92+
},
93+
},
94+
},
95+
handler,
96+
);
97+
98+
router.use(subRouter);
99+
100+
const params = {};
101+
102+
const { handlers, allowHeader, options } = router.find(method, path, params);
103+
104+
expect(handlers).toEqual([handler]);
105+
expect(allowHeader).toBe(method);
106+
expect(typeof options!.schema.response["200"]).toBe("function");
107+
expect(params).toEqual({});
108+
});

benchmarks/README.md

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 17 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foxify/router",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0-beta.2",
44
"description": "Foxify Router",
55
"homepage": "https://github.com/foxifyjs/router#readme",
66
"repository": {
@@ -10,6 +10,9 @@
1010
"bugs": {
1111
"url": "https://github.com/foxifyjs/router/issues"
1212
},
13+
"funding": {
14+
"url": "https://opencollective.com/foxify"
15+
},
1316
"license": "MIT",
1417
"author": {
1518
"name": "Ardalan Amini",
@@ -39,6 +42,10 @@
3942
"@foxify/http": "^1",
4043
"prototyped.js": "^1"
4144
},
45+
"dependencies": {
46+
"escape-html": "^1.0.3",
47+
"fast-json-stringify": "^1.21.0"
48+
},
4249
"devDependencies": {
4350
"@foxify/http": "^1.0.0-beta.2",
4451
"@foxify/inject": "^1.1.0",
@@ -54,8 +61,5 @@
5461
},
5562
"workspaces": [
5663
"benchmarks"
57-
],
58-
"dependencies": {
59-
"escape-html": "^1.0.3"
60-
}
64+
]
6165
}

0 commit comments

Comments
 (0)