58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
getTeamProgressErrorContent,
|
|
isConsistentTeamProgressSnapshot,
|
|
} from "../src/pages/match-team-progress-state.ts";
|
|
|
|
test("only accepts Competition and team snapshots with the same revision", () => {
|
|
assert.equal(
|
|
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 7 }),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 8 }),
|
|
false,
|
|
);
|
|
assert.equal(isConsistentTeamProgressSnapshot(undefined, { revision: 7 }), false);
|
|
});
|
|
|
|
test("describes a 401 response as an authentication error", () => {
|
|
assert.equal(
|
|
getTeamProgressErrorContent([{ status: 401 }]).kind,
|
|
"unauthorized",
|
|
);
|
|
});
|
|
|
|
test("describes a 403 response as a team access error", () => {
|
|
assert.equal(
|
|
getTeamProgressErrorContent([{ status: 403 }]).kind,
|
|
"forbidden",
|
|
);
|
|
});
|
|
|
|
test("describes a 404 response as missing Competition data", () => {
|
|
assert.equal(getTeamProgressErrorContent([{ status: 404 }]).kind, "not-found");
|
|
});
|
|
|
|
test("describes a 5xx response as a server error", () => {
|
|
assert.equal(getTeamProgressErrorContent([{ status: 503 }]).kind, "server");
|
|
});
|
|
|
|
test("describes a failed fetch as a network error", () => {
|
|
assert.equal(
|
|
getTeamProgressErrorContent([new TypeError("Failed to fetch")]).kind,
|
|
"network",
|
|
);
|
|
});
|
|
|
|
test("prioritizes authentication and authorization errors from either query", () => {
|
|
assert.equal(
|
|
getTeamProgressErrorContent([
|
|
new TypeError("Failed to fetch"),
|
|
{ status: 403 },
|
|
]).kind,
|
|
"forbidden",
|
|
);
|
|
});
|