Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Commit b84ca3c

Browse files
Merge pull request #226 from anvilresearch/vsimonian-fix-error-middleware-tests
Fix tests for error-handling middleware
2 parents 2a83161 + c8aa469 commit b84ca3c

File tree

7 files changed

+135
-99
lines changed

7 files changed

+135
-99
lines changed

test/integration/rest/v1/clients.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe 'RESTful Client Routes', ->
6767

6868
before (done) ->
6969
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
70+
sinon.stub(Client, 'list').callsArgWith 1, null, []
7071
request
7172
.get('/v1/clients')
7273
.set('Authorization', 'Bearer valid.signed.token')
@@ -77,6 +78,7 @@ describe 'RESTful Client Routes', ->
7778

7879
after ->
7980
AccessToken.verify.restore()
81+
Client.list.restore()
8082

8183
it 'should respond 200', ->
8284
res.statusCode.should.equal 200
@@ -136,7 +138,7 @@ describe 'RESTful Client Routes', ->
136138
res.headers['content-type'].should.contain 'text/html'
137139

138140
it 'should respond with "Not found."', ->
139-
res.text.should.equal 'Not found.'
141+
res.text.should.contain 'Not found.'
140142

141143

142144
describe 'with valid token and known client id', ->
@@ -301,7 +303,7 @@ describe 'RESTful Client Routes', ->
301303
res.headers['content-type'].should.contain 'text/html'
302304

303305
it 'should respond with "Not found."', ->
304-
res.text.should.equal 'Not found.'
306+
res.text.should.contain 'Not found.'
305307

306308

307309
describe 'with valid data', ->
@@ -413,7 +415,7 @@ describe 'RESTful Client Routes', ->
413415
res.headers['content-type'].should.contain 'text/html'
414416

415417
it 'should respond with "Not found."', ->
416-
res.text.should.equal 'Not found.'
418+
res.text.should.contain 'Not found.'
417419

418420

419421
describe 'with valid request', ->

test/integration/rest/v1/roleScopes.coffee

+9-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe 'Role Scopes REST Routes', ->
6262
res.statusCode.should.equal 401
6363

6464
it 'should respond "Unauthorized"', ->
65-
res.text.should.equal 'Unauthorized'
65+
res.text.should.contain 'Unauthorized'
6666

6767

6868
describe 'by default', ->
@@ -158,7 +158,7 @@ describe 'Role Scopes REST Routes', ->
158158
res.headers['content-type'].should.contain 'text/html'
159159

160160
it 'should respond with "Not found" error', ->
161-
res.text.should.equal 'Not found.'
161+
res.text.should.contain 'Not found.'
162162

163163

164164

@@ -182,13 +182,15 @@ describe 'Role Scopes REST Routes', ->
182182
res.statusCode.should.equal 401
183183

184184
it 'should respond "Unauthorized"', ->
185-
res.text.should.equal 'Unauthorized'
185+
res.text.should.contain 'Unauthorized'
186186

187187

188188
describe 'with valid data', ->
189189

190190
before (done) ->
191191
role = new Role
192+
role.addScopes = (id, cb) ->
193+
cb()
192194
scope = scopes[0]
193195
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
194196
sinon.stub(Role, 'get').callsArgWith(1, null, role)
@@ -240,7 +242,7 @@ describe 'Role Scopes REST Routes', ->
240242
res.headers['content-type'].should.contain 'text/html'
241243

242244
it 'should respond with "Not found" error', ->
243-
res.text.should.equal 'Not found.'
245+
res.text.should.contain 'Not found.'
244246

245247

246248
describe 'with unknown scope', ->
@@ -270,7 +272,7 @@ describe 'Role Scopes REST Routes', ->
270272
res.headers['content-type'].should.contain 'text/html'
271273

272274
it 'should respond with "Not found" error', ->
273-
res.text.should.equal 'Not found.'
275+
res.text.should.contain 'Not found.'
274276

275277

276278

@@ -294,7 +296,7 @@ describe 'Role Scopes REST Routes', ->
294296
res.statusCode.should.equal 401
295297

296298
it 'should respond "Unauthorized"', ->
297-
res.text.should.equal 'Unauthorized'
299+
res.text.should.contain 'Unauthorized'
298300

299301

300302
describe 'with unknown role', ->
@@ -321,7 +323,7 @@ describe 'Role Scopes REST Routes', ->
321323
res.headers['content-type'].should.contain 'text/html'
322324

323325
it 'should respond with "Not found" error', ->
324-
res.text.should.equal 'Not found.'
326+
res.text.should.contain 'Not found.'
325327

326328

327329
describe 'with valid request', ->

test/integration/rest/v1/roles.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe 'RESTful Role Routes', ->
6363

6464
before (done) ->
6565
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
66+
sinon.stub(Role, 'list').callsArgWith 1, null, []
6667
request
6768
.get('/v1/roles')
6869
.set('Authorization', 'Bearer valid.signed.token')
@@ -73,6 +74,7 @@ describe 'RESTful Role Routes', ->
7374

7475
after ->
7576
AccessToken.verify.restore()
77+
Role.list.restore()
7678

7779
it 'should respond 200', ->
7880
res.statusCode.should.equal 200
@@ -132,7 +134,7 @@ describe 'RESTful Role Routes', ->
132134
res.headers['content-type'].should.contain 'text/html'
133135

134136
it 'should respond with "Not found."', ->
135-
res.text.should.equal 'Not found.'
137+
res.text.should.contain 'Not found.'
136138

137139

138140
describe 'with valid token and known role id', ->
@@ -297,7 +299,7 @@ describe 'RESTful Role Routes', ->
297299
res.headers['content-type'].should.contain 'text/html'
298300

299301
it 'should respond with "Not found."', ->
300-
res.text.should.equal 'Not found.'
302+
res.text.should.contain 'Not found.'
301303

302304

303305
describe 'with valid data', ->
@@ -409,7 +411,7 @@ describe 'RESTful Role Routes', ->
409411
res.headers['content-type'].should.contain 'text/html'
410412

411413
it 'should respond with "Not found."', ->
412-
res.text.should.equal 'Not found.'
414+
res.text.should.contain 'Not found.'
413415

414416

415417
describe 'with valid request', ->

test/integration/rest/v1/scopes.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe 'RESTful Scope Routes', ->
6363

6464
before (done) ->
6565
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
66+
sinon.stub(Scope, 'list').callsArgWith 1, null, []
6667
request
6768
.get('/v1/scopes')
6869
.set('Authorization', 'Bearer valid.signed.token')
@@ -73,6 +74,7 @@ describe 'RESTful Scope Routes', ->
7374

7475
after ->
7576
AccessToken.verify.restore()
77+
Scope.list.restore()
7678

7779
it 'should respond 200', ->
7880
res.statusCode.should.equal 200
@@ -132,7 +134,7 @@ describe 'RESTful Scope Routes', ->
132134
res.headers['content-type'].should.contain 'text/html'
133135

134136
it 'should respond with "Not found."', ->
135-
res.text.should.equal 'Not found.'
137+
res.text.should.contain 'Not found.'
136138

137139

138140
describe 'with valid token and known scope id', ->
@@ -297,7 +299,7 @@ describe 'RESTful Scope Routes', ->
297299
res.headers['content-type'].should.contain 'text/html'
298300

299301
it 'should respond with "Not found."', ->
300-
res.text.should.equal 'Not found.'
302+
res.text.should.contain 'Not found.'
301303

302304

303305
describe 'with valid data', ->
@@ -409,7 +411,7 @@ describe 'RESTful Scope Routes', ->
409411
res.headers['content-type'].should.contain 'text/html'
410412

411413
it 'should respond with "Not found."', ->
412-
res.text.should.equal 'Not found.'
414+
res.text.should.contain 'Not found.'
413415

414416

415417
describe 'with valid request', ->

test/integration/rest/v1/userRoles.coffee

+9-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe 'User Roles REST Routes', ->
6262
res.statusCode.should.equal 401
6363

6464
it 'should respond "Unauthorized"', ->
65-
res.text.should.equal 'Unauthorized'
65+
res.text.should.contain 'Unauthorized'
6666

6767

6868
describe 'by default', ->
@@ -158,7 +158,7 @@ describe 'User Roles REST Routes', ->
158158
res.headers['content-type'].should.contain 'text/html'
159159

160160
it 'should respond with "Not found" error', ->
161-
res.text.should.equal 'Not found.'
161+
res.text.should.contain 'Not found.'
162162

163163

164164

@@ -182,13 +182,15 @@ describe 'User Roles REST Routes', ->
182182
res.statusCode.should.equal 401
183183

184184
it 'should respond "Unauthorized"', ->
185-
res.text.should.equal 'Unauthorized'
185+
res.text.should.contain 'Unauthorized'
186186

187187

188188
describe 'with valid data', ->
189189

190190
before (done) ->
191191
user = new User
192+
user.addRoles = (id, cb) ->
193+
cb()
192194
role = roles[0]
193195
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
194196
sinon.stub(User, 'get').callsArgWith(1, null, user)
@@ -240,7 +242,7 @@ describe 'User Roles REST Routes', ->
240242
res.headers['content-type'].should.contain 'text/html'
241243

242244
it 'should respond with "Not found" error', ->
243-
res.text.should.equal 'Not found.'
245+
res.text.should.contain 'Not found.'
244246

245247

246248
describe 'with unknown role', ->
@@ -270,7 +272,7 @@ describe 'User Roles REST Routes', ->
270272
res.headers['content-type'].should.contain 'text/html'
271273

272274
it 'should respond with "Not found" error', ->
273-
res.text.should.equal 'Not found.'
275+
res.text.should.contain 'Not found.'
274276

275277

276278

@@ -294,7 +296,7 @@ describe 'User Roles REST Routes', ->
294296
res.statusCode.should.equal 401
295297

296298
it 'should respond "Unauthorized"', ->
297-
res.text.should.equal 'Unauthorized'
299+
res.text.should.contain 'Unauthorized'
298300

299301

300302
describe 'with unknown user', ->
@@ -321,7 +323,7 @@ describe 'User Roles REST Routes', ->
321323
res.headers['content-type'].should.contain 'text/html'
322324

323325
it 'should respond with "Not found" error', ->
324-
res.text.should.equal 'Not found.'
326+
res.text.should.contain 'Not found.'
325327

326328

327329
describe 'with valid request', ->

test/integration/rest/v1/users.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe 'RESTful User Routes', ->
6363

6464
before (done) ->
6565
sinon.stub(AccessToken, 'verify').callsArgWith(2, null, {})
66+
sinon.stub(User, 'list').callsArgWith 1, null, []
6667
request
6768
.get('/v1/users')
6869
.set('Authorization', 'Bearer valid.signed.token')
@@ -73,6 +74,7 @@ describe 'RESTful User Routes', ->
7374

7475
after ->
7576
AccessToken.verify.restore()
77+
User.list.restore()
7678

7779
it 'should respond 200', ->
7880
res.statusCode.should.equal 200
@@ -132,7 +134,7 @@ describe 'RESTful User Routes', ->
132134
res.headers['content-type'].should.contain 'text/html'
133135

134136
it 'should respond with "Not found."', ->
135-
res.text.should.equal 'Not found.'
137+
res.text.should.contain 'Not found.'
136138

137139

138140
describe 'with valid token and known user id', ->
@@ -297,7 +299,7 @@ describe 'RESTful User Routes', ->
297299
res.headers['content-type'].should.contain 'text/html'
298300

299301
it 'should respond with "Not found."', ->
300-
res.text.should.equal 'Not found.'
302+
res.text.should.contain 'Not found.'
301303

302304

303305
describe 'with valid data', ->
@@ -409,7 +411,7 @@ describe 'RESTful User Routes', ->
409411
res.headers['content-type'].should.contain 'text/html'
410412

411413
it 'should respond with "Not found."', ->
412-
res.text.should.equal 'Not found.'
414+
res.text.should.contain 'Not found.'
413415

414416

415417
describe 'with valid request', ->

0 commit comments

Comments
 (0)