forked from andrewjmead/node-course-v3-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.test.js
More file actions
47 lines (43 loc) · 1.26 KB
/
task.test.js
File metadata and controls
47 lines (43 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const request = require('supertest')
const app = require('../src/app')
const Task = require('../src/models/task')
const {
userOneId,
userOne,
userTwoId,
userTwo,
taskOne,
taskTwo,
taskThree,
setupDatabase
} = require('./fixtures/db')
beforeEach(setupDatabase)
test('Should create task for user', async () => {
const response = await request(app)
.post('/tasks')
.set('Authorization', `Bearer ${userOne.tokens[0].token}`)
.send({
description: 'From my test'
})
.expect(201)
const task = await Task.findById(response.body._id)
expect(task).not.toBeNull()
expect(task.completed).toEqual(false)
})
test('Should fetch user tasks', async () => {
const response = await request(app)
.get('/tasks')
.set('Authorization', `Bearer ${userOne.tokens[0].token}`)
.send()
.expect(200)
expect(response.body.length).toEqual(2)
})
test('Should not delete other users tasks', async () => {
const response = await request(app)
.delete(`/tasks/${taskOne._id}`)
.set('Authorization', `Bearer ${userTwo.tokens[0].token}`)
.send()
.expect(404)
const task = await Task.findById(taskOne._id)
expect(task).not.toBeNull()
})