Skip to content

Commit da3c104

Browse files
authored
Fixed and written all the missing test cases (#172)
* update code * fixed failing test cases and missing test cases
1 parent 94ec342 commit da3c104

13 files changed

+154
-44
lines changed

.env.dev

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PORT=5000
22
NODE_ENV="development"
33
JWT_SECRET="thisismysupersecrettokenjustkidding"
4-
DATABASE_URL="mongodb://mongo:27017/donut-development"
4+
DATABASE_URL"mongodb://mongo:27017/donut-development"
55
SENDGRID_API_KEY='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'
66
SOCKET_PORT=8810
77
clientbaseurl = "http://localhost:3000/"

app/controllers/comment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ module.exports = {
7878
.sort({ updatedAt: -1 })
7979
.lean()
8080
.exec()
81-
if (!comments) {
81+
if (comments === undefined || comments.length === 0) {
8282
return res.status(HttpStatus.NOT_FOUND).json({ error: 'No such post' })
8383
}
84-
res.status(HttpStatus.OK).json({ comments: comments })
84+
return res.status(HttpStatus.OK).json({ comments: comments })
8585
} catch (error) {
8686
HANDLER.handleError(res, error)
8787
}

app/controllers/organization.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ module.exports = {
335335
const org = await Organisation.find({})
336336
.lean()
337337
.exec()
338-
if (org.length == 0) {
338+
if (org.length === 0) {
339339
return res.status(HttpStatus.NOT_FOUND).json({ error: 'No such organization exists!' })
340340
}
341341
return res.status(HttpStatus.OK).json({ methods: org[0].options.authentication })
342-
} catch(error) {
342+
} catch (error) {
343343
HANDLER.handleError(res, error)
344344
}
345345
}

app/controllers/post.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module.exports = {
181181
default:
182182
}
183183
await post.save()
184-
res.status(HttpStatus.OK).json({ post: post })
184+
return res.status(HttpStatus.OK).json({ post: post })
185185
} catch (error) {
186186
HANDLER.handleError(res, error)
187187
}
@@ -233,19 +233,16 @@ module.exports = {
233233
default:
234234
}
235235
await post.save()
236-
res.status(HttpStatus.OK).json({ post: post })
236+
return res.status(HttpStatus.OK).json({ post: post })
237237
} catch (error) {
238238
HANDLER.handleError(res, error)
239239
}
240240
},
241241

242242
getPostByUser: async (req, res, next) => {
243243
try {
244-
const posts = await PostModel.find(
245-
{ userId: req.params.id },
246-
{},
247-
helper.paginate(req)
248-
)
244+
const { id } = req.params
245+
const posts = await PostModel.find({ userId: id }, {}, helper.paginate(req))
249246
.populate('comments', ['content', 'votes'])
250247
.populate('userId', [
251248
'name.firstName',

app/controllers/user.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ module.exports = {
4646
// GET USER PROFILE
4747
userProfile: async (req, res, next) => {
4848
try {
49-
const id = req.params.id ? req.params.id : req.user._id
49+
const id = req.params.id || req.user._id
5050
const user = await User.findById({ _id: id })
51-
.populate('followings', [
51+
.populate('followings', [
5252
'name.firstName',
5353
'name.lastName',
5454
'info.about.designation',
@@ -255,16 +255,16 @@ module.exports = {
255255

256256
// ADD TO THE FOLLOWINGS LIST
257257
addFollowing: async (req, res, next) => {
258-
const { followId } = req.body
258+
const { id } = req.params
259259
try {
260-
if (followId === req.user._id) {
260+
if (id === req.user._id) {
261261
return res.status(HttpStatus.OK).json({ msg: 'You can not follow yourself!' })
262262
}
263263
const user = await User.findById(req.user.id)
264264
if (!user) {
265265
return res.status(HttpStatus.BAD_REQUEST).json({ msg: 'No such user exists!' })
266266
}
267-
user.followings.unshift(followId)
267+
user.followings.unshift(id)
268268
await user.save()
269269
next()
270270
} catch (error) {
@@ -274,9 +274,10 @@ module.exports = {
274274

275275
// ADD TO FOLLOWERS LIST
276276
addFollower: async (req, res, next) => {
277-
const { followId } = req.body
277+
console.log('follow request!')
278+
const { id } = req.params
278279
try {
279-
const user = await User.findById(followId)
280+
const user = await User.findById(id)
280281
if (!user) {
281282
return res.status(HttpStatus.BAD_REQUEST).json({ msg: 'No such user exists!' })
282283
}
@@ -305,15 +306,15 @@ module.exports = {
305306

306307
// REMOVE FROM FOLLOWINGS LIST
307308
removeFollowing: async (req, res, next) => {
308-
const { followId } = req.body
309+
const { id } = req.params
309310
try {
310311
const user = await User.findById(req.user._id)
311312
if (!user) {
312313
return res.status(HttpStatus.OK).json({ msg: 'No such user exists!' })
313314
}
314315
// check if followId is in following list or not
315316
const followingIdArray = user.followings.map(followingId => followingId._id)
316-
const isFollowingIdIndex = followingIdArray.indexOf(followId)
317+
const isFollowingIdIndex = followingIdArray.indexOf(id)
317318
if (isFollowingIdIndex === -1) {
318319
return res.status(HttpStatus.OK).json({ msg: 'You haven\'t followed the user!' })
319320
} else {
@@ -329,9 +330,9 @@ module.exports = {
329330

330331
// REMOVE FROM FOLLOWERS LIST
331332
removeFollower: async (req, res, next) => {
332-
const { followId } = req.body
333+
const { id } = req.params
333334
try {
334-
const user = await User.findById(followId)
335+
const user = await User.findById(id)
335336
if (!user) {
336337
return res.status(HttpStatus.NOT_FOUND).json({ msg: 'No such user exists!' })
337338
}

app/routes/user.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ router.post(
8282

8383
// follow the user
8484
router.patch(
85-
'/follow',
85+
'/follow/:id',
8686
isUnderMaintenance,
8787
auth,
8888
userController.addFollowing,
@@ -91,7 +91,7 @@ router.patch(
9191

9292
// unFollow the user
9393
router.patch(
94-
'/unfollow',
94+
'/unfollow/:id',
9595
isUnderMaintenance,
9696
auth,
9797
userController.removeFollowing,

config/mongoose.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mongoose
88
useFindAndModify: false
99
})
1010
.then(() => {
11+
console.log(`${process.env.DATABASE_URL}`)
1112
console.log('mongodb connection successful')
1213
})
1314
.catch((err) => {

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/event.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ test('Should get all the upcoming event', async (done) => {
293293

294294
test('Should get all the events created by user', async (done) => {
295295
await request(app)
296-
.get('/event/me/all')
296+
.get(`/event/${testUserId}/all`)
297297
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
298298
.send()
299299
.expect(HttpStatus.OK)

test/organisation.test.js

+91
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ const updatedTestOrg = {
3939
}
4040
}
4141

42+
const updateSettings = {
43+
settings: {
44+
enableEmail: true,
45+
language: 'German',
46+
timeFormat: '24'
47+
},
48+
permissions: {
49+
sendInvite: 'ADMINS',
50+
canCreateManage: 'MEMBERS',
51+
canChangeEmail: true,
52+
canChangeName: true
53+
},
54+
authentication: {
55+
email: true,
56+
google: true,
57+
github: true,
58+
gitlab: true
59+
}
60+
}
61+
4262
const testUser = {
4363
name: {
4464
firstName: 'test',
@@ -73,6 +93,7 @@ const testUser = {
7393
location: 'location'
7494
}
7595
},
96+
isAdmin: true,
7697
tokens: [{
7798
token: jwt.sign({
7899
_id: `${adminId}`
@@ -157,6 +178,76 @@ describe('PATCH /org/:id', () => {
157178
})
158179
})
159180

181+
/** GET ORGANIZATION LOGIN OPTIONS**/
182+
describe('GET login options', () => {
183+
test('Should retrieve the login options', async (done) => {
184+
const res = await request(app)
185+
.get('/org/login/options')
186+
.expect(HttpStatus.OK)
187+
expect(res.body).not.toBeNull()
188+
done()
189+
})
190+
})
191+
192+
/** UPDATE ORGANIZATION SETTINGS**/
193+
describe('UPDATE org-settings', () => {
194+
test('Should update org-settings', async (done) => {
195+
const res = await request(app)
196+
.patch(`/org/${orgId}/settings/update`)
197+
.set('Authorization', `Bearer ${token}`)
198+
.send(updateSettings)
199+
.expect(HttpStatus.OK)
200+
201+
// check res
202+
expect(res.body).not.toBeNull()
203+
done()
204+
})
205+
})
206+
207+
/** GET ORGANIZATION OVERVIEW**/
208+
describe('GET org overview', () => {
209+
test('Should retrieve the organization overview', async (done) => {
210+
const res = await request(app)
211+
.get('/org/overview/all')
212+
.set('Authorization', `Bearer ${token}`)
213+
.send()
214+
.expect(HttpStatus.OK)
215+
216+
// check response
217+
expect(res.body).not.toBeNull()
218+
done()
219+
})
220+
})
221+
222+
/** GET ALL MEMBERS **/
223+
describe('GET all members', () => {
224+
test('Should retrieve all the members of the org', async (done) => {
225+
const res = await request(app)
226+
.get('/org/members/all')
227+
.set('Authorization', `Bearer ${token}`)
228+
.send()
229+
.expect(HttpStatus.OK)
230+
231+
// check res
232+
expect(res.body).not.toBeNull()
233+
done()
234+
})
235+
})
236+
237+
/** REMOVE ADMIN**/
238+
describe('PATCH /org/remove/:orgId/:userId', () => {
239+
console.log('adminId ', adminId)
240+
test('Should remove the user', async (done) => {
241+
const res = await request(app)
242+
.patch(`/org/remove/${orgId}/${adminId}`)
243+
.set('Authorization', `Bearer ${token}`)
244+
.send()
245+
.expect(HttpStatus.BAD_REQUEST)
246+
expect(res.body).not.toBeNull()
247+
done()
248+
})
249+
})
250+
160251
/** DELETE ORGANIZATION**/
161252
describe('DELETE /org/:id', () => {
162253
test('Should delete the organization', async (done) => {

test/post.test.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,33 @@ test('Should update the Post data', async (done) => {
230230

231231
test('Should retrieve all posts created by a user', async (done) => {
232232
await request(app)
233-
.get('/post/me/all')
233+
.get(`/post/${testUserId}/all`)
234+
.set('Authorization', `Bearer ${token}`)
235+
.send()
236+
.expect(HttpStatus.OK)
237+
done()
238+
})
239+
240+
/**
241+
* Testing pin post of by particular user
242+
*/
243+
244+
test('Should pin the post', async (done) => {
245+
await request(app)
246+
.patch(`/post/pin/${testPostId}`)
247+
.set('Authorization', `Bearer ${token}`)
248+
.send()
249+
.expect(HttpStatus.OK)
250+
done()
251+
})
252+
253+
/**
254+
* Testing get all pinned post
255+
*/
256+
257+
test('Should retrieve all the pinned post', async (done) => {
258+
await request(app)
259+
.get('/post/all/pinned?pagination=10&page=1')
234260
.set('Authorization', `Bearer ${token}`)
235261
.send()
236262
.expect(HttpStatus.OK)

test/project.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ test('Should get project by id', async (done) => {
184184

185185
test('Should get all the project created by a user', async (done) => {
186186
await request(app)
187-
.get('/project/me/all')
187+
.get(`/project/${testUserId}/all`)
188188
.set('Authorization', `Bearer ${token}`)
189189
.send()
190190
.expect(HttpStatus.OK)

0 commit comments

Comments
 (0)