26 lines
1.3 KiB
JavaScript
26 lines
1.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readdir } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
import { legacyBachelorRedirects } from '../src/config/legacy-bachelor-redirects.mjs';
|
|
|
|
async function routes(directory, prefix = '') {
|
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
const found = [];
|
|
for (const entry of entries) {
|
|
const relative = `${prefix}${entry.name}`;
|
|
if (entry.isDirectory()) found.push(...await routes(`${directory}/${entry.name}`, `${relative}/`));
|
|
else if (/\.mdx?$/.test(entry.name)) {
|
|
const stem = relative.replace(/\.mdx?$/, '').replace(/index$/, '');
|
|
found.push(`/data-science-and-ai/${stem}`.replace(/\/+/g, '/'));
|
|
}
|
|
}
|
|
return found.sort();
|
|
}
|
|
|
|
test('every Data Science & AI page has an exact legacy bachelor redirect', async () => {
|
|
const canonical = await routes('src/content/docs/data-science-and-ai');
|
|
const expected = Object.fromEntries(canonical.map((target) => [target.replace('/data-science-and-ai/', '/bachelor/'), target]));
|
|
assert.deepEqual(legacyBachelorRedirects, expected);
|
|
assert.equal(legacyBachelorRedirects['/bachelor/'], '/data-science-and-ai/');
|
|
assert.equal(legacyBachelorRedirects['/bachelor/year-1/block-2/calculus'], '/data-science-and-ai/year-1/block-2/calculus');
|
|
});
|