Skip to content

Commit d8234d9

Browse files
committed
fixed tests - generateAuthToken arg updated to have key userId
1 parent e8eea13 commit d8234d9

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

test/integration/wallet.test.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,58 +58,40 @@ describe('Wallet', function () {
5858
return done()
5959
})
6060
})
61-
})
6261

63-
describe('GET /wallet/:username of own username', function () {
64-
it('Should return the user their own wallet', function (done) {
65-
chai
66-
.request(app)
67-
.get('/wallet/')
68-
.set('cookie', `${cookieName}=${authToken}`)
69-
.end((error, response) => {
70-
if (error) {
71-
return done(error)
72-
}
73-
74-
expect(response).to.have.status(200)
75-
expect(response.body.wallet.data.userId).to.be.equal(userId)
76-
77-
return done()
78-
})
79-
})
80-
})
81-
82-
describe('Check if the newly created wallet (by default we create a wallet for the new user) for the new user is pre-loader with 1000 dineros', function () {
8362
it('Should return the user their own wallet with 1000 dineros', function (done) {
8463
chai
8564
.request(app)
86-
.get('/wallet/')
65+
.get('/wallet')
8766
.set('cookie', `${cookieName}=${authToken}`)
8867
.end((error, response) => {
8968
if (error) {
9069
return done(error)
9170
}
9271

9372
expect(response).to.have.status(200)
73+
expect(response.body.wallet.data.userId).to.be.equal(userId)
74+
expect(response.body.message).to.be.equal('Wallet returned successfully for user')
9475
expect(response.body.wallet.data.currencies.dinero).to.be.equal(1000)
9576

9677
return done()
9778
})
9879
})
9980
})
10081

101-
describe('GET /wallet/:username of different user by an unauthorized user & unauthorized user', function () {
102-
let newUserName
82+
describe('GET /wallet/:username of different user by an unauthorized user & authorized user', function () {
10383
let newUserId
84+
let newUserAuthToken
85+
10486
let superUserId
10587
let superUserAuthToken
10688

10789
before(async function () {
10890
newUserId = await addUser(newUser)
109-
newUserName = await usersUtils.getUsername(newUserId)
91+
newUserAuthToken = authService.generateAuthToken({ userId: newUserId })
11092

11193
superUserId = await addUser(superUser)
112-
superUserAuthToken = authService.generateAuthToken({ superUserId })
94+
superUserAuthToken = authService.generateAuthToken({ userId: superUserId })
11395
})
11496

11597
it('Should return wallet when trying to access someone else\'s wallet, using authorized user (super_user)', function (done) {
@@ -122,9 +104,9 @@ describe('Wallet', function () {
122104
return done(error)
123105
}
124106

125-
expect(response).to.have.status(401)
126-
expect(response.body.error).to.be.equal('Unauthorized')
127-
expect(response.body.message).to.be.equal('You are not authorized for this action.')
107+
expect(response).to.have.status(200)
108+
expect(response.body.wallet.data.userId).to.be.equal(userId)
109+
expect(response.body.message).to.be.equal('Wallet returned successfully')
128110

129111
return done()
130112
})
@@ -133,12 +115,13 @@ describe('Wallet', function () {
133115
it('Should return unauthorized when trying to access someone else\'s wallet when not authorized', function (done) {
134116
chai
135117
.request(app)
136-
.get(`/wallet/${newUserName}`)
137-
.set('cookie', `${cookieName}=${authToken}`)
118+
.get(`/wallet/${userName}`)
119+
.set('cookie', `${cookieName}=${newUserAuthToken}`)
138120
.end((error, response) => {
139121
if (error) {
140122
return done(error)
141123
}
124+
142125
expect(response).to.have.status(401)
143126
expect(response.body.error).to.be.equal('Unauthorized')
144127
expect(response.body.message).to.be.equal('You are not authorized for this action.')

0 commit comments

Comments
 (0)