Skip to content

Commit 35134cd

Browse files
committed
Tests for client methods and todo for AuxMethod type.
1 parent daa2da6 commit 35134cd

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

express-zod-api/src/method.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type Method = (typeof methods)[number];
1717
/**
1818
* @desc Additional methods having some technical handling in the framework
1919
* @see makeCorsHeaders
20+
* @todo consider removing it and introducing CORSMethod = ClientMethod | "options"
2021
* */
2122
export type AuxMethod = Extract<keyof IRouter, "options" | "head">;
2223

express-zod-api/tests/method.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import * as R from "ramda";
2-
import { isMethod, methods, Method, AuxMethod } from "../src/method";
2+
import {
3+
isMethod,
4+
methods,
5+
Method,
6+
AuxMethod,
7+
clientMethods,
8+
ClientMethod,
9+
} from "../src/method";
10+
import { describe } from "node:test";
311

412
describe("Method", () => {
513
describe("methods array", () => {
@@ -8,6 +16,19 @@ describe("Method", () => {
816
});
917
});
1018

19+
describe("clientMethods array", () => {
20+
test("should be same methods and the head", () => {
21+
expect(clientMethods).toEqual([
22+
"get",
23+
"post",
24+
"put",
25+
"delete",
26+
"patch",
27+
"head",
28+
]);
29+
});
30+
});
31+
1132
describe("the type", () => {
1233
test("should match the entries of the methods array", () => {
1334
expectTypeOf<"get">().toExtend<Method>();
@@ -19,6 +40,18 @@ describe("Method", () => {
1940
});
2041
});
2142

43+
describe("ClientMethod type", () => {
44+
test("should match the entries of the methods array", () => {
45+
expectTypeOf<"get">().toExtend<ClientMethod>();
46+
expectTypeOf<"post">().toExtend<ClientMethod>();
47+
expectTypeOf<"put">().toExtend<ClientMethod>();
48+
expectTypeOf<"delete">().toExtend<ClientMethod>();
49+
expectTypeOf<"patch">().toExtend<ClientMethod>();
50+
expectTypeOf<"head">().toExtend<ClientMethod>();
51+
expectTypeOf<"wrong">().not.toExtend<ClientMethod>();
52+
});
53+
});
54+
2255
describe("AuxMethod", () => {
2356
test("should be options or head", () => {
2457
expectTypeOf<"options">().toExtend<AuxMethod>();

0 commit comments

Comments
 (0)