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
bc220889
Commit
bc220889
authored
May 07, 2021
by
Rosanny Sihombing
Browse files
update unit test
parent
5e87d550
Changes
2
Hide whitespace changes
Inline
Side-by-side
__tests__/gitlab.unit.test.js
View file @
bc220889
const
gitlab
=
require
(
'
../
route
s/gitlab
'
)
const
gitlab
=
require
(
'
../
function
s/gitlab
'
)
//const axios = require('axios')
//jest.mock('axios')
...
...
__tests__/method.unit.test.js
View file @
bc220889
const
methods
=
require
(
'
../
route
s/methods
'
)
const
methods
=
require
(
'
../
function
s/methods
'
)
describe
(
"
DB methohds test
"
,
()
=>
{
it
(
'
returns a user from DB by email
'
,
done
=>
{
methods
.
getUserByEmail
(
'
litehon958@whipjoy.com
'
,
function
(
resp
,
err
){
try
{
expect
(
resp
).
not
.
toBeNull
()
expect
(
err
).
toBeNull
()
done
()
}
catch
(
error
)
{
done
(
error
)
}
})
})
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
)
}
})
})
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
)
}
})
})
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
)
}
})
it
(
"
returns a user from DB by email
"
,
async
()
=>
{
const
user
=
await
methods
.
getUserByEmail
(
'
litehon958@whipjoy.com
'
)
expect
(
user
).
not
.
toBeNull
()
})
it
(
"
returns a null user
"
,
async
()
=>
{
const
user
=
await
methods
.
getUserByEmail
(
'
jondoe@nowhere.com
'
)
// a non-exist user
expect
(
user
).
toBeNull
()
})
it
(
"
returns a user's email
"
,
async
()
=>
{
const
email
=
await
methods
.
getUserEmailById
(
1
)
expect
(
email
).
not
.
toBeNull
()
})
it
(
"
returns null instead of a user's email
"
,
async
()
=>
{
const
email
=
await
methods
.
getUserEmailById
(
1005
)
// no user has this ID
expect
(
email
).
toBeNull
()
})
it
(
"
returns null from DB by token
"
,
async
()
=>
{
const
user
=
await
methods
.
getUserByToken
(
'
12345678
'
)
// unvalid token
expect
(
user
).
toBeNull
()
// for valid token = expect(user).not.toBeNull()
})
it
(
"
returns a user's verification token, if any
"
,
async
()
=>
{
const
token
=
await
methods
.
getVerificationTokenByUserId
(
1
)
expect
(
token
).
toBeNull
()
})
it
(
"
returns a user's ID, if any
"
,
async
()
=>
{
const
token
=
await
methods
.
getUserIdByVerificationToken
(
'
12345678
'
)
// unvalid token
expect
(
token
).
toBeNull
()
// for valid token = expect(user).not.toBeNull()
})
it
(
"
returns a user's GitLab_ID, if any
"
,
async
()
=>
{
const
id
=
await
methods
.
getGitlabId
(
1
)
expect
(
id
).
not
.
toBeNull
()
})
it
(
"
checks user email
"
,
async
()
=>
{
const
user
=
await
methods
.
checkUserEmail
(
'
litehon958@whipjoy.com
'
)
expect
(
user
).
not
.
toBeNull
()
})
it
(
"
checks user email and return null
"
,
async
()
=>
{
const
user
=
await
methods
.
checkUserEmail
(
'
jondoe@nowhere.com
'
)
// a non-exist user
expect
(
user
).
toBeNull
()
})
})
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