merge develop
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
const { useApi } = require("../../helpers/use-api");
|
||||
const { useApi } = require("../../helpers/use-api")
|
||||
|
||||
const header = {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const resolveCall = async (path, payload, header) => {
|
||||
const api = useApi();
|
||||
let res;
|
||||
const api = useApi()
|
||||
let res
|
||||
try {
|
||||
const resp = await api.post(path, payload, header);
|
||||
res = resp.status;
|
||||
const resp = await api.post(path, payload, header)
|
||||
res = resp.status
|
||||
} catch (expectedException) {
|
||||
try {
|
||||
res = expectedException.response.status;
|
||||
res = expectedException.response.status
|
||||
} catch (_) {
|
||||
console.error(expectedException);
|
||||
console.error(expectedException)
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
return res
|
||||
}
|
||||
|
||||
const determineFail = (actual, expected, path) => {
|
||||
if (expected !== actual) {
|
||||
console.log(`failed at path : ${path}`);
|
||||
console.log(`failed at path : ${path}`)
|
||||
}
|
||||
expect(actual).toEqual(expected);
|
||||
};
|
||||
expect(actual).toEqual(expected)
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to wrap a Call function so that you may reuse some input values.
|
||||
@@ -36,8 +36,8 @@ const determineFail = (actual, expected, path) => {
|
||||
* @returns
|
||||
*/
|
||||
module.exports.partial = function (fun, input = {}) {
|
||||
return async (remaining) => await fun({ ...remaining, ...input });
|
||||
};
|
||||
return async (remaining) => await fun({ ...remaining, ...input })
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to assert a specific code result from a POST call.
|
||||
@@ -51,9 +51,9 @@ module.exports.expectPostCallToReturn = async function (
|
||||
payload: {},
|
||||
}
|
||||
) {
|
||||
const res = await resolveCall(input.path, input.payload, header);
|
||||
determineFail(res, input.code, input.path);
|
||||
};
|
||||
const res = await resolveCall(input.path, input.payload, header)
|
||||
determineFail(res, input.code, input.path)
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to assert a specific code result from multiple POST
|
||||
@@ -76,10 +76,10 @@ module.exports.expectAllPostCallsToReturn = async function (
|
||||
input.pathf(i),
|
||||
input.payloadf ? input.payloadf(i) : {},
|
||||
header
|
||||
);
|
||||
determineFail(res, input.code, input.pathf(i));
|
||||
)
|
||||
determineFail(res, input.code, input.pathf(i))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to retrieve a specific object the response
|
||||
@@ -92,9 +92,9 @@ module.exports.expectAllPostCallsToReturn = async function (
|
||||
* to the get parameter provided.
|
||||
*/
|
||||
module.exports.callGet = async function ({ path, get }) {
|
||||
const api = useApi();
|
||||
const res = await api.get(path, header);
|
||||
const api = useApi()
|
||||
const res = await api.get(path, header)
|
||||
|
||||
determineFail(res.status, 200, path);
|
||||
return res?.data[get];
|
||||
};
|
||||
determineFail(res.status, 200, path)
|
||||
return res?.data[get]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user