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
d062dcc0
Commit
d062dcc0
authored
2 years ago
by
Titus Netland
Browse files
Options
Downloads
Patches
Plain Diff
Updated tests
parent
85d812eb
No related branches found
Branches containing commit
No related tags found
1 merge request
!12
API login mock tests
Pipeline
#175640
failed
2 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/unit/apiutil-login-mock.spec.js
+15
-19
15 additions, 19 deletions
tests/unit/apiutil-login-mock.spec.js
tests/unit/apiutil-login.spec.js
+0
-16
0 additions, 16 deletions
tests/unit/apiutil-login.spec.js
with
15 additions
and
35 deletions
tests/unit/apiutil-login-mock.spec.js
+
15
−
19
View file @
d062dcc0
...
...
@@ -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
);
});
});
This diff is collapsed.
Click to expand it.
tests/unit/apiutil-login.spec.js
deleted
100644 → 0
+
0
−
16
View file @
85d812eb
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
);
})
})
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