Skip to content
Snippets Groups Projects
Commit d062dcc0 authored by Titus Netland's avatar Titus Netland
Browse files

Updated tests

parent 85d812eb
No related branches found
No related tags found
1 merge request!12API login mock tests
Pipeline #175640 failed
......@@ -5,42 +5,38 @@ jest.mock("axios");
describe("testing mocking of apiutil.js", () => {
it("check that login fails with wrong credentials - against mock", async () => {
// mock api response on POST call (once)
const expectedLoginResponse = "Login failed" ;
const loginRequest = {
email: "wrong@email.com",
password: "thisiswrong123"};
const expectedLoginResponse = "Login failed";
axios.post.mockImplementation(() =>
Promise.resolve({data: "Login failed"})
Promise.resolve({ data: expectedLoginResponse })
);
// do the call
const loginRequest = {
email: "wrong@email.com",
password: "thisiswrong123",
};
const loginResponse = await doLogin(loginRequest);
// check response
// note that even if wrong username and password are used, mock is configured to return Success
expect(loginResponse).toEqual(expectedLoginResponse);
});
it("check that login succeeds when correct credentials - against mock", async () => {
// mock api response on POST call (once)
const loginRequest = {
email: "correct@email.com",
password: "thisiscorrect123"};
const apiResponse = {
response:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
};
const expectedLoginResponse = "Login failed";
axios.post.mockImplementation(() => Promise.resolve({data: apiResponse}));
// do the call
const loginRequest = {
email: "correct@email.com",
password: "thisiscorrect123",
};
axios.post.mockImplementation(() => Promise.resolve({ data: apiResponse }));
const loginResponse = await doLogin(loginRequest);
// check response
// note that even if wrong username and password are used, mock is configured to return Success
expect(loginResponse).not.toEqual(expectedLoginResponse);
});
});
import { doLogin } from '@/utils/apiutil'
describe('testing apiutil.js', () => {
it('test API call utility function - login Success', async () => {
const loginRequest = { username:"test@test.com", password: "hei" };
const loginResponse = await doLogin(loginRequest);
const expectedLoginResponse = "Login failed";
expect(loginResponse).not.toEqual(expectedLoginResponse);
})
it('test API call utility function - login Fail', async () => {
const loginRequest = { username:"failed@failed.com", password: "failed123" };
const loginResponse = await doLogin(loginRequest);
const expectedLoginResponse = "Login failed";
expect(loginResponse.data).toEqual(expectedLoginResponse);
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment