@@ -2,11 +2,14 @@ const chai = require('chai');
2
2
3
3
const { expect } = chai ;
4
4
const chaiHttp = require ( 'chai-http' ) ;
5
- const app = require ( '../../../ app' ) ;
5
+ const app = require ( '../../app' ) ;
6
6
const { deleteTestUser, tokenInvalid } = require ( '../utils' ) ;
7
7
8
8
chai . use ( chaiHttp ) ;
9
9
10
+ let token ;
11
+ let res2 ;
12
+
10
13
describe ( 'TodoRouter' , ( ) => {
11
14
before ( async ( ) => {
12
15
await chai
@@ -80,7 +83,7 @@ describe('TodoRouter', () => {
80
83
it ( 'Should return 200 when a single todo is fetched' , async ( ) => {
81
84
const res = await chai
82
85
. request ( app ) . get ( `/api/todos/${ res2 . body . id } ` )
83
- . set ( 'Authorization' , `Bearer ${ token } ` )
86
+ . set ( 'Authorization' , `Bearer ${ token } ` ) ;
84
87
85
88
expect ( res ) . to . have . status ( 200 ) ;
86
89
expect ( res . body ) . to . include . keys ( 'id' , 'title' , 'UserId' , 'updatedAt' , 'createdAt' ) ;
@@ -89,7 +92,7 @@ describe('TodoRouter', () => {
89
92
it ( 'Should return 200 when all todos are fetched' , async ( ) => {
90
93
const res = await chai
91
94
. request ( app ) . get ( '/api/todos/' )
92
- . set ( 'Authorization' , `Bearer ${ token } ` )
95
+ . set ( 'Authorization' , `Bearer ${ token } ` ) ;
93
96
94
97
expect ( res ) . to . have . status ( 200 ) ;
95
98
expect ( res . body . data ) . to . be . a ( 'array' ) ;
@@ -98,7 +101,7 @@ describe('TodoRouter', () => {
98
101
it ( 'Should return 200 when all todos are fetched with pagination query params' , async ( ) => {
99
102
const res = await chai
100
103
. request ( app ) . get ( '/api/todos/?limit=1&page=1' )
101
- . set ( 'Authorization' , `Bearer ${ token } ` )
104
+ . set ( 'Authorization' , `Bearer ${ token } ` ) ;
102
105
103
106
expect ( res ) . to . have . status ( 200 ) ;
104
107
expect ( res . body . data ) . to . be . a ( 'array' ) ;
@@ -107,7 +110,7 @@ describe('TodoRouter', () => {
107
110
it ( 'Should return 200 when all todos are fetched with incorrect(negative) page query param' , async ( ) => {
108
111
const res = await chai
109
112
. request ( app ) . get ( '/api/todos/?page=-1' )
110
- . set ( 'Authorization' , `Bearer ${ token } ` )
113
+ . set ( 'Authorization' , `Bearer ${ token } ` ) ;
111
114
112
115
expect ( res ) . to . have . status ( 200 ) ;
113
116
expect ( res . body . data ) . to . be . a ( 'array' ) ;
@@ -116,7 +119,7 @@ describe('TodoRouter', () => {
116
119
it ( 'Should return 200 when all todos are fetched with incorrect(negative) limit query param' , async ( ) => {
117
120
const res = await chai
118
121
. request ( app ) . get ( '/api/todos/?limit=-1' )
119
- . set ( 'Authorization' , `Bearer ${ token } ` )
122
+ . set ( 'Authorization' , `Bearer ${ token } ` ) ;
120
123
121
124
expect ( res ) . to . have . status ( 200 ) ;
122
125
expect ( res . body . data ) . to . be . a ( 'array' ) ;
@@ -150,7 +153,7 @@ describe('TodoRouter', () => {
150
153
it ( 'Should return 404 when a todo does not exist' , async ( ) => {
151
154
const res = await chai
152
155
. request ( app )
153
- . delete ( ` /api/todos/10000` )
156
+ . delete ( ' /api/todos/10000' )
154
157
. set ( 'Authorization' , `Bearer ${ token } ` ) ;
155
158
156
159
expect ( res ) . to . have . status ( 404 ) ;
@@ -160,15 +163,15 @@ describe('TodoRouter', () => {
160
163
161
164
describe ( 'Todo Items actions' , ( ) => {
162
165
it ( 'Should return 201 when a todo item is created successfully' , async ( ) => {
163
- const res2 = await chai
166
+ const res3 = await chai
164
167
. request ( app )
165
168
. post ( '/api/todos' )
166
169
. set ( 'Authorization' , `Bearer ${ token } ` )
167
170
. send ( { title : 'I took Killgrave down' } ) ;
168
171
169
172
const res = await chai
170
173
. request ( app )
171
- . post ( `/api/todos/${ res2 . body . id } /items` )
174
+ . post ( `/api/todos/${ res3 . body . id } /items` )
172
175
. set ( 'Authorization' , `Bearer ${ token } ` )
173
176
. send ( { content : 'I beat the hell out of Luke Cage' } ) ;
174
177
@@ -177,21 +180,21 @@ describe('TodoRouter', () => {
177
180
} ) ;
178
181
179
182
it ( 'Should return 204 when a todo item is deleted successfully' , async ( ) => {
180
- const res2 = await chai
183
+ const resCreate = await chai
181
184
. request ( app )
182
185
. post ( '/api/todos' )
183
186
. set ( 'Authorization' , `Bearer ${ token } ` )
184
187
. send ( { title : 'I took Killgrave down' } ) ;
185
188
186
189
const res3 = await chai
187
190
. request ( app )
188
- . post ( `/api/todos/${ res2 . body . id } /items` )
191
+ . post ( `/api/todos/${ resCreate . body . id } /items` )
189
192
. set ( 'Authorization' , `Bearer ${ token } ` )
190
193
. send ( { content : 'I beat the hell out of Luke Cage' } ) ;
191
194
192
195
const res = await chai
193
196
. request ( app )
194
- . delete ( `/api/todos/${ res2 . body . id } /items/${ res3 . body . id } ` )
197
+ . delete ( `/api/todos/${ resCreate . body . id } /items/${ res3 . body . id } ` )
195
198
. set ( 'Authorization' , `Bearer ${ token } ` ) ;
196
199
197
200
expect ( res ) . to . have . status ( 204 ) ;
0 commit comments