An outline of my code is this:
const apiOnePost = async (data) => {
console.log('posting the data');
};
const apiTwoPost = async (data) => {
console.log('posting the data');
return 'id';
};
const apiTwoGet = async (id) => {
console.log('getting the data');
return { rawData: 'foo' }
}
// Allready united tested
const mapData = (raw) => {
return { data: raw.rawData }
}
const businessFunction = async (data) => {
await apiOnePost(data);
let id = await apiTwoPost(data)
let raw = apiTwoGet(id);
return mapData(raw);
}
My objective is to test the function businessFunction (which is the only function that is exported from the file, mapData is actually in a separate file)
But as you see I can't just import businessFunction into my test file and run asserts because all it's doing is making api calls and mapping the results.
My test is strictly not supposed to send data to and from the APIs.
If I mock the apis how do I get the function to use those mocked apis instead of the real things when I'm running it to test my assertions?
If anyone is curious the solution I ended up choosing was separating each API post into it's own module and importing them in the main function, then running assertions on the main function was trivial because I could use jest.mock() on each API call.