Skip to content

Commit c096b70

Browse files
committed
chore(test): Add tests for helpers of LogicalContainer.
1 parent 3e7482b commit c096b70

2 files changed

Lines changed: 80 additions & 4 deletions

File tree

express-zod-api/src/logical-container.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ export type LogicalContainer<T> =
99
| LogicalAnd<T | LogicalOr<T>>
1010
| T;
1111

12-
const isLogicalOr = <T>(subject: LogicalContainer<T>) =>
12+
/** @internal */
13+
export const isLogicalOr = <T>(subject: LogicalContainer<T>) =>
1314
isObject(subject) && "or" in subject;
1415

15-
const isLogicalAnd = <T>(subject: LogicalContainer<T>) =>
16+
/** @internal */
17+
export const isLogicalAnd = <T>(subject: LogicalContainer<T>) =>
1618
isObject(subject) && "and" in subject;
1719

18-
const isSimple = <T>(entry: LogicalContainer<T>): entry is T =>
20+
/** @internal */
21+
export const isSimple = <T>(entry: LogicalContainer<T>): entry is T =>
1922
!isLogicalAnd(entry) && !isLogicalOr(entry);
2023

2124
type Combination<T> = T[];

express-zod-api/tests/logical-container.spec.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,79 @@
1-
import { processContainers } from "../src/logical-container";
1+
import {
2+
isLogicalOr,
3+
isLogicalAnd,
4+
isSimple,
5+
processContainers,
6+
} from "../src/logical-container";
27

38
describe("LogicalContainer", () => {
9+
describe("isLogicalOr()", () => {
10+
test.each([
11+
true,
12+
false,
13+
0,
14+
1,
15+
"",
16+
"test",
17+
null,
18+
undefined,
19+
[],
20+
[1],
21+
{},
22+
{ and: [] },
23+
])("should return false when has no 'or' property %#", (value) => {
24+
expect(isLogicalOr(value)).toBe(false);
25+
});
26+
27+
test.each([{ or: [] }, { or: [1] }, { or: [1, 2, 3] }])(
28+
"should return true for object with 'or' property %#",
29+
(value) => {
30+
expect(isLogicalOr(value)).toBe(true);
31+
},
32+
);
33+
});
34+
35+
describe("isLogicalAnd()", () => {
36+
test.each([
37+
true,
38+
false,
39+
0,
40+
1,
41+
"",
42+
"test",
43+
null,
44+
undefined,
45+
[],
46+
[1],
47+
{},
48+
{ or: [] },
49+
])("should return false when has no 'and' property %#", (value) => {
50+
expect(isLogicalAnd(value)).toBe(false);
51+
});
52+
53+
test.each([{ and: [] }, { and: [1] }, { and: [1, 2, 3] }])(
54+
"should return true for object with 'and' property %#",
55+
(value) => {
56+
expect(isLogicalAnd(value)).toBe(true);
57+
},
58+
);
59+
});
60+
61+
describe("isSimple()", () => {
62+
test.each([true, false, 0, 1, "", "test", null, undefined, [], [1], {}])(
63+
"should return true for non-logical values %#",
64+
(value) => {
65+
expect(isSimple(value)).toBe(true);
66+
},
67+
);
68+
69+
test.each([{ or: [] }, { or: [1] }, { and: [] }, { and: [1] }])(
70+
"should return false for logical containers %#",
71+
(value) => {
72+
expect(isSimple(value)).toBe(false);
73+
},
74+
);
75+
});
76+
477
describe("processContainers()", () => {
578
test("should process simples", () => {
679
expect(processContainers([1])).toEqual([[1]]);

0 commit comments

Comments
 (0)