Open History to see the last commit
1import { DEFAULT_SERVER_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
3import { describe, expect, it } from "vite-plus/test";
4
5import { settingInheritanceLayers } from "./SettingInheritance";
6
7const environmentId = EnvironmentId.make("laptop");
8const projectId = ProjectId.make("project");
9
10describe("settingInheritanceLayers", () => {
11 it("marks the built-in default effective when nothing is set", () => {
12 const resolved = resolveProjectSettings(DEFAULT_SERVER_SETTINGS, null);
13 const layers = settingInheritanceLayers(
14 { environmentId, label: "Laptop", projectId: null, ...resolved },
15 DEFAULT_SERVER_SETTINGS,
16 "defaultAutoPull",
17 );
18 expect(layers.map((layer) => [layer.label, layer.value, layer.effective])).toEqual([
19 ["Laptop", "Inherits", false],
20 ["Default", "Off", true],
21 ]);
22 });
23
24 it("walks project override, environment value, then built-in default", () => {
25 const settings = {
26 ...DEFAULT_SERVER_SETTINGS,
27 defaultAutoPull: true,
28 projectSettingsOverrides: { [projectId]: { defaultAutoPull: false } },
29 };
30 const resolved = resolveProjectSettings(settings, projectId);
31 const layers = settingInheritanceLayers(
32 { environmentId, label: "Laptop", projectId, ...resolved },
33 settings,
34 "defaultAutoPull",
35 );
36 expect(layers.map((layer) => [layer.label, layer.value, layer.effective])).toEqual([
37 ["Project", "Off", true],
38 ["Laptop", "On", false],
39 ["Default", "Off", false],
40 ]);
41 const inherited = settingInheritanceLayers(
42 {
43 environmentId,
44 label: "Laptop",
45 projectId,
46 ...resolveProjectSettings(settings, ProjectId.make("other")),
47 },
48 settings,
49 "defaultAutoPull",
50 );
51 expect(inherited.map((layer) => [layer.value, layer.effective])).toEqual([
52 ["Inherits", false],
53 ["On", true],
54 ["Off", false],
55 ]);
56 });
57});