Open History to see the last commit
1import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";
2import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
3import { describe, expect, it } from "vite-plus/test";
4
5import { sourceIdFromUrl } from "./AddUsageLimitSourceDialog.logic";
6
7describe("adding usage limit sources", () => {
8 it.each([
9 ["http://proxy.test:8318/hub-a", "http://proxy.test:8318/hub-b"],
10 ["localhost:8318", "localhost:9318"],
11 ])("retains saved configurations for %s and %s", (firstUrl, secondUrl) => {
12 let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
13 const sources = [
14 [firstUrl, "First hub", "first-key"],
15 [secondUrl, "Second hub", "second-key"],
16 [`${secondUrl}/extra`, "Third hub", "third-key"],
17 ] as const;
18 for (const [url, label, managementKey] of sources) {
19 const id = sourceIdFromUrl(url, settings.usageLimitSources);
20 settings = applyServerSettingsPatch(settings, {
21 usageLimitSources: {
22 [id]: { kind: "cliproxy", url, label, managementKey, enabled: true },
23 },
24 });
25 }
26 expect(Object.values(settings.usageLimitSources)).toEqual(
27 sources.map(([url, label, managementKey]) => ({
28 kind: "cliproxy",
29 url,
30 label,
31 managementKey,
32 enabled: true,
33 })),
34 );
35 });
36
37 it("updates a saved hub when its URL is added again", () => {
38 let settings: ServerSettings = DEFAULT_SERVER_SETTINGS;
39 for (const managementKey of ["old-key", "new-key"]) {
40 const url = "http://proxy.test:8318/hub-a";
41 settings = applyServerSettingsPatch(settings, {
42 usageLimitSources: {
43 [sourceIdFromUrl(url, settings.usageLimitSources)]: {
44 kind: "cliproxy",
45 url,
46 managementKey,
47 enabled: true,
48 },
49 },
50 });
51 }
52 expect(Object.values(settings.usageLimitSources)).toEqual([
53 {
54 kind: "cliproxy",
55 url: "http://proxy.test:8318/hub-a",
56 managementKey: "new-key",
57 enabled: true,
58 },
59 ]);
60 });
61});