| 1 | import { DEFAULT_SERVER_SETTINGS, ProjectId, type ServerSettings } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { findOrphanedProjectIds } from "./ProjectSettingsOverrideSweep.ts"; |
| 5 | |
| 6 | const liveProjectId = ProjectId.make("project-live"); |
| 7 | const deletedProjectId = ProjectId.make("project-deleted"); |
| 8 | |
| 9 | function settingsWith(overrides: Partial<ServerSettings>): ServerSettings { |
| 10 | return { ...DEFAULT_SERVER_SETTINGS, ...overrides }; |
| 11 | } |
| 12 | |
| 13 | describe("findOrphanedProjectIds", () => { |
| 14 | it("reports a project override whose project is no longer live", () => { |
| 15 | const settings = settingsWith({ |
| 16 | projectSettingsOverrides: { |
| 17 | [liveProjectId]: { providerInstances: {} }, |
| 18 | [deletedProjectId]: { providerInstances: {} }, |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | const orphaned = findOrphanedProjectIds(settings, new Set([liveProjectId])); |
| 23 | |
| 24 | expect(orphaned).toEqual([deletedProjectId]); |
| 25 | }); |
| 26 | |
| 27 | it("reports nothing when every override's project is still live", () => { |
| 28 | const settings = settingsWith({ |
| 29 | projectSettingsOverrides: { |
| 30 | [liveProjectId]: { providerInstances: {} }, |
| 31 | }, |
| 32 | }); |
| 33 | |
| 34 | const orphaned = findOrphanedProjectIds(settings, new Set([liveProjectId])); |
| 35 | |
| 36 | expect(orphaned).toEqual([]); |
| 37 | }); |
| 38 | |
| 39 | it("reports nothing when there are no overrides at all", () => { |
| 40 | const settings = settingsWith({ projectSettingsOverrides: {} }); |
| 41 | |
| 42 | const orphaned = findOrphanedProjectIds(settings, new Set([liveProjectId])); |
| 43 | |
| 44 | expect(orphaned).toEqual([]); |
| 45 | }); |
| 46 | }); |