Skip to content

Commit b42e3b5

Browse files
authored
Merge pull request #354 from bhk31/website-backend-349
Integration tests for task/:username route
2 parents 09c53d8 + a782a22 commit b42e3b5

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

test/integration/tasks.test.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('Tasks', function () {
3232
startedOn: 4567,
3333
status: 'active',
3434
percentCompleted: 10,
35-
participants: [appOwner.username],
35+
participants: [],
36+
assignee: appOwner.username,
3637
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
3738
lossRate: { [DINERO]: 1 },
3839
isNoteworthy: true
@@ -115,7 +116,13 @@ describe('Tasks', function () {
115116
expect(res.body.message).to.equal('Tasks returned successfully!')
116117
expect(res.body.tasks).to.be.a('array')
117118
const taskWithParticipants = res.body.tasks[0]
118-
expect(taskWithParticipants.participants).to.have.members([appOwner.username])
119+
120+
if (taskWithParticipants.type === 'group') {
121+
expect(taskWithParticipants.participants).to.include(appOwner.username)
122+
} else {
123+
expect(taskWithParticipants.assignee).to.equal(appOwner.username)
124+
}
125+
119126
return done()
120127
})
121128
})
@@ -249,4 +256,42 @@ describe('Tasks', function () {
249256
})
250257
})
251258
})
259+
260+
describe('GET /tasks/:username', function () {
261+
it('Should return 200 when username is valid', function (done) {
262+
chai
263+
.request(app)
264+
.get(`/tasks/${appOwner.username}`)
265+
.end((err, res) => {
266+
if (err) { return done(err) }
267+
expect(res).to.have.status(200)
268+
expect(res.body).to.be.a('object')
269+
expect(res.body.message).to.equal('Tasks returned successfully!')
270+
271+
const task1 = res.body.tasks[0]
272+
273+
if (task1.type === 'group') {
274+
expect(task1.participants).to.include(appOwner.username)
275+
} else {
276+
expect(task1.assignee).to.equal(appOwner.username)
277+
}
278+
279+
expect(res.body.tasks).to.be.a('array')
280+
return done()
281+
})
282+
})
283+
284+
it('Should return 404 when username is invalid', function (done) {
285+
chai
286+
.request(app)
287+
.get('/tasks/dummyUser')
288+
.end((err, res) => {
289+
if (err) { return done(err) }
290+
expect(res).to.have.status(404)
291+
expect(res.body).to.be.a('object')
292+
expect(res.body.message).to.equal('User doesn\'t exist')
293+
return done()
294+
})
295+
})
296+
})
252297
})

0 commit comments

Comments
 (0)