Hello I am new to testing and I am following this client’s testing protocol where they make an axios.post request to a localhost end point (they start up a separate express server during test script)
describe("Arrived For Delivery", () => {
it("POST /courier/arrivedForDelivery should return success", async () => {
const res = await axios.post(
`http://localhost:8888/courier/arrivedForDelivery`,
{ order_id: "MOCK" },
{
params: {
authentication: mockAuth,
},
}
);
// Assertion
expect(res.data).to.be.equal("success");
});
it("POST /courier/arrivedForDelivery should return error data", async () => {
// Arrange
const stubProviderStorage = stub(ProviderStorage, "GetProviderByID");
stubProviderStorage.throws({ message: "test" });
try {
// Act
await axios.post(
`http://localhost:8888/courier/arrivedForDelivery`,
{ order_id: "MOCK" },
{
params: {
authentication: mockAuth,
},
}
);
// Assert
expect.fail();
} catch (error) {
expect((error as AxiosError).response?.data).to.be.eqls({
code: 400,
message: "arrivedForDelivery Error test",
});
}
stubProviderStorage.restore();
});
});
is it possible to use sinon to make a mock api call and define what the response should be? because my senior dev from another company is telling me that i shouldnt be making real axios requests in an unit test nor i should make requests outside the code base.
any suggestions?