Skip to content

Commit 433cb54

Browse files
authored
Merge pull request #54 from SpaIns/LCS-83/Add-List-Route-Tests
Lcs 83/add list route tests
2 parents aaf0e08 + 65c18d2 commit 433cb54

File tree

8 files changed

+732
-95
lines changed

8 files changed

+732
-95
lines changed

server/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
"nyc": "^15.1.0"
2626
},
2727
"scripts": {
28-
"test": "env TESTING=true mocha ./tests/**/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
2928
"_comment": "Note: --exit in the test element is to force the test program to exit after finishing in case we use done()",
29+
"test": "env TESTING=true mocha ./tests/**/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
3030
"coverage": "nyc --reporter=lcov --reporter=text-lcov npm test",
3131
"authTest": "env TESTING=true mocha ./tests/Auth/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
3232
"authCoverage": "nyc --reporter=lcov --reporter=text-lcov npm run authTest",
3333
"userTest": "env TESTING=true mocha ./tests/Users/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
3434
"userCoverage": "nyc --reporter=lcov --reporter=text-lcov npm run userTest",
3535
"problemTest": "env TESTING=true mocha ./tests/Problems/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
3636
"problemCoverage": "nyc --reporter=lcov --reporter=text-lcov npm run problemTest",
37+
"listTest": "env TESTING=true mocha ./tests/Lists/*.test.js --exit --inspect=0.0.0.0:9299 --timeout 120000",
38+
"listCoverage": "nyc --reporter=lcov --reporter=text-lcov npm run listTest",
3739

3840
"start": "node server",
3941
"server": "nodemon server",

server/routes/api/auth.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const auth = require('../../middleware/auth')
21
const User = require('../../models/User')
32

43
const express = require('express')

server/routes/api/lists.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const router = express.Router()
1717
router.get('/', async (req, res) => {
1818
try {
1919
const lists = await List.find({public: true})
20-
if (!lists) {
20+
if (!lists || lists.length === 0) {
2121
return res.status(404).json({errors: [{msg: 'No lists found.'}]})
2222
}
2323
return res.json(lists)
@@ -34,7 +34,7 @@ router.get('/own', auth, async (req, res) => {
3434
try {
3535
const user = await User.findById(req.user.id)
3636
const lists = await List.find({creator: user._id})
37-
if (!lists) {
37+
if (!lists || lists.length === 0) {
3838
return res.status(404).json({errors: [{msg: 'You do not own any lists.'}]})
3939
}
4040
return res.json(lists)
@@ -45,7 +45,7 @@ router.get('/own', auth, async (req, res) => {
4545
})
4646

4747

48-
// @route GET api/lists/:id
48+
// @route GET api/lists/public/id/:id
4949
// @desc Get a public list by ID
5050
// @access Public
5151
router.get('/public/id/:id', async (req, res) => {
@@ -72,7 +72,7 @@ router.get('/public/id/:id', async (req, res) => {
7272
router.get('/public/search/:term', async (req, res) => {
7373
try {
7474
// If no term is passed, just return an empty array
75-
if (!req.params.term) {
75+
if (!req.params.term || req.params.term === '') {
7676
return res.json([])
7777
}
7878
const lists = await List.find({$and:
@@ -88,7 +88,7 @@ router.get('/public/search/:term', async (req, res) => {
8888
}
8989
})
9090

91-
// @route GET api/lists/:id
91+
// @route GET api/lists/private/:id
9292
// @desc Get a public list, or private list user owns
9393
// @access Private
9494
router.get('/private/:id', auth, async (req, res) => {
@@ -208,7 +208,7 @@ router.post('/', [auth, [
208208

209209
const numberOfLists = user.lists.length
210210
if (numberOfLists >= 100) {
211-
console.log('User already has ' + numberOfLists + ' lists.')
211+
console.log('User ' + user.name + ' already has ' + numberOfLists + ' lists.')
212212
// Prevent a user from owning more than 100 lists
213213
return res.status(401).json({errors: [{msg: 'You cannot have more than 100 lists.'}]})
214214
}

0 commit comments

Comments
 (0)