Repository navigation
Expand file tree
/
Copy pathAddUsageLimitSourceDialog.logic.test.ts
More file actions
61 lines (58 loc) · 2.03 KB
/
Copy pathAddUsageLimitSourceDialog.logic.test.ts
File metadata and controls
61 lines (58 loc) · 2.03 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
import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
import { describe, expect, it } from "vite-plus/test";
import { sourceIdFromUrl } from "./AddUsageLimitSourceDialog.logic";
describe("adding usage limit sources", () => {
it.each([
["http://proxy.test:8318/hub-a", "http://proxy.test:8318/hub-b"],
["localhost:8318", "localhost:9318"],
])("retains saved configurations for %s and %s", (firstUrl, secondUrl) => {
let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
const sources = [
[firstUrl, "First hub", "first-key"],
[secondUrl, "Second hub", "second-key"],
[`${secondUrl}/extra`, "Third hub", "third-key"],
] as const;
for (const [url, label, managementKey] of sources) {
const id = sourceIdFromUrl(url, settings.usageLimitSources);
settings = applyServerSettingsPatch(settings, {
usageLimitSources: {
[id]: { kind: "cliproxy", url, label, managementKey, enabled: true },
},
});
}
expect(Object.values(settings.usageLimitSources)).toEqual(
sources.map(([url, label, managementKey]) => ({
kind: "cliproxy",
url,
label,
managementKey,
enabled: true,
})),
);
});
it("updates a saved hub when its URL is added again", () => {
let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
for (const managementKey of ["old-key", "new-key"]) {
const url = "http://proxy.test:8318/hub-a";
settings = applyServerSettingsPatch(settings, {
usageLimitSources: {
[sourceIdFromUrl(url, settings.usageLimitSources)]: {
kind: "cliproxy",
url,
managementKey,
enabled: true,
},
},
});
}
expect(Object.values(settings.usageLimitSources)).toEqual([
{
kind: "cliproxy",
url: "http://proxy.test:8318/hub-a",
managementKey: "new-key",
enabled: true,
},
]);
});
});