test(phase7): align service behaviour harness with client wrappers
This commit is contained in:
@@ -2019,3 +2019,33 @@ Validation:
|
|||||||
Follow-ups:
|
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.
|
- 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.
|
||||||
|
|||||||
@@ -72,6 +72,38 @@ const loadServiceModule = (fileName, injected = {}) => {
|
|||||||
source = source.replace(/export const\s+/g, "const ");
|
source = source.replace(/export const\s+/g, "const ");
|
||||||
source += `\nmodule.exports = { ${exportNames.join(", ")} };\n`;
|
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 = {
|
const context = {
|
||||||
module: { exports: {} },
|
module: { exports: {} },
|
||||||
exports: {},
|
exports: {},
|
||||||
@@ -85,6 +117,10 @@ const loadServiceModule = (fileName, injected = {}) => {
|
|||||||
warn: () => {},
|
warn: () => {},
|
||||||
error: () => {}
|
error: () => {}
|
||||||
},
|
},
|
||||||
|
getJson: injected.getJson || defaultGetJson,
|
||||||
|
requestJson: injected.requestJson || defaultRequestJson,
|
||||||
|
buildHashedQueryUrl:
|
||||||
|
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl,
|
||||||
...injected
|
...injected
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -367,7 +403,7 @@ test("notify/sendEmail posts payload and returns response data", async () => {
|
|||||||
const axios = createAxiosMock();
|
const axios = createAxiosMock();
|
||||||
const logger = createLoggerMock();
|
const logger = createLoggerMock();
|
||||||
|
|
||||||
axios.postHandler = async () => ({ data: { id: "msg-1" } });
|
axios.requestHandler = async () => ({ data: { id: "msg-1" } });
|
||||||
|
|
||||||
const notify = loadServiceModule("notifyDirectService.js", {
|
const notify = loadServiceModule("notifyDirectService.js", {
|
||||||
axios,
|
axios,
|
||||||
@@ -382,8 +418,9 @@ test("notify/sendEmail posts payload and returns response data", async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.deepStrictEqual(normalize(result), { id: "msg-1" });
|
assert.deepStrictEqual(normalize(result), { id: "msg-1" });
|
||||||
assert.strictEqual(axios.calls[0].url, "/api/email/notify");
|
assert.strictEqual(axios.calls[0].config.url, "/api/email/notify");
|
||||||
assert.deepStrictEqual(normalize(axios.calls[0].data), {
|
assert.strictEqual(axios.calls[0].config.method, "post");
|
||||||
|
assert.deepStrictEqual(normalize(axios.calls[0].config.data), {
|
||||||
templateId: "template-1",
|
templateId: "template-1",
|
||||||
emailAddress: "person@example.com",
|
emailAddress: "person@example.com",
|
||||||
reference: "ref-123",
|
reference: "ref-123",
|
||||||
@@ -396,7 +433,7 @@ test("notify/sendEmail logs and rethrows on failure", async () => {
|
|||||||
const logger = createLoggerMock();
|
const logger = createLoggerMock();
|
||||||
const error = createAxiosError(429, "Too Many Requests");
|
const error = createAxiosError(429, "Too Many Requests");
|
||||||
|
|
||||||
axios.postHandler = async () => Promise.reject(error);
|
axios.requestHandler = async () => Promise.reject(error);
|
||||||
|
|
||||||
const notify = loadServiceModule("notifyDirectService.js", {
|
const notify = loadServiceModule("notifyDirectService.js", {
|
||||||
axios,
|
axios,
|
||||||
|
|||||||
Reference in New Issue
Block a user