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

API login frontend tests and mock tests

parent 401bd0b5
No related branches found
No related tags found
1 merge request!12API login mock tests
Pipeline #175558 passed
......@@ -6,9 +6,9 @@ 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 = { response: "Login failed" };
const expectedLoginResponse = "Login failed" ;
axios.post.mockImplementation(() =>
Promise.resolve({ data: expectedLoginResponse })
Promise.resolve(expectedLoginResponse)
);
// do the call
......@@ -28,8 +28,8 @@ describe("testing mocking of apiutil.js", () => {
response:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
};
const expectedLoginResponse = { response: "Login failed" };
axios.post.mockImplementation(() => Promise.resolve({ data: apiResponse }));
const expectedLoginResponse = "Login failed";
axios.post.mockImplementation(() => Promise.resolve(apiResponse ));
// do the call
const loginRequest = {
......
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