Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
m4lab_tv1
User Account
Commits
70638bdb
Commit
70638bdb
authored
Mar 08, 2021
by
Rosanny Sihombing
Browse files
update unit test
parent
908416f6
Changes
3
Show whitespace changes
Inline
Side-by-side
__tests__/gitlab.unit.test.js
View file @
70638bdb
const
gitlab
=
require
(
'
../routes/gitlab
'
)
const
axios
=
require
(
'
axios
'
)
//const axios = require('axios')
//jest.mock('axios')
beforeAll
(()
=>
{
// test gitlab API connection
var
config
=
{
method
:
'
get
'
,
url
:
'
https://transfer.hft-stuttgart.de/gitlab/api/v4/projects
'
describe
(
'
GitLab API
'
,
()
=>
{
/*
test('jest.fn recalls what it has been called with', () => {
const mock = jest.fn()
mock('a', 'b', 'c')
expect(mock).toHaveBeenCalledTimes(1)
expect(mock).toHaveBeenCalledWith('a', 'b', 'c')
}); */
// mock
/* it('returns an existing gitlab-userID by an email address', done => {
let resp = {
error: false,
data: 1}
axios.get.mockResolvedValue(resp)
gitlab.getUserIdByEmail('rosanny.sihombing@hft-stuttgart.de', function(resp){
try {
expect(resp.error).toBeFalsy()
expect(resp.data).not.toBeNull()
done()
} catch (error) {
done(error)
}
})
})
*/
axios
(
config
)
.
then
(
function
(
response
)
{
expect
(
response
.
statusCode
).
toBe
(
200
)
it
(
'
returns an existing gitlab-userID by an email address
'
,
done
=>
{
gitlab
.
getUserIdByEmail
(
'
rosanny.sihombing@hft-stuttgart.de
'
,
function
(
data
){
try
{
expect
(
data
.
error
).
toBeFalsy
()
expect
(
data
.
data
).
not
.
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
})
describe
(
'
GitLab API test
'
,
()
=>
{
test
(
"
Get a gitlab userID by email
"
,
()
=>
{
// email = any email address
gitlab
.
getUserIdByEmail
(
"
test@email.de
"
,
function
(
resp
){
expect
(
resp
).
not
.
toBeNull
()
it
(
'
returns an error due to the non-exist user
'
,
done
=>
{
gitlab
.
getUserIdByEmail
(
'
test@hft-stuttgart.com
'
,
function
(
data
)
{
try
{
expect
(
data
.
error
).
toBeTruthy
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
test
(
"
Get the projects of a particular user
"
,
()
=>
{
// userID = any integer
gitlab
.
getUserProjects
(
3
,
function
(
resp
){
expect
(
resp
).
not
.
toBeNull
()
it
(
'
returns the projects of a particular userId
'
,
done
=>
{
gitlab
.
getUserProjects
(
3
,
function
(
data
)
{
try
{
expect
(
data
.
error
).
toBeFalsy
()
expect
(
data
.
data
).
not
.
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
it
(
'
returns an error due to the wrong userID
'
,
done
=>
{
gitlab
.
getUserProjects
(
'
abc
'
,
function
(
data
)
{
try
{
expect
(
data
.
error
).
toBeTruthy
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
})
\ No newline at end of file
__tests__/method.unit.test.js
View file @
70638bdb
const
dbconn
=
require
(
'
../routes/dbconn
'
)
const
methods
=
require
(
'
../routes/methods
'
)
beforeAll
(()
=>
{
// test DB connection
dbconn
.
user
.
query
(
'
SELECT 1 + 5 AS solution
'
,
function
(
err
,
rows
)
{
expect
(
err
).
toBeNull
()
expect
(
rows
[
0
].
solution
).
toBe
(
6
)
})
dbconn
.
project
.
query
(
'
SELECT 10 + 5 AS solution
'
,
function
(
err
,
rows
)
{
expect
(
err
).
toBeNull
()
expect
(
rows
[
0
].
solution
).
toBe
(
15
)
})
})
describe
(
"
DB methohds test
"
,
()
=>
{
/*
test("Get a user from DB by email", () => {
let gitlabUserData = "to-be-defined"
methods.addGitlabUser(gitlabUserData, function(data, err){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
}) */
test
(
"
Get a user from DB by email
"
,
()
=>
{
// email = any email address
methods
.
getUserByEmail
(
"
test@email.de
"
,
function
(
data
,
err
){
expect
(
data
).
not
.
toBeNull
()
it
(
'
returns a user from DB by email
'
,
done
=>
{
methods
.
getUserByEmail
(
'
rosanny.sihombing@hft-stuttgart.de
'
,
function
(
resp
,
err
){
try
{
expect
(
resp
).
not
.
toBeNull
()
expect
(
err
).
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
test
(
"
Get a user from DB by ID
"
,
()
=>
{
// ID = any integer
methods
.
getUserById
(
100
,
function
(
data
,
err
){
expect
(
data
).
not
.
toBeNull
()
it
(
"
returns a user from DB by ID
"
,
done
=>
{
methods
.
getUserById
(
10
,
function
(
resp
,
err
){
try
{
expect
(
resp
).
not
.
toBeNull
()
expect
(
err
).
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
test
(
"
Check user email
"
,
()
=>
{
// email = any email address
methods
.
checkUserEmail
(
"
test@email.de
"
,
function
(
err
,
data
){
expect
(
data
).
not
.
toBeNull
()
it
(
"
checks user email
"
,
done
=>
{
methods
.
checkUserEmail
(
"
test@email.de
"
,
function
(
err
,
resp
){
try
{
expect
(
resp
).
not
.
toBeNull
()
expect
(
err
).
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
test
(
"
Get a user by token
"
,
()
=>
{
// token = any alphanumeric
methods
.
checkUserEmail
(
"
1abc0qwerty
"
,
function
(
err
,
data
){
expect
(
data
).
not
.
toBeNull
()
it
(
"
returns a user by token
"
,
done
=>
{
methods
.
checkUserEmail
(
"
1abc0qwerty
"
,
function
(
err
,
resp
){
// token = any alphanumeric
try
{
expect
(
resp
).
not
.
toBeNull
()
expect
(
err
).
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
})
__tests__/routes-account.unit.test.js
deleted
100644 → 0
View file @
908416f6
describe
(
'
Sample Test
'
,
()
=>
{
it
(
'
should test that true === true
'
,
()
=>
{
expect
(
true
).
toBe
(
true
)
})
})
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment