-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathconfig.spec.ts
More file actions
99 lines (76 loc) · 2.87 KB
/
config.spec.ts
File metadata and controls
99 lines (76 loc) · 2.87 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
describe("config", () => {
const originalEnv = process.env;
beforeEach(() => {
vi.resetModules();
process.env = { ...originalEnv };
});
afterEach(() => {
process.env = originalEnv;
});
describe("validateEnv", () => {
it("exits when CONVEX_URL is missing", async () => {
delete process.env.CONVEX_URL;
process.env.AGENCY_URL = "http://localhost:18789";
process.env.AGENCY_TOKEN = "test-token";
const mockExit = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
const mockError = vi.spyOn(console, "error").mockImplementation(() => {});
const { validateEnv } = await import("./config.js");
validateEnv();
expect(mockError).toHaveBeenCalledWith(
expect.stringContaining("CONVEX_URL"),
);
expect(mockExit).toHaveBeenCalledWith(1);
mockExit.mockRestore();
mockError.mockRestore();
});
it("exits when AGENCY_URL is missing", async () => {
process.env.CONVEX_URL = "https://test.convex.cloud";
delete process.env.AGENCY_URL;
process.env.AGENCY_TOKEN = "test-token";
const mockExit = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
const mockError = vi.spyOn(console, "error").mockImplementation(() => {});
const { validateEnv } = await import("./config.js");
validateEnv();
expect(mockError).toHaveBeenCalledWith(
expect.stringContaining("AGENCY_URL"),
);
expect(mockExit).toHaveBeenCalledWith(1);
mockExit.mockRestore();
mockError.mockRestore();
});
it("does not exit when all required vars are set", async () => {
process.env.CONVEX_URL = "https://test.convex.cloud";
process.env.AGENCY_URL = "http://localhost:18789";
process.env.AGENCY_TOKEN = "test-token";
const mockExit = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
const { validateEnv } = await import("./config.js");
validateEnv();
expect(mockExit).not.toHaveBeenCalled();
mockExit.mockRestore();
});
});
describe("config object", () => {
it("has correct default values", async () => {
process.env.CONVEX_URL = "https://test.convex.cloud";
process.env.AGENCY_URL = "http://custom:8080";
process.env.AGENCY_TOKEN = "my-token";
const { config } = await import("./config.js");
expect(config.convexUrl).toBe("https://test.convex.cloud");
expect(config.agencyUrl).toBe("http://custom:8080");
expect(config.agencyToken).toBe("my-token");
});
});
describe("POLL_INTERVAL_MS", () => {
it("is set to 2000ms", async () => {
const { POLL_INTERVAL_MS } = await import("./config.js");
expect(POLL_INTERVAL_MS).toBe(2000);
});
});
});