38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
checkDeploymentVersion,
|
|
normalizeReloadPrefix,
|
|
shouldReloadPath,
|
|
} from "@/lib/realtime/deployment-refresh";
|
|
|
|
describe("deployment refresh policy", () => {
|
|
test("uses the first version as a baseline and detects later changes", () => {
|
|
expect(checkDeploymentVersion(null, "build-a")).toEqual({
|
|
version: "build-a",
|
|
hasUpdate: false,
|
|
});
|
|
expect(checkDeploymentVersion("build-a", "build-a")).toEqual({
|
|
version: "build-a",
|
|
hasUpdate: false,
|
|
});
|
|
expect(checkDeploymentVersion("build-a", "build-b")).toEqual({
|
|
version: "build-b",
|
|
hasUpdate: true,
|
|
});
|
|
});
|
|
|
|
test("matches global and pathname-prefix reloads", () => {
|
|
expect(shouldReloadPath(null, "/profile")).toBeTrue();
|
|
expect(shouldReloadPath("/admin", "/admin/backend")).toBeTrue();
|
|
expect(shouldReloadPath("/form", "/profile")).toBeFalse();
|
|
});
|
|
|
|
test("normalizes valid prefixes and rejects invalid ones", () => {
|
|
expect(normalizeReloadPrefix(null)).toBeNull();
|
|
expect(normalizeReloadPrefix(" /admin ")).toBe("/admin");
|
|
expect(() => normalizeReloadPrefix("admin")).toThrow(
|
|
"Reload path must start with /",
|
|
);
|
|
});
|
|
});
|