Merged PR 2432: Add myportal API grouping facade read slice
Add myportal API grouping facade read slice Related work items: #23754
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
const assert = require("assert");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const { loadModule, createRes } = require("../phase21/_shared.cjs");
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
|
||||
const tests = [];
|
||||
const test = (name, fn) => tests.push({ name, fn });
|
||||
|
||||
const read = (relativePath) =>
|
||||
fs.readFileSync(path.join(rootDir, relativePath), "utf8");
|
||||
|
||||
test("myportal get-my-cases facade delegates to legacy handler", async () => {
|
||||
const calls = [];
|
||||
const mod = loadModule("pages/api/myportal/get-my-cases.js", {
|
||||
legacyGetMyCasesHandler: async (req, res) => {
|
||||
calls.push({ req, res });
|
||||
return res.status(200).json({ ok: true, route: "my-cases" });
|
||||
}
|
||||
});
|
||||
|
||||
const req = { method: "GET", query: { loggedInUserId: "user-1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(calls.length, 1);
|
||||
assert.strictEqual(calls[0].req, req);
|
||||
assert.strictEqual(calls[0].res, res);
|
||||
});
|
||||
|
||||
test("myportal get-my-lpa-cases facade delegates to legacy handler", async () => {
|
||||
const calls = [];
|
||||
const mod = loadModule("pages/api/myportal/get-my-lpa-cases.js", {
|
||||
legacyGetMyLpaCasesHandler: async (req, res) => {
|
||||
calls.push({ req, res });
|
||||
return res.status(200).json({ ok: true, route: "my-lpa-cases" });
|
||||
}
|
||||
});
|
||||
|
||||
const req = { method: "GET", query: { lpaid: "lpa-1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(calls.length, 1);
|
||||
assert.strictEqual(calls[0].req, req);
|
||||
assert.strictEqual(calls[0].res, res);
|
||||
});
|
||||
|
||||
test("myportal get-portal-module-details facade delegates to legacy handler", async () => {
|
||||
const calls = [];
|
||||
const mod = loadModule("pages/api/myportal/get-portal-module-details.js", {
|
||||
legacyGetPortalModuleDetailsHandler: async (req, res) => {
|
||||
calls.push({ req, res });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ ok: true, route: "portal-module-details" });
|
||||
}
|
||||
});
|
||||
|
||||
const req = {
|
||||
method: "GET",
|
||||
query: {
|
||||
appealType: "pinswg_planningappeals78s",
|
||||
caseReference: "CAS-1"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(calls.length, 1);
|
||||
assert.strictEqual(calls[0].req, req);
|
||||
assert.strictEqual(calls[0].res, res);
|
||||
});
|
||||
|
||||
test("legacy myportal endpoint handlers remain present", async () => {
|
||||
const legacyFiles = [
|
||||
"pages/api/endpoint/getmycases_api.js",
|
||||
"pages/api/endpoint/getmylpacases_api.js",
|
||||
"pages/api/endpoint/getportalmoduledetails_api.js",
|
||||
"pages/api/endpoint/getmyrepresentations_api.js",
|
||||
"pages/api/endpoint/getawaitingsubmission_api.js"
|
||||
];
|
||||
|
||||
legacyFiles.forEach((filePath) => {
|
||||
assert.strictEqual(
|
||||
fs.existsSync(path.join(rootDir, filePath)),
|
||||
true,
|
||||
filePath
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("active service layers now target grouped myportal routes", async () => {
|
||||
const portalSource = read("actions/services/portalDirectService.js");
|
||||
const caseSource = read("actions/services/caseDirectService.js");
|
||||
|
||||
assert.match(portalSource, /\/api\/myportal\/get-my-cases/);
|
||||
assert.match(portalSource, /\/api\/myportal\/get-my-lpa-cases/);
|
||||
assert.match(caseSource, /\/api\/myportal\/get-portal-module-details/);
|
||||
});
|
||||
|
||||
test("adopted service methods no longer target legacy endpoint URLs", async () => {
|
||||
const portalSource = read("actions/services/portalDirectService.js");
|
||||
const caseSource = read("actions/services/caseDirectService.js");
|
||||
|
||||
assert.doesNotMatch(portalSource, /\/api\/endpoint\/getmycases_api/);
|
||||
assert.doesNotMatch(portalSource, /\/api\/endpoint\/getmylpacases_api/);
|
||||
assert.doesNotMatch(
|
||||
caseSource,
|
||||
/\/api\/endpoint\/getportalmoduledetails_api/
|
||||
);
|
||||
});
|
||||
|
||||
test("runtime contract strings and parameter names are preserved where structurally testable", async () => {
|
||||
const portalSource = read("actions/services/portalDirectService.js");
|
||||
const caseSource = read("actions/services/caseDirectService.js");
|
||||
|
||||
assert.match(portalSource, /loggedInUserId/);
|
||||
assert.match(portalSource, /lpaid/);
|
||||
assert.match(caseSource, /appealType/);
|
||||
assert.match(caseSource, /caseReference: encodeURI\(caseReference\)/);
|
||||
});
|
||||
|
||||
test("excluded route families remain outside this myportal slice", async () => {
|
||||
const portalSource = read("actions/services/portalDirectService.js");
|
||||
const caseSource = read("actions/services/caseDirectService.js");
|
||||
const pageSource = read("pages/myportal/index.js");
|
||||
|
||||
assert.match(portalSource, /\/api\/subscriptions\/get-watched-cases/);
|
||||
assert.match(pageSource, /getRepsFromBlob\(thisSession.user.id\)/);
|
||||
assert.match(
|
||||
pageSource,
|
||||
/getAwaitingSubmissionFromBlob\(thisSession.user.id\)/
|
||||
);
|
||||
assert.match(portalSource, /\/api\/endpoint\/getmyrepresentations_api/);
|
||||
assert.match(portalSource, /\/api\/endpoint\/getawaitingsubmission_api/);
|
||||
assert.doesNotMatch(caseSource, /\/api\/cases\/get-case"/);
|
||||
assert.doesNotMatch(caseSource, /\/api\/cases\/get-case-by-id/);
|
||||
});
|
||||
|
||||
async function run() {
|
||||
let failures = 0;
|
||||
|
||||
for (const { name, fn } of tests) {
|
||||
try {
|
||||
await fn();
|
||||
console.log(`✓ ${name}`);
|
||||
} catch (error) {
|
||||
failures += 1;
|
||||
console.error(`✗ ${name}`);
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (failures > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user