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

Commit

Permalink
feat: Add route options
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Dec 30, 2020
1 parent 0d7a133 commit d91ae38
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 127 deletions.
108 changes: 108 additions & 0 deletions __tests__/options.test.ts
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({});
});
114 changes: 57 additions & 57 deletions benchmarks/README.md

Large diffs are not rendered by default.

48 changes: 17 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foxify/router",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Foxify Router",
"homepage": "https://github.com/foxifyjs/router#readme",
"repository": {
Expand All @@ -10,6 +10,9 @@
"bugs": {
"url": "https://github.com/foxifyjs/router/issues"
},
"funding": {
"url": "https://opencollective.com/foxify"
},
"license": "MIT",
"author": {
"name": "Ardalan Amini",
Expand Down Expand Up @@ -39,6 +42,10 @@
"@foxify/http": "^1",
"prototyped.js": "^1"
},
"dependencies": {
"escape-html": "^1.0.3",
"fast-json-stringify": "^1.21.0"
},
"devDependencies": {
"@foxify/http": "^1.0.0-beta.2",
"@foxify/inject": "^1.1.0",
Expand All @@ -54,8 +61,5 @@
},
"workspaces": [
"benchmarks"
],
"dependencies": {
"escape-html": "^1.0.3"
}
]
}
Loading

0 comments on commit d91ae38

Please sign in to comment.