mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-21 13:53:01 +01:00
Add Firefox data consent, repair contributor sign-in, and introduce optional Hide clutter buttons. Harden video navigation, voting, and action layouts with shared browser regression coverage and reproducible release packaging.
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
const assert = require("node:assert/strict");
|
|
|
|
const API_METHODS_BY_PATH = Object.freeze({
|
|
"/configs/selectors": Object.freeze(["GET"]),
|
|
"/interact/confirmVote": Object.freeze(["POST"]),
|
|
"/interact/vote": Object.freeze(["POST"]),
|
|
"/puzzle/registration": Object.freeze(["GET", "POST"]),
|
|
"/votes": Object.freeze(["GET"]),
|
|
});
|
|
|
|
const WORKER_SIGNAL_PATH = "/__ryd_e2e/worker-signal";
|
|
|
|
function allowedMethodsForPath(pathname) {
|
|
if (pathname === WORKER_SIGNAL_PATH) return ["POST"];
|
|
return API_METHODS_BY_PATH[pathname] ?? [];
|
|
}
|
|
|
|
function isAllowedApiPreflight(pathname, requestedMethod) {
|
|
if (typeof requestedMethod !== "string" || requestedMethod.trim() === "") return false;
|
|
return allowedMethodsForPath(pathname).includes(requestedMethod.toUpperCase());
|
|
}
|
|
|
|
function assertExactSuccessfulVotesTraffic(records, expectedVideoIds, label = "The hermetic runtime") {
|
|
assert.ok(Array.isArray(records), `${label} has no recorded API traffic.`);
|
|
assert.ok(Array.isArray(expectedVideoIds), `${label} has no expected /votes request sequence.`);
|
|
const votes = records.filter((record) => record.method === "GET" && record.pathname === "/votes");
|
|
assert.deepEqual(
|
|
votes.map((record) => record.query?.videoId),
|
|
expectedVideoIds,
|
|
`${label} emitted a missing, duplicate, or stale /votes request.`,
|
|
);
|
|
for (const [index, record] of votes.entries()) {
|
|
const videoId = expectedVideoIds[index];
|
|
assert.equal(record.responseStatus, 200, `${label} /votes request for ${videoId} did not receive HTTP 200.`);
|
|
assert.ok(
|
|
Number.isFinite(record.respondedAt),
|
|
`${label} /votes request for ${videoId} did not finish before the contract completed.`,
|
|
);
|
|
}
|
|
return votes;
|
|
}
|
|
|
|
module.exports = {
|
|
API_METHODS_BY_PATH,
|
|
WORKER_SIGNAL_PATH,
|
|
allowedMethodsForPath,
|
|
assertExactSuccessfulVotesTraffic,
|
|
isAllowedApiPreflight,
|
|
};
|