diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue index 4f8b255939253b9470ee2170e24759f931c0d5fa..f2277abe009f0a0cf28396f377c472be45fd5fd0 100644 --- a/src/components/LoginForm.vue +++ b/src/components/LoginForm.vue @@ -1,162 +1,112 @@ - - - + + + diff --git a/src/router/index.js b/src/router/index.js index 3e9afc866ddd3b838a5720151bca3d7cd89f819a..54dff76cba79672aec7b27a533b8ed46a009b73e 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,7 +2,6 @@ import { createRouter, createWebHistory } from "vue-router"; import HomeView from "../views/HomeView.vue"; import LoginView from "../views/LoginView.vue"; - const routes = [ { path: "/endre", //Endre før push diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js index 15809ca5993e2d95edf6e771e1eaef3892b35cbb..773bd8d67e484a1f42d371339b5a46ce757a9347 100644 --- a/src/utils/apiutil.js +++ b/src/utils/apiutil.js @@ -2,7 +2,7 @@ import axios from "axios"; export function doLogin(loginRequest) { return axios - .post(`http://localhost:8080/api/login/authentication`, loginRequest) + .post(`http://65.108.62.223:3000/api/login/authentication`, loginRequest) .then((response) => { return response.data; }); diff --git a/tests/unit/LoginFormComponentTest.spec.js b/tests/unit/LoginFormComponentTest.spec.js deleted file mode 100644 index 1f892f5e720420f3aae91f6f3716955cd3b7daf2..0000000000000000000000000000000000000000 --- a/tests/unit/LoginFormComponentTest.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -import { shallowMount } from "@vue/test-utils"; -import LoginForm from "@/components/LoginForm"; - -describe("Tests labels in LoginForm component", () => { - it("checks the E-post label", () => { - const wrapper = shallowMount(LoginForm); - - expect(wrapper.find('#emailLabelId').text()).toMatch("E-post"); - }); - - it("checks the password label", () => { - const wrapper = shallowMount(LoginForm); - - expect(wrapper.find('#passwordLabelId').text()).toMatch("Passord"); - }); -}); diff --git a/tests/unit/apiutil-login-mock.spec.js b/tests/unit/apiutil-login-mock.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..4d0764ecff86922419d816522cff259cb9b838cd --- /dev/null +++ b/tests/unit/apiutil-login-mock.spec.js @@ -0,0 +1,37 @@ +import { doLogin } from '@/utils/apiutil' +import axios from 'axios'; + +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'}; + axios.post.mockImplementation(() => 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 apiResponse = {response: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'}; + const expectedLoginResponse = {response: 'Login failed'}; + axios.post.mockImplementation(() => Promise.resolve({data: apiResponse})); + + // do the call + const loginRequest = {email: "correct@email.com", password: "thisiscorrect123"}; + 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); + })}) + +