TASK22211: normalize token endpoint contract handling
This commit is contained in:
@@ -3611,6 +3611,70 @@ test("getappealtypesfornewappeal returns success payload contract", async () =>
|
||||
);
|
||||
});
|
||||
|
||||
test("getToken success returns token payload contract", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getToken.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
axios: {
|
||||
post: async () => ({
|
||||
data: {
|
||||
access_token: "token",
|
||||
token_type: "Bearer"
|
||||
}
|
||||
})
|
||||
},
|
||||
process: {
|
||||
env: {
|
||||
ACCESS_TOKEN_ENDPOINT: "https://login.microsoftonline.com/",
|
||||
TENANT: "tenant-id",
|
||||
GRANT_TYPE: "client_credentials",
|
||||
CLIENT_ID: "client-id",
|
||||
CLIENT_SECRET: "secret",
|
||||
RELAYURI: "relay.example"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const req = { body: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
||||
access_token: "token",
|
||||
token_type: "Bearer"
|
||||
});
|
||||
});
|
||||
|
||||
test("getToken catch path returns TOKEN_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getToken.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
axios: {
|
||||
post: async () => {
|
||||
throw new Error("token fetch failed");
|
||||
}
|
||||
},
|
||||
process: {
|
||||
env: {
|
||||
ACCESS_TOKEN_ENDPOINT: "https://login.microsoftonline.com/",
|
||||
TENANT: "tenant-id",
|
||||
GRANT_TYPE: "client_credentials",
|
||||
CLIENT_ID: "client-id",
|
||||
CLIENT_SECRET: "secret",
|
||||
RELAYURI: "relay.example"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const req = { body: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "TOKEN_FETCH_FAILED");
|
||||
});
|
||||
|
||||
test("getsipsmedia returns success contract", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getsipsmedia_api.js", {
|
||||
respondSuccess: respondSuccessMock
|
||||
|
||||
Reference in New Issue
Block a user