Skip to content

Commit 5de1199

Browse files
Added the comented changes & keys to fixtures
1 parent 513df92 commit 5de1199

File tree

2 files changed

+42
-47
lines changed

2 files changed

+42
-47
lines changed

test/fixtures/auctions/auctions.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@ const auctionData = {
1414
end_time: Date.now() + 60 * 60 * 1000
1515
}
1616

17-
module.exports = auctionData
17+
const auctionKeys = [
18+
'auctions',
19+
'message'
20+
]
21+
22+
const auctionWithIdKeys = [
23+
'bidders_and_bids',
24+
'end_time',
25+
'highest_bid',
26+
'item',
27+
'quantity',
28+
'seller',
29+
'start_time'
30+
]
31+
32+
module.exports = { auctionData, auctionKeys, auctionWithIdKeys }

test/integration/auction.test.js

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable mocha/no-exclusive-tests */
2-
/* eslint-disable no-console */
31
const chai = require('chai')
42
const { expect } = chai
53
const chaiHttp = require('chai-http')
@@ -14,7 +12,7 @@ const { createWallet } = require('../../models/wallets')
1412

1513
// Import fixtures
1614
const userData = require('../fixtures/user/user')()
17-
const auctionData = require('../fixtures/auctions/auctions')
15+
const { auctionData, auctionKeys, auctionWithIdKeys } = require('../fixtures/auctions/auctions')
1816
const { initial_price: initialPrice, item_type: itemType, end_time: endTime, quantity } = auctionData
1917
const currenciesData = require('../fixtures/currencies/currencies')
2018

@@ -23,7 +21,7 @@ const cookieName = config.get('userToken.cookieName')
2321

2422
chai.use(chaiHttp)
2523

26-
describe.only('Auctions', function () {
24+
describe('Auctions', function () {
2725
let jwt
2826
let auctionId
2927

@@ -48,31 +46,13 @@ describe.only('Auctions', function () {
4846

4947
expect(res).to.have.status(200)
5048
expect(res.body).to.be.a('object')
49+
expect(res.body).to.have.all.keys(...auctionKeys)
5150
expect(res.body.message).to.be.equal('Auctions returned successfully!')
5251
expect(res.body.auctions).to.be.a('array')
5352

5453
return done()
5554
})
5655
})
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-
})
7656
})
7757

7858
describe('GET /auctions/:id', function () {
@@ -85,6 +65,7 @@ describe.only('Auctions', function () {
8565

8666
expect(res).to.have.status(200)
8767
expect(res.body).to.be.a('object')
68+
expect(res.body).to.have.all.keys(...auctionWithIdKeys)
8869
expect(res.body.seller).to.be.equal(userData[0].username)
8970

9071
return done()
@@ -142,19 +123,19 @@ describe.only('Auctions', function () {
142123
})
143124
})
144125

145-
it('Should return 404, for Auction not Found', function (done) {
126+
it('Should return 401, for Unauthenticated User', function (done) {
146127
chai
147128
.request(app)
148-
.post('/auction')
129+
.post('/auctions')
149130
.end((err, res) => {
150131
if (err) { return done(err) }
151132

152-
expect(res).to.have.status(404)
133+
expect(res).to.have.status(401)
153134
expect(res.body).to.be.a('object')
154135
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'
158139
})
159140

160141
return done()
@@ -180,55 +161,54 @@ describe.only('Auctions', function () {
180161
})
181162
})
182163

183-
it('Should be higher than the previous bid', function (done) {
164+
it('Should have a sufficient balance', function (done) {
184165
chai
185166
.request(app)
186167
.post(`/auctions/bid/${auctionId}`)
187168
.set('cookie', `${cookieName}=${jwt}`)
188-
.send({ bid: 50 })
169+
.send({ bid: 1001 })
170+
189171
.end((err, res) => {
190172
if (err) { return done(err) }
191173

192174
expect(res).to.have.status(403)
193175
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')
195177

196178
return done()
197179
})
198180
})
199181

200-
it('Should return 401, for Unauthenticated User', function (done) {
182+
it('Should be higher than the previous bid', function (done) {
201183
chai
202184
.request(app)
203-
.post('/auctions/bid/invalidId')
185+
.post(`/auctions/bid/${auctionId}`)
186+
.set('cookie', `${cookieName}=${jwt}`)
187+
.send({ bid: 50 })
204188
.end((err, res) => {
205189
if (err) { return done(err) }
206190

207-
expect(res).to.have.status(401)
191+
expect(res).to.have.status(403)
208192
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!')
214194

215195
return done()
216196
})
217197
})
218198

219-
it('Should return 404, for Bid not found', function (done) {
199+
it('Should return 401, for Unauthenticated User', function (done) {
220200
chai
221201
.request(app)
222-
.post('/auction/bids')
202+
.post('/auctions/bid/invalidId')
223203
.end((err, res) => {
224204
if (err) { return done(err) }
225205

226-
expect(res).to.have.status(404)
206+
expect(res).to.have.status(401)
227207
expect(res.body).to.be.a('object')
228208
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'
232212
})
233213

234214
return done()

0 commit comments

Comments
 (0)