42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { SchemaRequestGuard } from "../src/panels/modeling/schemaRequestGuard.ts";
|
|
|
|
const projectA = {
|
|
tenantId: "tenant-a",
|
|
projectId: "project-a",
|
|
graphName: "graph-a",
|
|
};
|
|
|
|
const projectB = {
|
|
tenantId: "tenant-b",
|
|
projectId: "project-b",
|
|
graphName: "graph-b",
|
|
};
|
|
|
|
test("a response from project A is stale as soon as project B starts loading", () => {
|
|
const guard = new SchemaRequestGuard();
|
|
const requestA = guard.begin(projectA);
|
|
const requestB = guard.begin(projectB);
|
|
|
|
assert.equal(guard.isCurrent(requestA, projectB), false);
|
|
assert.equal(guard.isCurrent(requestB, projectB), true);
|
|
});
|
|
|
|
test("an explicit project-context invalidation rejects an in-flight response", () => {
|
|
const guard = new SchemaRequestGuard();
|
|
const requestA = guard.begin(projectA);
|
|
|
|
guard.invalidate();
|
|
|
|
assert.equal(guard.isCurrent(requestA, projectA), false);
|
|
});
|
|
|
|
test("the captured context also protects against a context change without a new request", () => {
|
|
const guard = new SchemaRequestGuard();
|
|
const requestA = guard.begin(projectA);
|
|
|
|
assert.equal(guard.isCurrent(requestA, projectB), false);
|
|
});
|