Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settings-scoped-server.test.ts

94 lines3.0 KB

1import {
2 DEFAULT_SERVER_SETTINGS,
3 type EnvironmentId,
4 type ProjectId,
5 type ServerSettings,
6} from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8​
9import type { SettingsTarget } from "./settings-environment-filter";
10import {
11 planMobileScopedSettingsClear,
12 planMobileScopedSettingsPatch,
13 resolveMobileSettingsTargets,
14} from "./settings-scoped-server";
15​
16const firstId = "first" as EnvironmentId;
17const secondId = "second" as EnvironmentId;
18const firstProject = "first-project" as ProjectId;
19const secondProject = "second-project" as ProjectId;
20​
21function environment(environmentId: EnvironmentId, settings: ServerSettings): SettingsTarget {
22 return {
23 environmentId,
24 serverConfig: {
25 settings,
26 environment: { capabilities: { projectSettingsOverrides: true } },
27 },
28 } as SettingsTarget;
30​
31describe("mobile project settings scope", () => {
32 it("edits each checkout's own override without changing either environment default", () => {
33 const firstSettings: ServerSettings = {
34 ...DEFAULT_SERVER_SETTINGS,
35 responseStreamingMode: "paragraph",
36 projectSettingsOverrides: { [firstProject]: { defaultAutoPull: true } },
37 };
38 const secondSettings: ServerSettings = {
39 ...DEFAULT_SERVER_SETTINGS,
40 responseStreamingMode: "token",
41 projectSettingsOverrides: {},
42 };
43 const targets = resolveMobileSettingsTargets(
44 [environment(firstId, firstSettings), environment(secondId, secondSettings)],
45 [
46 { environmentId: firstId, id: firstProject },
47 { environmentId: secondId, id: secondProject },
48 ],
49 );
50​
51 const writes = planMobileScopedSettingsPatch(targets, true, {
52 responseStreamingMode: "turn",
53 });
54 expect(writes).toEqual([
55 {
56 environmentId: firstId,
57 patch: {
58 projectSettingsOverrides: {
59 [firstProject]: { defaultAutoPull: true, responseStreamingMode: "turn" },
60 },
61 },
62 },
63 {
64 environmentId: secondId,
65 patch: { projectSettingsOverrides: { [secondProject]: { responseStreamingMode: "turn" } } },
66 },
67 ]);
68 expect(firstSettings.responseStreamingMode).toBe("paragraph");
69 expect(secondSettings.responseStreamingMode).toBe("token");
70 });
71​
72 it("resets only the selected page's override and rejects environment-wide writes", () => {
73 const settings: ServerSettings = {
74 ...DEFAULT_SERVER_SETTINGS,
75 projectSettingsOverrides: {
76 [firstProject]: { defaultAutoPull: true, responseStreamingMode: "turn" },
77 },
78 };
79 const targets = resolveMobileSettingsTargets(
80 [environment(firstId, settings)],
81 [{ environmentId: firstId, id: firstProject }],
82 );
83​
84 expect(planMobileScopedSettingsClear(targets, ["responseStreamingMode"])).toEqual([
85 {
86 environmentId: firstId,
87 patch: { projectSettingsOverrides: { [firstProject]: { defaultAutoPull: true } } },
88 },
89 ]);
90 expect(
91 planMobileScopedSettingsPatch(targets, true, { enableProviderUpdateChecks: false }),
92 ).toEqual([]);
93 });
94});