53 lines
3.9 KiB
JavaScript
53 lines
3.9 KiB
JavaScript
"use strict";
|
|
const fs = require("node:fs"), vm = require("node:vm"), path = require("node:path"), assert = require("node:assert/strict");
|
|
const legacy = fs.readFileSync(path.join(__dirname, "build199_goal_penalty.cjs"), "utf8");
|
|
const cut = legacy.indexOf("\nconst cases = {};"); assert.ok(cut > 0);
|
|
const io = legacy.slice(0, cut).replace("['hockeyStoreGameControl', 'hockeyScoreCommand'", "['hockeyScoreDockMarkup', 'hockeyStoreGameControl', 'hockeyScoreCommand'");
|
|
assert.notEqual(io, legacy.slice(0, cut));
|
|
const { harness, penalty, flush, assertInfrastructure, source } = new Function("require", "process", "__dirname", io + "\nreturn { harness, penalty, flush, assertInfrastructure, source };")(require, process, __dirname);
|
|
function armLegacy(h) {
|
|
const count = { home: 0, away: 0 };
|
|
for (const row of h.board().penalties) if (!row.finished && row.remainingMs > 0) count[row.side]++;
|
|
for (const control of [h.server, h.state.data.hockey.game_control, h.state.hockeyGameControl["game-A"]]) {
|
|
control.strength = { ...control.strength, home_penalties: count.home, away_penalties: count.away,
|
|
advantage_side: count.home < count.away ? "home" : count.away < count.home ? "away" : "" };
|
|
}
|
|
h.server.flags.score_penalty_shot = true;
|
|
h.state.data.hockey.game_control.flags.score_penalty_shot = true;
|
|
h.state.hockeyGameControl["game-A"].flags.score_penalty_shot = true;
|
|
}
|
|
const cases = {};
|
|
cases.dock_has_no_manual_shot = async () => {
|
|
const h = harness(); armLegacy(h);
|
|
const start = source.indexOf(" const escapeHtml ="), end = source.indexOf(";\n", start);
|
|
assert.ok(start >= 0 && end > start);
|
|
vm.runInContext(source.slice(start, end + 1).replace("const escapeHtml =", "globalThis.escapeHtml ="), h.c);
|
|
const html = h.c.hockeyScoreDockMarkup();
|
|
assert.equal(html.includes("data-hockey-score-penalty-shot"), false, "The removed manual shot button must not be rendered, even for an old armed match");
|
|
assert.equal(html.includes("ШБ"), false);
|
|
for (const command of ["home_plus", "home_minus", "away_plus", "away_minus", "sync"]) assert.ok(html.includes('data-hockey-score-command="' + command + '"'));
|
|
assertInfrastructure(h);
|
|
};
|
|
for (const penalized of ["home", "away"]) cases["old_flag_cannot_block_sql_" + penalized] = async () => {
|
|
const h = harness([penalty("minor", penalized)]); armLegacy(h); await h.prime(); await h.score(0, 0);
|
|
await h.score(penalized === "away" ? 1 : 0, penalized === "home" ? 1 : 0);
|
|
assertInfrastructure(h);
|
|
assert.equal(h.board().penalties.length, 0, "An obsolete manual flag must not classify an ordinary opponent goal as a penalty shot");
|
|
assert.ok(h.commands().some(row => /^OverlayInput[1-8]Out$/.test(row.Function)));
|
|
assert.equal(h.requests.some(row => row.url.endsWith("/control/flags")), false, "No obsolete flag writeback or extra score-blocking request");
|
|
};
|
|
cases.old_pending_flag_cannot_block_manual = async () => {
|
|
const h = harness(); await h.prime();
|
|
h.state.hockeyScorePenaltyShotPending = { context: h.c.hockeyGoalPenaltyContext(), desired: true, promise: Promise.resolve(true) };
|
|
await h.c.hockeyScoreCommand("home_plus", { refreshMapping: false, announce: false }); await h.settle();
|
|
assertInfrastructure(h); assert.equal(h.board().penalties.length, 0);
|
|
assert.equal(h.requests.some(row => row.url.endsWith("/control/flags")), false);
|
|
};
|
|
cases.explicit_goal_type_preserves_penalty_shot_rule = async () => {
|
|
const h = harness(); await h.prime();
|
|
await h.c.hockeyScoreCommand("home_plus", { refreshMapping: false, announce: false, goalType: "penalty_shot" }); await h.settle();
|
|
assertInfrastructure(h); assert.equal(h.board().penalties.length, 1);
|
|
assert.equal(h.commands().some(row => /^OverlayInput[1-8]Out$/.test(row.Function)), false);
|
|
};
|
|
(async () => { const name = process.argv[2]; assert.equal(typeof cases[name], "function"); await cases[name](); console.log("PASS BUILD201 SHB: " + name); })().catch(error => { console.error(error); process.exitCode = 1; });
|