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
e4cca909
Commit
e4cca909
authored
3 years ago
by
Bernard Roland (Student Com20)
Browse files
Options
Downloads
Patches
Plain Diff
Added more tests, some of them fail
parent
01b17175
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/src/setupTests.ts
+1
-1
1 addition, 1 deletion
server/src/setupTests.ts
server/src/v1/user.test.ts
+109
-3
109 additions, 3 deletions
server/src/v1/user.test.ts
server/src/v1/user.ts
+5
-3
5 additions, 3 deletions
server/src/v1/user.ts
with
115 additions
and
7 deletions
server/src/setupTests.ts
+
1
−
1
View file @
e4cca909
...
...
@@ -234,7 +234,7 @@ async function loadTestData() {
id
:
'
00000000-0000-4000-8000-000000000002
'
,
task_id
:
'
00000000-0000-4000-8000-000000000005
'
,
user_id
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
new
Date
(
'
2020-10-1
0
T05:00:00
'
),
started
:
new
Date
(
'
2020-10-1
1
T05:00:00
'
),
finished
:
null
,
}
]);
...
...
This diff is collapsed.
Click to expand it.
server/src/v1/user.test.ts
+
109
−
3
View file @
e4cca909
...
...
@@ -2,6 +2,7 @@
import
supertest
from
'
supertest
'
;
import
{
api
}
from
'
../api
'
;
import
{
generateAuthToken
}
from
'
./auth
'
;
const
request
=
supertest
(
api
);
...
...
@@ -27,18 +28,123 @@ describe('/user/name', () => {
});
})
describe
(
'
/:uuid/image
'
,
()
=>
{
describe
(
'
/
user/
:uuid/image
'
,
()
=>
{
test
(
'
returns 404 without body if no image is set
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000000/image
'
);
expect
(
response
.
status
).
toEqual
(
404
);
expect
(
response
.
body
).
toEqual
({});
})
})
;
test
(
'
returns 404 if the user does not exist
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000002/image
'
);
expect
(
response
.
status
).
toEqual
(
404
);
expect
(
response
.
body
.
status
).
toEqual
(
'
error
'
);
})
});
test
(
'
returns the image if the user has an image
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/00000000-0000-4000-8000-000000000001/image
'
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
).
toBeTruthy
();
});
})
describe
(
'
/user
'
,
()
=>
{
test
(
'
returns the user that is authorized
'
,
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
'
);
expect
(
response
.
body
.
user
.
email
).
toEqual
(
'
test0@example.com
'
);
expect
(
response
.
body
.
user
.
realname
).
toEqual
(
'
Testing Tester
'
);
});
});
describe
(
'
/user/tasks
'
,
()
=>
{
test
(
'
returns the tasks the user is assigned to
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/tasks
'
)
.
set
(
'
Authorization
'
,
`Bearer
${
await
generateAuthToken
(
'
00000000-0000-4000-8000-000000000000
'
)}
`
);
expect
(
response
.
status
).
toEqual
(
200
);
expect
(
response
.
body
.
status
).
toEqual
(
'
success
'
);
expect
(
response
.
body
.
tasks
.
length
).
toEqual
(
1
);
expect
(
response
.
body
.
tasks
[
0
].
id
).
toEqual
(
'
00000000-0000-4000-8000-000000000005
'
);
});
});
describe
(
'
/user/work
'
,
()
=>
{
test
(
'
returns all the users work items
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
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
(
3
);
});
test
(
'
returns all finished work items
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
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
).
toContainEqual
({
id
:
'
00000000-0000-4000-8000-000000000000
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Date
(
'
2020-10-10T00:00:00
'
)).
toString
(),
finished
:
(
new
Date
(
'
2020-10-10T01:00:00
'
)).
toString
(),
});
expect
(
response
.
body
.
work
).
toContainEqual
({
id
:
'
00000000-0000-4000-8000-000000000001
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Date
(
'
2020-10-10T03:00:00
'
)).
toString
(),
finished
:
(
new
Date
(
'
2020-10-10T04:00:00
'
)).
toString
(),
});
});
test
(
'
returns unfinished work items
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/work
'
)
.
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
).
toContainEqual
({
id
:
'
00000000-0000-4000-8000-000000000002
'
,
task
:
'
00000000-0000-4000-8000-000000000005
'
,
user
:
'
00000000-0000-4000-8000-000000000000
'
,
started
:
(
new
Date
(
'
2020-10-11T05:00:00
'
)).
toString
(),
finished
:
null
,
});
});
test
(
'
can be limited in time with from date
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
`/v1/user/work?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
.
work
.
length
).
toEqual
(
1
);
});
});
describe
(
'
/user/activity
'
,
()
=>
{
test
(
'
returns time worked for all days
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/v1/user/activity
'
)
.
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
(
1
);
});
test
(
'
returns time worked for all days
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
`/v1/user/activity?to=
${
Date
.
parse
(
"
2020-10-20
"
)}
`
)
.
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
(
1
);
});
});
This diff is collapsed.
Click to expand it.
server/src/v1/user.ts
+
5
−
3
View file @
e4cca909
...
...
@@ -160,7 +160,8 @@ user.get('/tasks', async (req, res) => {
user
.
get
(
'
/work
'
,
async
(
req
,
res
)
=>
{
try
{
const
since
=
(
req
.
query
.
since
??
0
)
as
number
;
const
since
=
parseInt
(
req
.
query
.
since
as
string
??
0
);
const
to
=
parseInt
(
req
.
query
.
to
as
string
??
Date
.
now
());
const
work
=
await
database
(
'
workhours
'
)
.
select
({
id
:
'
workhours.id
'
,
...
...
@@ -173,6 +174,7 @@ user.get('/work', async (req, res) => {
'
workhours.user_id
'
:
req
.
body
.
token
.
id
,
})
.
andWhere
(
'
workhours.started
'
,
'
>=
'
,
since
)
.
andWhere
(
'
workhours.started
'
,
'
<=
'
,
to
)
.
groupBy
(
'
workhours.id
'
);
res
.
status
(
200
).
json
({
status
:
'
success
'
,
...
...
@@ -188,8 +190,8 @@ user.get('/work', async (req, res) => {
user
.
get
(
'
/activity
'
,
async
(
req
,
res
)
=>
{
try
{
const
since
=
(
req
.
query
.
since
??
0
)
as
number
;
const
to
=
(
req
.
query
.
to
??
Date
.
now
())
as
number
;
const
since
=
parseInt
(
req
.
query
.
since
as
string
??
0
)
;
const
to
=
parseInt
(
req
.
query
.
to
as
string
??
Date
.
now
());
const
activity
=
await
database
(
'
workhours
'
)
.
select
({
day
:
database
.
raw
(
'
Date(`started` / 1000,
\'
unixepoch
\'
)
'
),
...
...
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