Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spring2021-SellPoint
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
TDT4140-Group 58
Spring2021-SellPoint
Commits
2bef3ee1
Commit
2bef3ee1
authored
4 years ago
by
Jonny Ngo Luong
Browse files
Options
Downloads
Patches
Plain Diff
test: add test for category filtering on post (
#6
)
parent
f0e8b3dc
No related branches found
Branches containing commit
No related tags found
1 merge request
!9
Resolve "Organiser/Filtrere funksjon etter kategori"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/src/controllers/postController/index.ts
+0
-2
0 additions, 2 deletions
server/src/controllers/postController/index.ts
server/src/controllers/postController/tests/postController.test.ts
+28
-21
28 additions, 21 deletions
...c/controllers/postController/tests/postController.test.ts
with
28 additions
and
23 deletions
server/src/controllers/postController/index.ts
+
0
−
2
View file @
2bef3ee1
...
...
@@ -41,13 +41,11 @@ router.route("/").post(async (request: Request, response: Response) => {
// Get all posts `/api/post/?categoryid=`
router
.
route
(
"
/
"
).
get
(
async
(
request
:
Request
,
response
:
Response
)
=>
{
const
{
categoryid
}
=
request
.
query
as
{
[
key
:
string
]:
string
};
console
.
log
(
categoryid
);
try
{
let
input
=
`SELECT p.id, p.title, p.description, p.timestamp, p.owner, category.name, p.imageUrl
FROM post as p
INNER JOIN category ON category.categoryid = p.categoryid`
;
if
(
categoryid
)
input
+=
` WHERE p.categoryid=
${
categoryid
}
`
;
console
.
log
(
input
);
response
.
status
(
200
).
json
(
await
query
(
input
,
""
));
}
catch
(
error
)
{
response
.
status
(
400
).
send
(
"
Bad Request
"
);
...
...
This diff is collapsed.
Click to expand it.
server/src/controllers/postController/tests/postController.test.ts
+
28
−
21
View file @
2bef3ee1
import
request
from
'
supertest
'
;
import
app
from
'
../../../app
'
;
import
request
from
"
supertest
"
;
import
app
from
"
../../../app
"
;
describe
(
'
Test postController
'
,
()
=>
{
beforeAll
(
async
()
=>
{
// kjører før testing
console
.
log
(
"
Post controller test starting...
"
);
});
describe
(
"
Test postController
"
,
()
=>
{
beforeAll
(
async
()
=>
{
// kjører før testing
console
.
log
(
"
Post controller test starting...
"
);
});
afterAll
(
async
()
=>
{
// kjører når all testing er gått gjennom
console
.
log
(
"
...Test ending
"
);
});
afterAll
(
async
()
=>
{
// kjører når all testing er gått gjennom
console
.
log
(
"
...Test ending
"
);
});
it
(
'
Request /api/post should return request of 200!
'
,
async
()
=>
{
const
result
=
await
request
(
app
)
.
get
(
'
/api/post
'
)
.
send
()
it
(
"
Request /api/post should return request of 200!
"
,
async
()
=>
{
const
result
=
await
request
(
app
).
get
(
"
/api/post
"
).
send
();
expect
(
result
.
status
).
toBe
(
200
);
});
expect
(
result
.
status
).
toBe
(
200
);
});
it
(
'
Request /api/post/1 should return data with name "test"!
'
,
async
()
=>
{
const
result
=
await
request
(
app
).
get
(
'
/api/post/1
'
).
send
();
it
(
'
Request /api/post/1 should return data with name "test"!
'
,
async
()
=>
{
const
result
=
await
request
(
app
).
get
(
"
/api/post/1
"
).
send
();
expect
(
result
.
status
).
toBe
(
200
);
expect
(
result
.
body
.
data
[
0
]?.
title
).
toBe
(
'
test
'
);
});
expect
(
result
.
status
).
toBe
(
200
);
expect
(
result
.
body
.
data
[
0
]?.
title
).
toBe
(
"
test
"
);
});
it
(
'
Request /api/post/?categoryid=1 should return datas with categoryname = "Antikviteter og Kunst"
'
,
async
()
=>
{
const
result
=
await
request
(
app
).
get
(
"
/api/post/1
"
).
send
();
expect
(
result
.
status
).
toBe
(
200
);
expect
(
result
.
body
.
data
[
0
]?.
name
).
toBe
(
"
Antikviteter og Kunst
"
);
});
});
});
\ No newline at end of file
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