Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WIE_202021_CSBillero11
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Bernard Roland (Student Com20)
WIE_202021_CSBillero11
Commits
4208b72e
Commit
4208b72e
authored
3 years ago
by
Bernard Roland (Student Com20)
Browse files
Options
Downloads
Patches
Plain Diff
Added user tests
parent
c16909f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/src/v1/user.test.ts
+130
-15
130 additions, 15 deletions
server/src/v1/user.test.ts
with
130 additions
and
15 deletions
server/src/v1/user.test.ts
+
130
−
15
View file @
4208b72e
import
supertest
from
'
supertest
'
;
import
supertest
,
{
Response
}
from
'
supertest
'
;
import
{
api
}
from
'
../api
'
;
import
{
api
}
from
'
../api
'
;
import
{
generateAuthToken
}
from
'
./auth
'
;
import
{
generateAuthToken
}
from
'
./auth
'
;
const
request
=
supertest
(
api
);
const
request
=
supertest
(
api
);
describe
(
'
/user/name
'
,
()
=>
{
describe
(
'
GET
/user/name
'
,
()
=>
{
test
(
'
non existant username returns
'
,
async
()
=>
{
test
(
'
non existant username returns
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/name/User3
'
);
const
response
=
await
request
.
get
(
'
/v1/user/name/User3
'
);
expect
(
response
.
status
).
toEqual
(
404
);
expect
(
response
.
status
).
toEqual
(
404
);
...
@@ -28,7 +28,7 @@ describe('/user/name', () => {
...
@@ -28,7 +28,7 @@ describe('/user/name', () => {
});
});
})
})
describe
(
'
/user/:uuid/image
'
,
()
=>
{
describe
(
'
GET
/user/:uuid/image
'
,
()
=>
{
test
(
'
returns 404 without body if no image is set
'
,
async
()
=>
{
test
(
'
returns 404 without body if no image is set
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000000/image
'
);
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000000/image
'
);
expect
(
response
.
status
).
toEqual
(
404
);
expect
(
response
.
status
).
toEqual
(
404
);
...
@@ -48,7 +48,7 @@ describe('/user/:uuid/image', () => {
...
@@ -48,7 +48,7 @@ describe('/user/:uuid/image', () => {
});
});
})
})
describe
(
'
/user
'
,
()
=>
{
describe
(
'
GET
/user
'
,
()
=>
{
test
(
'
returns the user that is authorized
'
,
async
()
=>
{
test
(
'
returns the user that is authorized
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user
'
)
.
get
(
'
/v1/user
'
)
...
@@ -62,7 +62,7 @@ describe('/user', () => {
...
@@ -62,7 +62,7 @@ describe('/user', () => {
});
});
});
});
describe
(
'
/user/tasks
'
,
()
=>
{
describe
(
'
GET
/user/tasks
'
,
()
=>
{
test
(
'
returns the tasks the user is assigned to
'
,
async
()
=>
{
test
(
'
returns the tasks the user is assigned to
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user/tasks
'
)
.
get
(
'
/v1/user/tasks
'
)
...
@@ -74,7 +74,7 @@ describe('/user/tasks', () => {
...
@@ -74,7 +74,7 @@ describe('/user/tasks', () => {
});
});
});
});
describe
(
'
/user/work
'
,
()
=>
{
describe
(
'
GET
/user/work
'
,
()
=>
{
test
(
'
returns all the users work items
'
,
async
()
=>
{
test
(
'
returns all the users work items
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
get
(
'
/v1/user/work
'
)
...
@@ -83,6 +83,7 @@ describe('/user/work', () => {
...
@@ -83,6 +83,7 @@ describe('/user/work', () => {
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
work
.
length
).
toEqual
(
3
);
expect
(
response
.
body
.
work
.
length
).
toEqual
(
3
);
});
});
test
(
'
returns all finished work items
'
,
async
()
=>
{
test
(
'
returns all finished work items
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
get
(
'
/v1/user/work
'
)
...
@@ -93,17 +94,18 @@ describe('/user/work', () => {
...
@@ -93,17 +94,18 @@ describe('/user/work', () => {
id
:
'
00000000-0000-4000-8000-000000000000
'
,
id
:
'
00000000-0000-4000-8000-000000000000
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Dat
e
(
'
2020-10-10T
00
:00:00
'
)
).
toString
()
,
started
:
Date
.
pars
e
(
'
2020-10-10T
12
:00:00
'
),
finished
:
(
new
Dat
e
(
'
2020-10-10T
0
1:00:00
'
)
).
toString
()
,
finished
:
Date
.
pars
e
(
'
2020-10-10T1
3
:00:00
'
),
});
});
expect
(
response
.
body
.
work
).
toContainEqual
({
expect
(
response
.
body
.
work
).
toContainEqual
({
id
:
'
00000000-0000-4000-8000-000000000001
'
,
id
:
'
00000000-0000-4000-8000-000000000001
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Dat
e
(
'
2020-10-10T
0
3:00:00
'
)
).
toString
()
,
started
:
Date
.
pars
e
(
'
2020-10-10T
1
3:00:00
'
),
finished
:
(
new
Dat
e
(
'
2020-10-10T
0
4:00:00
'
)
).
toString
()
,
finished
:
Date
.
pars
e
(
'
2020-10-10T
1
4:00:00
'
),
});
});
});
});
test
(
'
returns unfinished work items
'
,
async
()
=>
{
test
(
'
returns unfinished work items
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
get
(
'
/v1/user/work
'
)
...
@@ -114,10 +116,11 @@ describe('/user/work', () => {
...
@@ -114,10 +116,11 @@ describe('/user/work', () => {
id
:
'
00000000-0000-4000-8000-000000000002
'
,
id
:
'
00000000-0000-4000-8000-000000000002
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Dat
e
(
'
2020-10-11T
05
:00:00
'
)
).
toString
()
,
started
:
Date
.
pars
e
(
'
2020-10-11T
12
:00:00
'
),
finished
:
null
,
finished
:
null
,
});
});
});
});
test
(
'
can be limited in time with from date
'
,
async
()
=>
{
test
(
'
can be limited in time with from date
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
`/v1/user/work?since=
${
Date
.
parse
(
'
2020-10-10T20:00:00
'
)}
`
)
.
get
(
`/v1/user/work?since=
${
Date
.
parse
(
'
2020-10-10T20:00:00
'
)}
`
)
...
@@ -126,9 +129,18 @@ describe('/user/work', () => {
...
@@ -126,9 +129,18 @@ describe('/user/work', () => {
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
work
.
length
).
toEqual
(
1
);
expect
(
response
.
body
.
work
.
length
).
toEqual
(
1
);
});
});
test
(
'
can be limited in time with to date
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
`/v1/user/work?to=
${
Date
.
parse
(
'
2020-10-10T20:00:00
'
)}
`
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
work
.
length
).
toEqual
(
2
);
});
});
});
describe
(
'
/user/activity
'
,
()
=>
{
describe
(
'
GET
/user/activity
'
,
()
=>
{
test
(
'
returns time worked for all days
'
,
async
()
=>
{
test
(
'
returns time worked for all days
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
'
/v1/user/activity
'
)
.
get
(
'
/v1/user/activity
'
)
...
@@ -138,13 +150,116 @@ describe('/user/activity', () => {
...
@@ -138,13 +150,116 @@ describe('/user/activity', () => {
expect
(
response
.
body
.
activity
.
length
).
toEqual
(
1
);
expect
(
response
.
body
.
activity
.
length
).
toEqual
(
1
);
});
});
test
(
'
returns t
ime
work
ed
for
all
day
s
'
,
async
()
=>
{
test
(
'
returns t
he total amount of
work for
each
day
'
,
async
()
=>
{
const
response
=
await
request
const
response
=
await
request
.
get
(
`
/v1/user/activity
?to=
${
Date
.
parse
(
"
2020-10-20
"
)}
`
)
.
get
(
'
/v1/user/activity
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
activity
.
length
).
toEqual
(
1
);
expect
(
response
.
body
.
activity
[
0
].
day
).
toEqual
(
'
2020-10-10
'
);
expect
(
response
.
body
.
activity
[
0
].
time
).
toEqual
(
120
*
60
*
1000
);
});
test
(
'
can be limited in time with from date
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
`/v1/user/activity?since=
${
Date
.
parse
(
'
2020-10-10T20:00:00
'
)}
`
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
activity
.
length
).
toEqual
(
0
);
});
});
describe
(
'
GET /user/completion
'
,
()
=>
{
test
(
'
returns completion for assigned tasks
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/completion
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
completion
).
toEqual
({
open
:
0
,
closed
:
0
,
suspended
:
0
,
overdue
:
1
,
});
});
test
(
'
can be limited in time with from date
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
`/v1/user/completion?since=
${
Date
.
parse
(
'
2020-10-30T20:00:00
'
)}
`
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
completion
).
toEqual
({
open
:
0
,
closed
:
0
,
suspended
:
0
,
overdue
:
0
,
});
});
});
describe
(
'
PUT /user
'
,
()
=>
{
let
response
:
Response
;
beforeAll
(
async
()
=>
{
response
=
await
request
.
put
(
'
/v1/user
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
)
.
send
({
realname
:
'
Testing
'
,
email
:
'
test2@example.com
'
,
});
});
test
(
'
successfully returns
'
,
async
()
=>
{
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
});
test
(
'
the current user now contains the new information
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
user
.
email
).
toEqual
(
'
test2@example.com
'
);
expect
(
response
.
body
.
user
.
realname
).
toEqual
(
'
Testing
'
);
});
test
(
'
the current user still contains the same username and id
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
user
.
id
).
toEqual
(
'
00000000-0000-4000-8000-000000000000
'
);
expect
(
response
.
body
.
user
.
username
).
toEqual
(
'
user0
'
);
});
afterAll
(
async
()
=>
{
await
request
.
put
(
'
/v1/user
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
)
.
send
({
realname
:
'
Testing Tester
'
,
email
:
'
test0@example.com
'
,
});
})
});
describe
(
'
GET /user/:uuid
'
,
()
=>
{
test
(
'
returns the user that is requested
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000001
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
user
.
id
).
toEqual
(
'
00000000-0000-4000-8000-000000000001
'
);
expect
(
response
.
body
.
user
.
username
).
toEqual
(
'
user1
'
);
expect
(
response
.
body
.
user
.
email
).
toEqual
(
'
test1@example.com
'
);
expect
(
response
.
body
.
user
.
realname
).
toEqual
(
'
Tester Testing
'
);
});
});
});
});
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