refactor(api): migrate batch 10 endpoints to relayGet

This commit is contained in:
2026-03-24 10:08:51 +00:00
parent e8d4e8563e
commit 0f4b8005ba
4 changed files with 78 additions and 85 deletions
@@ -274,14 +274,12 @@ test("getportallogin returns HASH_REQUIRED when hash missing", async () => {
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async () => ({}),
hashAPIPath: (input) =>
input && input.startsWith("/api/endpoint/getportallogin_api")
? "&hash=expected"
: "&hash=relay",
azureHeadersPaged: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
azureHeadersPaged: () => ({})
});
const req = { query: { emailAddress: "user@test.local" } };
@@ -296,14 +294,12 @@ test("getportallogin returns INVALID_HASH when hash mismatch", async () => {
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async () => ({}),
hashAPIPath: (input) =>
input && input.startsWith("/api/endpoint/getportallogin_api")
? "&hash=expected"
: "&hash=relay",
azureHeadersPaged: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
azureHeadersPaged: () => ({})
});
const req = { query: { emailAddress: "user@test.local", hash: "wrong" } };
@@ -318,18 +314,13 @@ test("getportallogin catch path returns PORTAL_LOGIN_FETCH_FAILED", async () =>
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
hashAPIPath: (input) =>
input && input.startsWith("/api/endpoint/getportallogin_api")
? "&hash=expected"
: "&hash=relay",
azureHeadersPaged: () => ({}),
axios: {
get: async () => {
throw new Error("relay failed");
}
},
consoleLogger: () => {}
azureHeadersPaged: () => ({})
});
const req = {
@@ -349,16 +340,13 @@ test("getportallogin accepts encoded email hash variant", async () => {
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async ({ res }) =>
respondSuccessMock(res, { value: [{ contactid: "c1" }] }),
hashAPIPath: (input) =>
input && input.includes("emailAddress=user%2Btest%40local")
? "&hash=expected"
: "&hash=other",
azureHeadersPaged: () => ({}),
axios: {
get: async () => ({ data: { value: [{ contactid: "c1" }] } })
},
consoleLogger: () => {}
azureHeadersPaged: () => ({})
});
const req = {
@@ -2421,13 +2409,10 @@ test("getmylpacases returns LPA_ID_REQUIRED when lpaid missing", async () => {
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async () => ({}),
getLPA: async () => [{ name: "Test LPA", accountid: "acc1" }],
jsonpath: () => [{ accountid: "acc1" }],
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
azureHeaders: () => ({})
});
const req = { query: {} };
@@ -2442,13 +2427,10 @@ test("getmylpacases returns LPA_NOT_FOUND when lpaid lookup misses", async () =>
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async () => ({}),
getLPA: async () => [{ name: "Another LPA", accountid: "acc1" }],
jsonpath: () => [],
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
azureHeaders: () => ({})
});
const req = { query: { lpaid: "Missing LPA" } };
@@ -2463,17 +2445,11 @@ test("getmylpacases catch path returns MY_LPA_CASES_FETCH_FAILED", async () => {
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
relayGet: async ({ res, errorResponse }) =>
respondErrorMock(res, errorResponse),
getLPA: async () => [{ name: "Test LPA", accountid: "acc1" }],
jsonpath: () => [{ accountid: "acc1" }],
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: {
get: async () => {
throw new Error("relay failed");
}
},
consoleLogger: () => {}
azureHeaders: () => ({})
});
const req = { query: { lpaid: "Test LPA" } };