nebulab-dropbox
Version:
Client library for the Dropbox API
70 lines (53 loc) • 2.45 kB
text/coffeescript
describe 'Dropbox.AuthError', ->
describe '#constructor', ->
it 'throws an exception when given a non-error response', ->
expect(=>new Dropbox.AuthError(
access_token: 'token', token_type: 'Bearer')).to.throw(Error,
/oauth.*error/i)
describe 'with the RFC 6749 4.2.2 example', ->
beforeEach ->
= new Dropbox.AuthError error: 'access_denied', state: 'xyz'
it 'parses the error code', ->
expect().to.have.property 'code'
expect(.code).to.equal Dropbox.AuthError.ACCESS_DENIED
it "doesn't report a description", ->
expect(.description).to.equal null
it "doesn't report an URI", ->
expect(.uri).to.equal null
describe '#toString', ->
it 'reports the error code', ->
expect(.toString()).to.match(/access_denied/i)
it 'says it is related to OAuth', ->
expect(.toString()).to.match(/oauth.*error/i)
describe 'with a synthetic example', ->
beforeEach ->
= new Dropbox.AuthError(
error: 'invalid_scope',
error_description: 'The Dropbox API does not use scopes',
error_uri: 'http://error.uri', state: 'xyz')
it 'parses the error code', ->
expect().to.have.property 'code'
expect(.code).to.equal Dropbox.AuthError.INVALID_SCOPE
it 'parses the description', ->
expect(.description).to.equal 'The Dropbox API does not use scopes'
it 'parses the URI', ->
expect(.uri).to.equal 'http://error.uri'
describe '#toString', ->
it 'reports the error code', ->
expect(.toString()).to.match(/invalid_scope/i)
it 'reports the error description', ->
expect(.toString()).to.match(/not use scopes/i)
it 'says it is related to OAuth', ->
expect(.toString()).to.match(/oauth.*error/i)
describe 'with an API server example', ->
beforeEach ->
= new Dropbox.AuthError(
error: {
error: 'invalid_grant',
error_description: 'given "code" is not valid'
})
it 'parses the error code', ->
expect().to.have.property 'code'
expect(.code).to.equal Dropbox.AuthError.INVALID_GRANT
it 'parses the description', ->
expect(.description).to.equal 'given "code" is not valid'