|
| 1 | +var AuthorizationError = require('../../lib/errors/authorizationerror'); |
| 2 | + |
| 3 | + |
| 4 | +describe('AuthorizationError', function() { |
| 5 | + |
| 6 | + describe('constructed without a message', function() { |
| 7 | + var err = new AuthorizationError(); |
| 8 | + |
| 9 | + it('should have default properties', function() { |
| 10 | + expect(err.message).to.be.undefined; |
| 11 | + expect(err.code).to.equal('server_error'); |
| 12 | + expect(err.uri).to.be.undefined; |
| 13 | + expect(err.status).to.equal(500); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should format correctly', function() { |
| 17 | + expect(err.toString()).to.equal('AuthorizationError'); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('constructed with a message', function() { |
| 22 | + var err = new AuthorizationError('Invalid return URI'); |
| 23 | + |
| 24 | + it('should have default properties', function() { |
| 25 | + expect(err.message).to.equal('Invalid return URI'); |
| 26 | + expect(err.code).to.equal('server_error'); |
| 27 | + expect(err.uri).to.be.undefined; |
| 28 | + expect(err.status).to.equal(500); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should format correctly', function() { |
| 32 | + expect(err.toString()).to.equal('AuthorizationError: Invalid return URI'); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + describe('constructed with a message and access_denied code', function() { |
| 37 | + var err = new AuthorizationError('Access denied', 'access_denied'); |
| 38 | + |
| 39 | + it('should have default properties', function() { |
| 40 | + expect(err.message).to.equal('Access denied'); |
| 41 | + expect(err.code).to.equal('access_denied'); |
| 42 | + expect(err.uri).to.be.undefined; |
| 43 | + expect(err.status).to.equal(403); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('constructed with a message and server_error code', function() { |
| 48 | + var err = new AuthorizationError('Server error', 'server_error'); |
| 49 | + |
| 50 | + it('should have default properties', function() { |
| 51 | + expect(err.message).to.equal('Server error'); |
| 52 | + expect(err.code).to.equal('server_error'); |
| 53 | + expect(err.uri).to.be.undefined; |
| 54 | + expect(err.status).to.equal(502); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('constructed with a message and temporarily_unavailable code', function() { |
| 59 | + var err = new AuthorizationError('Temporarily unavailable', 'temporarily_unavailable'); |
| 60 | + |
| 61 | + it('should have default properties', function() { |
| 62 | + expect(err.message).to.equal('Temporarily unavailable'); |
| 63 | + expect(err.code).to.equal('temporarily_unavailable'); |
| 64 | + expect(err.uri).to.be.undefined; |
| 65 | + expect(err.status).to.equal(503); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('constructed with a message, code, uri and status', function() { |
| 70 | + var err = new AuthorizationError('Unsupported response type: foo', 'unsupported_response_type', 'http://www.example.com/oauth/help', 501); |
| 71 | + |
| 72 | + it('should have default properties', function() { |
| 73 | + expect(err.message).to.equal('Unsupported response type: foo'); |
| 74 | + expect(err.code).to.equal('unsupported_response_type'); |
| 75 | + expect(err.uri).to.equal('http://www.example.com/oauth/help'); |
| 76 | + expect(err.status).to.equal(501); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should format correctly', function() { |
| 80 | + expect(err.toString()).to.equal('AuthorizationError: Unsupported response type: foo'); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | +}); |
0 commit comments