From d062dcc0219fccc0f34c54c3087aeb91c0d84c4f Mon Sep 17 00:00:00 2001
From: Titus Kristiansen <titusk@stud.ntnu.no>
Date: Mon, 25 Apr 2022 15:01:40 +0200
Subject: [PATCH] Updated tests

---
 tests/unit/apiutil-login-mock.spec.js | 34 ++++++++++++---------------
 tests/unit/apiutil-login.spec.js      | 16 -------------
 2 files changed, 15 insertions(+), 35 deletions(-)
 delete mode 100644 tests/unit/apiutil-login.spec.js

diff --git a/tests/unit/apiutil-login-mock.spec.js b/tests/unit/apiutil-login-mock.spec.js
index cbb649c..946f6f7 100644
--- a/tests/unit/apiutil-login-mock.spec.js
+++ b/tests/unit/apiutil-login-mock.spec.js
@@ -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);
   });
 });
diff --git a/tests/unit/apiutil-login.spec.js b/tests/unit/apiutil-login.spec.js
deleted file mode 100644
index 50212b6..0000000
--- a/tests/unit/apiutil-login.spec.js
+++ /dev/null
@@ -1,16 +0,0 @@
-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);
-    })
-})
-- 
GitLab