Skip to content

Commit 8f4e63a

Browse files
Merge pull request #139 from Real-Dev-Squad/feature/tasks-integration-tests
Added the tasks integration tests
2 parents dbc0e07 + f9ab425 commit 8f4e63a

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
const chai = require('chai')
2+
const sinon = require('sinon')
3+
const { expect } = chai
4+
const chaiHttp = require('chai-http')
5+
6+
const app = require('../../server')
7+
const tasks = require('../../models/tasks')
8+
9+
chai.use(chaiHttp)
10+
11+
describe('Tasks', function () {
12+
let tid = ''
13+
before(async function () {
14+
const taskData = {
15+
title: 'Test Task',
16+
purpose: 'To Test mocha',
17+
featureUrl: '<testUrl>',
18+
type: 'Dev | Group',
19+
links: [
20+
'test1'
21+
],
22+
endsOn: '<unix timestamp>',
23+
startedOn: '<unix timestamp>',
24+
status: 'Active',
25+
ownerId: '<app owner user id>',
26+
percentCompleted: 10,
27+
dependsOn: [
28+
'd12',
29+
'd23'
30+
],
31+
participants: ['id1'],
32+
completionAward: { gold: 3, bronze: 300 },
33+
lossRate: { gold: 1 },
34+
isNoteWorthy: true
35+
}
36+
const { taskId } = await tasks.updateTask(taskData)
37+
tid = taskId
38+
})
39+
40+
afterEach(function () {
41+
sinon.restore()
42+
})
43+
44+
describe('POST /tasks - creates a new task', function () {
45+
it('Should return success response after adding the task', function (done) {
46+
chai
47+
.request(app)
48+
.post('/tasks')
49+
.send({
50+
title: 'Test Task',
51+
purpose: 'To Test mocha',
52+
featureUrl: '<testUrl>',
53+
type: 'Dev | Group',
54+
links: [
55+
'test1'
56+
],
57+
endsOn: '<unix timestamp>',
58+
startedOn: '<unix timestamp>',
59+
status: 'Active',
60+
ownerId: '<app owner user id>',
61+
percentCompleted: 10,
62+
dependsOn: [
63+
'd12',
64+
'd23'
65+
],
66+
participants: ['id1'],
67+
completionAward: { gold: 3, bronze: 300 },
68+
lossRate: { gold: 1 },
69+
isNoteworthy: true
70+
})
71+
.end((err, res) => {
72+
if (err) { return done() }
73+
expect(res).to.have.status(200)
74+
expect(res.body).to.be.a('object')
75+
expect(res.body.message).to.equal('Task created successfully!')
76+
expect(res.body.id).to.be.a('string')
77+
expect(res.body.task).to.be.a('object')
78+
79+
return done()
80+
})
81+
})
82+
})
83+
84+
describe('GET /tasks', function () {
85+
it('Should get all the list of tasks', function (done) {
86+
chai
87+
.request(app)
88+
.get('/tasks')
89+
.end((err, res) => {
90+
if (err) { return done() }
91+
expect(res).to.have.status(200)
92+
expect(res.body).to.be.a('object')
93+
expect(res.body.message).to.equal('Tasks returned successfully!')
94+
expect(res.body.tasks).to.be.a('array')
95+
96+
return done()
97+
})
98+
})
99+
})
100+
101+
describe('PATCH /tasks', function () {
102+
it('Should update the task for the given taskid', function (done) {
103+
chai
104+
.request(app)
105+
.patch('/tasks/' + tid)
106+
.send({
107+
ownerId: 'sumit'
108+
})
109+
.end((err, res) => {
110+
if (err) { return done() }
111+
expect(res).to.have.status(204)
112+
113+
return done()
114+
})
115+
})
116+
117+
it('Should return 404 if task does not exist', function (done) {
118+
chai
119+
.request(app)
120+
.patch('/tasks/taskid')
121+
.send({
122+
ownerId: 'umit'
123+
})
124+
.end((err, res) => {
125+
if (err) { return done() }
126+
expect(res).to.have.status(404)
127+
expect(res.body).to.be.a('object')
128+
expect(res.body.message).to.equal('Task not found')
129+
130+
return done()
131+
})
132+
})
133+
})
134+
})

0 commit comments

Comments
 (0)