-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrouter.test.ts
More file actions
79 lines (67 loc) · 2.57 KB
/
router.test.ts
File metadata and controls
79 lines (67 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describe, expect, it } from "bun:test";
import sflow from "sflow";
describe("getRepoUrls filter logic", () => {
it("should filter out non-string and empty repository values", async () => {
// Mock data similar to what CNRepos.find() might return
const mockData = [
{ repository: "https://github.com/user/repo1" },
{ repository: "https://github.com/user/repo2" },
{ repository: "" },
{ repository: undefined },
{ repository: null },
{ repository: "https://github.com/user/repo3" },
];
const result = await sflow(mockData)
.map((e) => (e as unknown as { repository: string }).repository)
.filter((repo) => typeof repo === "string" && repo.length > 0)
.toArray();
expect(result).toEqual([
"https://github.com/user/repo1",
"https://github.com/user/repo2",
"https://github.com/user/repo3",
]);
});
it("should handle all invalid values", async () => {
const mockData = [{ repository: "" }, { repository: undefined }, { repository: null }];
const result = await sflow(mockData)
.map((e) => (e as unknown as { repository: string }).repository)
.filter((repo) => typeof repo === "string" && repo.length > 0)
.toArray();
expect(result).toEqual([]);
});
it("should handle all valid values", async () => {
const mockData = [
{ repository: "https://github.com/user/repo1" },
{ repository: "https://github.com/user/repo2" },
{ repository: "https://github.com/user/repo3" },
];
const result = await sflow(mockData)
.map((e) => (e as unknown as { repository: string }).repository)
.filter((repo) => typeof repo === "string" && repo.length > 0)
.toArray();
expect(result).toEqual([
"https://github.com/user/repo1",
"https://github.com/user/repo2",
"https://github.com/user/repo3",
]);
});
});
describe("getRepoUrls pagination", () => {
it("should validate skip parameter is non-negative", () => {
// The zod schema should enforce skip >= 0
const schema = { skip: { min: 0 } };
expect(schema.skip.min).toBe(0);
});
it("should validate limit parameter range", () => {
// The zod schema should enforce 1 <= limit <= 5000
const schema = { limit: { min: 1, max: 5000 } };
expect(schema.limit.min).toBe(1);
expect(schema.limit.max).toBe(5000);
});
it("should have default values for skip and limit", () => {
// Default values: skip=0, limit=1000
const defaults = { skip: 0, limit: 1000 };
expect(defaults.skip).toBe(0);
expect(defaults.limit).toBe(1000);
});
});