feat(deploy): notify clients of new releases
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
hasDeploymentChanged,
|
||||
normalizeDeploymentId,
|
||||
} from "./version";
|
||||
|
||||
describe("deployment version comparison", () => {
|
||||
it("normalizes identifiers before comparing them", () => {
|
||||
expect(normalizeDeploymentId(" release-2 ")).toBe("release-2");
|
||||
expect(normalizeDeploymentId(" ")).toBeNull();
|
||||
expect(hasDeploymentChanged("release-1", " release-2 ")).toBe(true);
|
||||
});
|
||||
|
||||
it("does not announce the initial or unchanged deployment", () => {
|
||||
expect(hasDeploymentChanged(null, "release-2")).toBe(false);
|
||||
expect(hasDeploymentChanged("release-2", "release-2")).toBe(false);
|
||||
expect(hasDeploymentChanged("release-2", "")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
export function normalizeDeploymentId(
|
||||
value: string | null | undefined,
|
||||
): string | null {
|
||||
const normalized = value?.trim();
|
||||
return normalized ? normalized : null;
|
||||
}
|
||||
|
||||
export function hasDeploymentChanged(
|
||||
current: string | null | undefined,
|
||||
next: string | null | undefined,
|
||||
): boolean {
|
||||
const currentId = normalizeDeploymentId(current);
|
||||
const nextId = normalizeDeploymentId(next);
|
||||
return currentId !== null && nextId !== null && currentId !== nextId;
|
||||
}
|
||||
Reference in New Issue
Block a user