import { expect } from 'chai'; import { Configuration, ProductionConfiguration, TestConfiguration } from '../../src/configuration'; describe('Configuration', () => { let instance: any; describe('constructor', () => { it('should construct', () => { expect(() => { new Configuration(); }).to.not.throw(); }); }); describe('constructed', () => { beforeEach(() => { instance = new Configuration(); }); describe('set', () => { it('should throw if nothing passed', () => { expect(() => { instance.set(); }).to.throw(); }); it('should throw if an array passed as first param', () => { expect(() => { instance.set([]); }).to.throw(); }); context('pass a string and value', () => { it('should throw if parameter string does not exist', () => { expect(() => { instance.set('testing'); }).to.throw(); }); it('should set the config variable', () => { instance.set('invoiceApiKey', 'testing'); expect(instance.get('invoiceApiKey')).to.equal('testing'); }); }); context('pass an object', () => { it('should throw if config object parameter does not exist', () => { expect(() => { instance.set({ invoiceApiKey: 'test', testing: test }); }).to.throw(); }); it('should set the config variables', () => { const invoiceApiKey = 'invoiceApiKeyTest'; const sessionApiKey = "sessionsApiKeyTest"; instance.set({ invoiceApiKey, sessionApiKey, }); expect(instance.get("invoiceApiKey")).to.equal(invoiceApiKey); expect(instance.get("sessionApiKey")).to.equal(sessionApiKey); }); }); }); describe('get', () => { it('should throw if nothing passed', () => { expect(() => { instance.get(); }).to.throw(); }); it('should throw if config parameter does not exist', () => { expect(() => { instance.get('testing'); }).to.throw(); }); it('should throw if the parameter is not set', () => { expect(() => { instance.get('invoiceApiKey'); }).to.throw(); }); it('should return the value that has been set', () => { const invoiceApiKey = 'invoiceApiKeyTest'; instance.set('invoiceApiKey', invoiceApiKey); expect(instance.get('invoiceApiKey')).to.equal(invoiceApiKey); }); }); }); }); describe('ProductionConfiguration', () => { let instance: any; beforeEach(() => { instance = new ProductionConfiguration(); }); it('returns property membershipApi', () => { expect(instance.config.membershipApi).to.equal('https://api.ft.com'); }); it('returns property paypalPaymentGateway', () => { expect(instance.config.paypalPaymentGateway).to.equal('Paypal Gateway'); }); it('returns property requestUserPurgeEndpoint', () => { expect(instance.config.requestUserPurgeEndpoint).to.equal('https://request-user-purge-svc-eu-prod.memb.ft.com'); }); it('property zuoraApi is null for production', () => { expect(instance.config.zuoraApi).to.equal(null); }); }); describe('TestConfiguration', () => { let instance: any; beforeEach(() => { instance = new TestConfiguration(); }); it('returns property membershipApi', () => { expect(instance.config.membershipApi).to.equal('https://api-t.ft.com'); }); it('returns property paypalPaymentGateway', () => { expect(instance.config.paypalPaymentGateway).to.equal('TEST - Paypal Gateway'); }); it('returns property requestUserPurgeEndpoint', () => { expect(instance.config.requestUserPurgeEndpoint).to.equal('https://request-user-purge-svc-eu-test.memb.ft.com'); }); it('returns property zuoraApi', () => { expect(instance.config.zuoraApi).to.equal('https://rest.apisandbox.zuora.com'); }); });