-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathduplicateTaskIds.test.ts
More file actions
55 lines (45 loc) · 1.99 KB
/
Copy pathduplicateTaskIds.test.ts
File metadata and controls
55 lines (45 loc) · 1.99 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
import { describe, it, expect } from "vitest";
import { ServiceValidationError } from "~/v3/services/common.server";
import { assertNoDuplicateTaskIds } from "~/v3/services/duplicateTaskIds.server";
function task(partial: { id: string; filePath?: string; exportName?: string; triggerSource?: string }) {
return {
filePath: "src/trigger/example.ts",
exportName: "exampleTask",
...partial,
} as any;
}
describe("assertNoDuplicateTaskIds", () => {
it("does not throw when all task ids are unique", () => {
const tasks = [task({ id: "a" }), task({ id: "b" }), task({ id: "c" })];
expect(() => assertNoDuplicateTaskIds(tasks)).not.toThrow();
});
it("throws a ServiceValidationError when a task id is duplicated", () => {
const tasks = [task({ id: "a" }), task({ id: "a" })];
expect(() => assertNoDuplicateTaskIds(tasks)).toThrow(ServiceValidationError);
});
it("reports a 400 and names the duplicate id and its files", () => {
const tasks = [
task({ id: "report", filePath: "src/trigger/report.ts" }),
task({ id: "report", filePath: "src/trigger/scheduled.ts" }),
];
let error: unknown;
try {
assertNoDuplicateTaskIds(tasks);
} catch (e) {
error = e;
}
expect(error).toBeInstanceOf(ServiceValidationError);
const validationError = error as ServiceValidationError;
expect(validationError.status).toBe(400);
expect(validationError.message).toContain("report");
expect(validationError.message).toContain("src/trigger/report.ts");
expect(validationError.message).toContain("src/trigger/scheduled.ts");
});
it("detects duplicates across different task types (a schedule and a regular task sharing an id)", () => {
const tasks = [
task({ id: "report", triggerSource: undefined, filePath: "src/trigger/report.ts" }),
task({ id: "report", triggerSource: "schedule", filePath: "src/trigger/scheduled.ts" }),
];
expect(() => assertNoDuplicateTaskIds(tasks)).toThrow(ServiceValidationError);
});
});