* chore(merge): resolve conflicts, fix mockWs error, and apply refactor standards * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): Stabilize github actions and resolve test failures - fix(tests): update WsClient mock to use standard function for Vitest constructor compatibility - fix(db): correct PrismaClient import path to use generated output directory - fix(e2e): add predev database boot step to playwright CI workflow - chore: sync pnpm-lock.yaml after merge conflict resolution * refactor(plugins): decouple GeoJSON plugin and implement data bus lifecycle - feat(sdk): [Minor] Added dynamicPluginCreate, dynamicPluginRemove, and pluginUnregistered to DataBusEvents. - feat(core): [Minor] Implemented unregisterPlugin in PluginManager.ts for automated IndexedDB caching cleanup and polling teardown. - feat(core): [Minor] Added removeLayer to layersSlice.ts to support safe removal of plugin states. - refactor(plugins): [Patch] Refactored useGeoJsonImport.ts and ImportedLayerList.tsx to decouple from direct manager imports, utilizing DataBus for lifecycle events. - refactor(core): [Patch] Added pluginUnregistered listener to DataBusSubscriber.tsx to handle state and cache cleanup synchronously via event. * fix(types): resolve PluginManager type errors * refactor(core): decouple PluginManager and fix rendering invariants - refactor(core): Replace Zustand mutations in PluginManager with DataBus events (Patch) - refactor(sdk): Add layerLoadingChanged, pluginError, pluginUnregistered to DataBusEvents (Patch) - refactor(ui): Subscribe to new DataBus events in DataBusSubscriber (Patch) - fix(plugins): Remove size from BaseAviationPlugin to fix model rendering clipping (Patch) - fix(plugins): Migrate BaseIncidentPlugin from size to iconScale to fix billboard clipping (Patch) * chore: resolve lockfile conflict --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import {
|
|
describe, it, expect, vi, beforeEach
|
|
} from "vitest";
|
|
|
|
/**
|
|
* Tests for isDemoAdmin and getDemoAdminSecret.
|
|
*
|
|
* Uses vi.stubEnv + dynamic imports to control module-level state
|
|
* (edition constant is set at module load time).
|
|
*/
|
|
|
|
describe("getDemoAdminSecret", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
it("returns undefined on non-demo editions", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "local");
|
|
vi.stubEnv("WWV_DEMO_ADMIN_SECRET", "secret123");
|
|
const { getDemoAdminSecret } = await import("./edition");
|
|
expect(getDemoAdminSecret()).toBeUndefined();
|
|
});
|
|
|
|
it("returns undefined on demo when secret is not set", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
delete process.env.WWV_DEMO_ADMIN_SECRET;
|
|
const { getDemoAdminSecret } = await import("./edition");
|
|
expect(getDemoAdminSecret()).toBeUndefined();
|
|
});
|
|
|
|
it("returns the secret on demo when set", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
vi.stubEnv("WWV_DEMO_ADMIN_SECRET", "secret123");
|
|
const { getDemoAdminSecret } = await import("./edition");
|
|
expect(getDemoAdminSecret()).toBe("secret123");
|
|
});
|
|
|
|
it("trims whitespace from the secret", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
vi.stubEnv("WWV_DEMO_ADMIN_SECRET", " secret123 ");
|
|
const { getDemoAdminSecret } = await import("./edition");
|
|
expect(getDemoAdminSecret()).toBe("secret123");
|
|
});
|
|
});
|
|
|
|
describe("isDemoAdmin", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
it("returns false on non-demo editions even with demo-admin role", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "local");
|
|
const { isDemoAdmin, DEMO_ADMIN_ROLE } = await import("./edition");
|
|
expect(isDemoAdmin({ user: { role: DEMO_ADMIN_ROLE } })).toBe(false);
|
|
});
|
|
|
|
it("returns false on demo with null session", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
const { isDemoAdmin } = await import("./edition");
|
|
expect(isDemoAdmin(null)).toBe(false);
|
|
});
|
|
|
|
it("returns false on demo with undefined session", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
const { isDemoAdmin } = await import("./edition");
|
|
expect(isDemoAdmin(undefined)).toBe(false);
|
|
});
|
|
|
|
it("returns false on demo with wrong role", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
const { isDemoAdmin } = await import("./edition");
|
|
expect(isDemoAdmin({ user: { role: "user" } })).toBe(false);
|
|
});
|
|
|
|
it("returns true on demo with demo-admin role", async () => {
|
|
vi.stubEnv("NEXT_PUBLIC_WWV_EDITION", "demo");
|
|
const { isDemoAdmin, DEMO_ADMIN_ROLE } = await import("./edition");
|
|
expect(isDemoAdmin({ user: { role: DEMO_ADMIN_ROLE } })).toBe(true);
|
|
});
|
|
});
|