Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
091ffcbc
Commit
091ffcbc
authored
2 years ago
by
Titus Netland
Browse files
Options
Downloads
Patches
Plain Diff
Fixed mock tests of login API to return an Object and not a string
parent
db170cd9
No related branches found
No related tags found
1 merge request
!12
API login mock tests
Pipeline
#175984
passed
2 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/LoginForm.vue
+1
-1
1 addition, 1 deletion
src/components/LoginForm.vue
tests/unit/apiutil-login-mock.spec.js
+8
-8
8 additions, 8 deletions
tests/unit/apiutil-login-mock.spec.js
with
9 additions
and
9 deletions
src/components/LoginForm.vue
+
1
−
1
View file @
091ffcbc
...
...
@@ -84,7 +84,7 @@
>
Logg inn
</button>
<div
class=
"
flex justify-center
align-items: flex-end; mb-6 mt-6"
>
<div
class=
"align-items: flex-end; mb-6 mt-6"
>
<div
class=
"ml-3 text-sm"
>
<router-link
to=
"register"
class=
"text-blue-600"
>
Ny bruker
</router-link
...
...
This diff is collapsed.
Click to expand it.
tests/unit/apiutil-login-mock.spec.js
+
8
−
8
View file @
091ffcbc
...
...
@@ -4,13 +4,14 @@ import axios from "axios";
jest
.
mock
(
"
axios
"
);
describe
(
"
testing mocking of apiutil.js
"
,
()
=>
{
it
(
"
check that login fails with wrong credentials - against mock
"
,
async
()
=>
{
const
loginRequest
=
{
email
:
"
wrong@email.com
"
,
password
:
"
thisiswrong123
"
};
const
expectedLoginResponse
=
"
Login failed
"
;
const
expectedLoginResponse
=
{
isLoggedIn
:
false
,
token
:
""
}
axios
.
post
.
mockImplementation
(()
=>
Promise
.
resolve
({
data
:
expectedLoginResponse
})
...
...
@@ -18,25 +19,24 @@ describe("testing mocking of apiutil.js", () => {
const
loginResponse
=
await
doLogin
(
loginRequest
);
expect
(
loginResponse
).
toEqual
(
expectedLoginResponse
);
expect
(
loginResponse
.
token
.
isLoggedIn
).
toEqual
(
expectedLoginResponse
.
isLoggedIn
);
});
it
(
"
check that login succeeds when correct credentials - against mock
"
,
async
()
=>
{
const
loginRequest
=
{
email
:
"
correct@email.com
"
,
password
:
"
thisiscorrect123
"
};
const
apiResponse
=
{
response
:
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
"
,
};
const
apiResponse
=
{
isLoggedIn
:
true
,
token
:
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM
"
+
"
0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
"
};
const
expectedLoginResponse
=
"
Login failed
"
;
const
expectedLoginResponse
=
{
isLoggedIn
:
false
,
token
:
""
}
;
axios
.
post
.
mockImplementation
(()
=>
Promise
.
resolve
({
data
:
apiResponse
}));
const
loginResponse
=
await
doLogin
(
loginRequest
);
expect
(
loginResponse
).
not
.
toEqual
(
expectedLoginResponse
);
expect
(
loginResponse
.
token
.
isLoggedIn
).
not
.
toEqual
(
expectedLoginResponse
.
isLoggedIn
);
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment