1
- /* eslint-disable mocha/no-exclusive-tests */
2
- /* eslint-disable no-console */
3
1
const chai = require ( 'chai' )
4
2
const { expect } = chai
5
3
const chaiHttp = require ( 'chai-http' )
@@ -14,7 +12,7 @@ const { createWallet } = require('../../models/wallets')
14
12
15
13
// Import fixtures
16
14
const userData = require ( '../fixtures/user/user' ) ( )
17
- const auctionData = require ( '../fixtures/auctions/auctions' )
15
+ const { auctionData, auctionKeys , auctionWithIdKeys } = require ( '../fixtures/auctions/auctions' )
18
16
const { initial_price : initialPrice , item_type : itemType , end_time : endTime , quantity } = auctionData
19
17
const currenciesData = require ( '../fixtures/currencies/currencies' )
20
18
@@ -23,7 +21,7 @@ const cookieName = config.get('userToken.cookieName')
23
21
24
22
chai . use ( chaiHttp )
25
23
26
- describe . only ( 'Auctions' , function ( ) {
24
+ describe ( 'Auctions' , function ( ) {
27
25
let jwt
28
26
let auctionId
29
27
@@ -48,31 +46,13 @@ describe.only('Auctions', function () {
48
46
49
47
expect ( res ) . to . have . status ( 200 )
50
48
expect ( res . body ) . to . be . a ( 'object' )
49
+ expect ( res . body ) . to . have . all . keys ( ...auctionKeys )
51
50
expect ( res . body . message ) . to . be . equal ( 'Auctions returned successfully!' )
52
51
expect ( res . body . auctions ) . to . be . a ( 'array' )
53
52
54
53
return done ( )
55
54
} )
56
55
} )
57
-
58
- it ( 'Should return 404, for Auction not Found' , function ( done ) {
59
- chai
60
- . request ( app )
61
- . get ( '/auction' )
62
- . end ( ( err , res ) => {
63
- if ( err ) { return done ( err ) }
64
-
65
- expect ( res ) . to . have . status ( 404 )
66
- expect ( res . body ) . to . be . a ( 'object' )
67
- expect ( res . body ) . to . deep . equal ( {
68
- statusCode : 404 ,
69
- error : 'Not Found' ,
70
- message : 'Not Found'
71
- } )
72
-
73
- return done ( )
74
- } )
75
- } )
76
56
} )
77
57
78
58
describe ( 'GET /auctions/:id' , function ( ) {
@@ -85,6 +65,7 @@ describe.only('Auctions', function () {
85
65
86
66
expect ( res ) . to . have . status ( 200 )
87
67
expect ( res . body ) . to . be . a ( 'object' )
68
+ expect ( res . body ) . to . have . all . keys ( ...auctionWithIdKeys )
88
69
expect ( res . body . seller ) . to . be . equal ( userData [ 0 ] . username )
89
70
90
71
return done ( )
@@ -142,19 +123,19 @@ describe.only('Auctions', function () {
142
123
} )
143
124
} )
144
125
145
- it ( 'Should return 404 , for Auction not Found ' , function ( done ) {
126
+ it ( 'Should return 401 , for Unauthenticated User ' , function ( done ) {
146
127
chai
147
128
. request ( app )
148
- . post ( '/auction ' )
129
+ . post ( '/auctions ' )
149
130
. end ( ( err , res ) => {
150
131
if ( err ) { return done ( err ) }
151
132
152
- expect ( res ) . to . have . status ( 404 )
133
+ expect ( res ) . to . have . status ( 401 )
153
134
expect ( res . body ) . to . be . a ( 'object' )
154
135
expect ( res . body ) . to . deep . equal ( {
155
- statusCode : 404 ,
156
- error : 'Not Found ' ,
157
- message : 'Not Found '
136
+ statusCode : 401 ,
137
+ error : 'Unauthorized ' ,
138
+ message : 'Unauthenticated User '
158
139
} )
159
140
160
141
return done ( )
@@ -180,55 +161,54 @@ describe.only('Auctions', function () {
180
161
} )
181
162
} )
182
163
183
- it ( 'Should be higher than the previous bid ' , function ( done ) {
164
+ it ( 'Should have a sufficient balance ' , function ( done ) {
184
165
chai
185
166
. request ( app )
186
167
. post ( `/auctions/bid/${ auctionId } ` )
187
168
. set ( 'cookie' , `${ cookieName } =${ jwt } ` )
188
- . send ( { bid : 50 } )
169
+ . send ( { bid : 1001 } )
170
+
189
171
. end ( ( err , res ) => {
190
172
if ( err ) { return done ( err ) }
191
173
192
174
expect ( res ) . to . have . status ( 403 )
193
175
expect ( res . body ) . to . be . a ( 'object' )
194
- expect ( res . body . message ) . to . be . equal ( 'Your bid was not higher than current one! ' )
176
+ expect ( res . body . message ) . to . be . equal ( 'You do not have sufficient money ' )
195
177
196
178
return done ( )
197
179
} )
198
180
} )
199
181
200
- it ( 'Should return 401, for Unauthenticated User ' , function ( done ) {
182
+ it ( 'Should be higher than the previous bid ' , function ( done ) {
201
183
chai
202
184
. request ( app )
203
- . post ( '/auctions/bid/invalidId' )
185
+ . post ( `/auctions/bid/${ auctionId } ` )
186
+ . set ( 'cookie' , `${ cookieName } =${ jwt } ` )
187
+ . send ( { bid : 50 } )
204
188
. end ( ( err , res ) => {
205
189
if ( err ) { return done ( err ) }
206
190
207
- expect ( res ) . to . have . status ( 401 )
191
+ expect ( res ) . to . have . status ( 403 )
208
192
expect ( res . body ) . to . be . a ( 'object' )
209
- expect ( res . body ) . to . deep . equal ( {
210
- statusCode : 401 ,
211
- error : 'Unauthorized' ,
212
- message : 'Unauthenticated User'
213
- } )
193
+ expect ( res . body . message ) . to . be . equal ( 'Your bid was not higher than current one!' )
214
194
215
195
return done ( )
216
196
} )
217
197
} )
218
198
219
- it ( 'Should return 404 , for Bid not found ' , function ( done ) {
199
+ it ( 'Should return 401 , for Unauthenticated User ' , function ( done ) {
220
200
chai
221
201
. request ( app )
222
- . post ( '/auction/bids ' )
202
+ . post ( '/auctions/bid/invalidId ' )
223
203
. end ( ( err , res ) => {
224
204
if ( err ) { return done ( err ) }
225
205
226
- expect ( res ) . to . have . status ( 404 )
206
+ expect ( res ) . to . have . status ( 401 )
227
207
expect ( res . body ) . to . be . a ( 'object' )
228
208
expect ( res . body ) . to . deep . equal ( {
229
- statusCode : 404 ,
230
- error : 'Not Found ' ,
231
- message : 'Not Found '
209
+ statusCode : 401 ,
210
+ error : 'Unauthorized ' ,
211
+ message : 'Unauthenticated User '
232
212
} )
233
213
234
214
return done ( )
0 commit comments