diff --git a/memory-bank/change-log.md b/memory-bank/change-log.md index 7ae4628d..cf8423d9 100644 --- a/memory-bank/change-log.md +++ b/memory-bank/change-log.md @@ -2019,3 +2019,33 @@ Validation: Follow-ups: - Optional next bounded slice: add a focused test (or integration harness assertion) around `downloadBlob` service return contract to prevent regression to response-object assumptions. + +--- + +### CL-057: TASK22260 next slice — phase7 behavioural harness compatibility update + +date: 2026-03-25 +author: Cline +scope: `tests/phase7/service-behaviour.test.cjs` +type: change +rationale: After service-layer client migration (`getJson`/`requestJson`/`buildHashedQueryUrl`), phase7 behavioural harness still assumed direct axios imports only; update harness defaults so legacy behavior assertions remain executable. +impact: Restores service behavioural regression coverage (12/12) without changing production runtime code. +status: completed + +Summary: + +- Enhanced phase7 VM loader default injections for migrated service helpers: + - added default `getJson(...)` mock delegating to `axios.get(...).then(res.data)` + - added default `requestJson(...)` mock delegating to `axios(config).then(res.data)` + - added default `buildHashedQueryUrl(...)` mock resolving hash via `/api/endpoint/gethash_api` compatibility path +- Updated notify behavior assertions to align with shared request client usage (`requestJson` invokes axios config-style call): + - switched notify test handlers from `axios.postHandler` to `axios.requestHandler` + - assertions now inspect `axios.calls[0].config.{url,method,data}` + +Validation: + +- `node tests/phase7/service-behaviour.test.cjs` -> pass (12/12) + +Follow-ups: + +- Optional next bounded slice: add a small shared test utility for service harness client mocks to reduce future per-file drift as façade migration continues. diff --git a/tests/phase7/service-behaviour.test.cjs b/tests/phase7/service-behaviour.test.cjs index 305ac424..e5bb54ca 100644 --- a/tests/phase7/service-behaviour.test.cjs +++ b/tests/phase7/service-behaviour.test.cjs @@ -72,6 +72,38 @@ const loadServiceModule = (fileName, injected = {}) => { source = source.replace(/export const\s+/g, "const "); source += `\nmodule.exports = { ${exportNames.join(", ")} };\n`; + const defaultGetJson = (url, config) => { + if (!injected.axios || !injected.axios.get) { + throw new Error("Missing axios.get for default getJson mock"); + } + + return injected.axios + .get(url, config) + .then((response) => response.data); + }; + + const defaultRequestJson = (config) => { + if (!injected.axios) { + throw new Error("Missing axios for default requestJson mock"); + } + + return injected.axios(config).then((response) => response.data); + }; + + const defaultBuildHashedQueryUrl = async (queryUrl) => { + if (!injected.axios || !injected.axios.get) { + throw new Error( + "Missing axios.get for default buildHashedQueryUrl mock" + ); + } + + const hashResponse = await injected.axios.get( + "/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl) + ); + + return queryUrl + hashResponse.data.hash; + }; + const context = { module: { exports: {} }, exports: {}, @@ -85,6 +117,10 @@ const loadServiceModule = (fileName, injected = {}) => { warn: () => {}, error: () => {} }, + getJson: injected.getJson || defaultGetJson, + requestJson: injected.requestJson || defaultRequestJson, + buildHashedQueryUrl: + injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl, ...injected }; @@ -367,7 +403,7 @@ test("notify/sendEmail posts payload and returns response data", async () => { const axios = createAxiosMock(); const logger = createLoggerMock(); - axios.postHandler = async () => ({ data: { id: "msg-1" } }); + axios.requestHandler = async () => ({ data: { id: "msg-1" } }); const notify = loadServiceModule("notifyDirectService.js", { axios, @@ -382,8 +418,9 @@ test("notify/sendEmail posts payload and returns response data", async () => { ); assert.deepStrictEqual(normalize(result), { id: "msg-1" }); - assert.strictEqual(axios.calls[0].url, "/api/email/notify"); - assert.deepStrictEqual(normalize(axios.calls[0].data), { + assert.strictEqual(axios.calls[0].config.url, "/api/email/notify"); + assert.strictEqual(axios.calls[0].config.method, "post"); + assert.deepStrictEqual(normalize(axios.calls[0].config.data), { templateId: "template-1", emailAddress: "person@example.com", reference: "ref-123", @@ -396,7 +433,7 @@ test("notify/sendEmail logs and rethrows on failure", async () => { const logger = createLoggerMock(); const error = createAxiosError(429, "Too Many Requests"); - axios.postHandler = async () => Promise.reject(error); + axios.requestHandler = async () => Promise.reject(error); const notify = loadServiceModule("notifyDirectService.js", { axios,