|
| 1 | +var expect = require('chai').expect; |
| 2 | +var configFactory = require('../lib/config-factory'); |
| 3 | + |
| 4 | +describe('configFactory', function () { |
| 5 | + var result; |
| 6 | + |
| 7 | + describe('createConfig()', function () { |
| 8 | + |
| 9 | + describe('classic api', function () { |
| 10 | + var context = '/api'; |
| 11 | + var options = {target: 'http://www.example.org'}; |
| 12 | + |
| 13 | + beforeEach(function () { |
| 14 | + result = configFactory.createConfig(context, options); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return on config object', function () { |
| 18 | + expect(result).to.have.all.keys('context', 'options'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should return on config object with context', function () { |
| 22 | + expect(result.context).to.equal(context); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should return on config object with options', function () { |
| 26 | + expect(result.options).to.deep.equal(options); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('shorthand api', function () { |
| 31 | + beforeEach(function () { |
| 32 | + result = configFactory.createConfig('http://www.example.org:8000/api'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should return on config object', function () { |
| 36 | + expect(result).to.have.all.keys('context', 'options'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return on config object with context', function () { |
| 40 | + expect(result.context).to.equal('/api'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should return on config object with options', function () { |
| 44 | + expect(result.options).to.deep.equal({target: 'http://www.example.org:8000'}); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('shorthand api for whole domain', function () { |
| 49 | + beforeEach(function () { |
| 50 | + result = configFactory.createConfig('http://www.example.org:8000'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return on config object with context', function () { |
| 54 | + expect(result.context).to.equal('/'); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('shorthand api with globbing', function () { |
| 59 | + beforeEach(function () { |
| 60 | + result = configFactory.createConfig('http://www.example.org:8000/api/*.json'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should return on config object with context', function () { |
| 64 | + expect(result.context).to.equal('/api/*.json'); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('shorthand api with options', function () { |
| 69 | + beforeEach(function () { |
| 70 | + result = configFactory.createConfig('http://www.example.org:8000/api', {changeOrigin: true}); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should return on config object with additional options', function () { |
| 74 | + expect(result.options).to.deep.equal({target: 'http://www.example.org:8000', changeOrigin: true}); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe('missing option.target', function () { |
| 79 | + var fn |
| 80 | + beforeEach(function () { |
| 81 | + fn = function () { |
| 82 | + configFactory.createConfig('/api'); |
| 83 | + } |
| 84 | + }); |
| 85 | + |
| 86 | + it('should throw an error when target option is missing', function () { |
| 87 | + expect(fn).to.throw(Error); |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + |
| 92 | + }); |
| 93 | + |
| 94 | +}); |
| 95 | + |
0 commit comments