test(phase22): add auth redirect safety and i18n route parity checks
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
|
||||
const tests = [];
|
||||
const test = (name, fn) => tests.push({ name, fn });
|
||||
|
||||
const loadRewrites = async () => {
|
||||
const configPath = path.join(__dirname, "..", "..", "next.config.js");
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require
|
||||
const nextConfig = require(configPath);
|
||||
return nextConfig.rewrites();
|
||||
};
|
||||
|
||||
test("i18n/rewrites include required CY aliases for auth and policy routes", async () => {
|
||||
const rewrites = await loadRewrites();
|
||||
|
||||
const requiredPairs = [
|
||||
{ source: "/awd/mewngofnodi", destination: "/auth/signin" },
|
||||
{ source: "/awd/mewngofnodi/ebost", destination: "/auth/signin/email" },
|
||||
{ source: "/awd/gwall", destination: "/auth/error" },
|
||||
{ source: "/awd/gwirio-cais", destination: "/auth/verify-request" },
|
||||
{ source: "/preifatrwydd", destination: "/privacy" },
|
||||
{ source: "/hygyrchedd", destination: "/accessibility" },
|
||||
{
|
||||
source: "/telerau-ac-amodau",
|
||||
destination: "/terms-and-conditions"
|
||||
}
|
||||
];
|
||||
|
||||
for (const pair of requiredPairs) {
|
||||
const found = rewrites.some(
|
||||
(entry) =>
|
||||
entry.source === pair.source &&
|
||||
entry.destination === pair.destination
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
found,
|
||||
true,
|
||||
`Missing required CY rewrite ${pair.source} -> ${pair.destination}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
|
||||
for (const currentTest of tests) {
|
||||
await currentTest.fn();
|
||||
passed += 1;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Phase 22 i18n-route tests passed (${passed}/${tests.length}).`
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = run;
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user