var CSCoreSDK = require('../build/cs-core-sdk.node.js'); describe('CSCoreSDK',function(){ it('Has config object attached', function(){ expect(CSCoreSDK.config).not.toBeNull(); }); it('I can set the shared web api key', function(){ CSCoreSDK.useWebApiKey("SOME-WEB-API-KEY"); expect(CSCoreSDK.config.webApiKey).toBe("SOME-WEB-API-KEY"); }); it('Allows configuration to be chained',function(){ CSCoreSDK.useWebApiKey("SOME-WEB-API-KEY") .useLanguage("en-US") .useRequestSigning('SomeKey') expect(CSCoreSDK.config.webApiKey).toBe("SOME-WEB-API-KEY"); expect(CSCoreSDK.config.language).toBe("en-US"); expect(CSCoreSDK.config.signingKey).toBe("SomeKey"); }) describe('WebApiClient',function(){ it('Throws an error when I try to use SDK client without api key',function(){ var client = new CSCoreSDK.WebApiClient(new CSCoreSDK.WebApiConfiguration()) expect( function(){client.callApi()} ).toThrow(new CSCoreSDK.ConfigurationError("You have to provide WEB-API-KEY to the SDK before calling the API!")) }); it('Throws an error when I try to use SDK client without language set',function(){ var config = new CSCoreSDK.WebApiConfiguration(); config.webApiKey = "Some key" config.language = '' var client = new CSCoreSDK.WebApiClient(config) expect( function(){client.callApi()} ).toThrow(new CSCoreSDK.ConfigurationError("You have to provide language in which to communicate with the API!")) }); }); });