UNPKG

imf-data-nodejs-sdk

Version:
114 lines (99 loc) 3.77 kB
/** * Copyright 2015 IBM Corp. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var assert = require('assert'); var IMFData = require('../lib/imfdata.js'); var config = require('./utils/config.js'); var tools = require('./utils/assert-tools.js'); var Errors = require('../lib/Errors.js'); var _ = require('underscore'); describe('IMFData', function() { describe('.initialize(config, [callback])', function() { it('should initialize the account and assert all functions are in the returned module', function(done) { this.timeout(1000); var imfdata = IMFData.initialize(config); tools.assertIMFDataPropsExist(imfdata); done(); }); it('should initialize the account and assert all functions are in the callback module', function(done) { this.timeout(10000); IMFData.initialize(config, function(err, imfdata, response) { assert.ifError(err); tools.assertIMFDataPropsExist(imfdata); done(); }); }); it('should assert the module in the returned value and in the callback are the same object', function(done) { this.timeout(10000); var data = IMFData.initialize(config, function(err, imfdata, response) { assert.ifError(err); assert.strictEqual(data, imfdata); done(); }); }); it('should throw if no configuration object', function(done) { try { IMFData.initialize(); done(new Error('#initialize() should have thrown an error')); } catch (e) { assert.ok(e); assert.equal(e.message, new Errors.IMFData_CONFIG().message); done(); } }); it('should throw if no appId', function(done) { try { IMFData.initialize({}); done(new Error('#initialize({}) should have thrown an error')); } catch (e) { assert.ok(e); assert.equal(e.message, new Errors.IMFData_CONFIG().message); done(); } }); it('should throw if upsupported language is set', function(done){ var configuration = _.clone(config); configuration.language = 'de-DE'; try { IMFData.initialize(configuration); done(new Error('#initialize(configuration) should have thrown an error')); } catch (e){ assert.ok(e); assert.equal(e.message, "Cannot find module '../locales/de-DE/translation.json'"); done(); } }); it('should return error in callback for bad secret', function(done) { this.timeout(10000); IMFData.initialize({ appId: config.appId, AdvancedMobileAccess: { tenantId: config.appId, clientId: config.appId, secret: 'badpass', serverUrl: config.AdvancedMobileAccess.serverUrl } }, function(err, imfdata, response) { assert.ok(err); done(); }); }); it('should assert all module constants', function() { assert.equal(IMFData.permissions.ADMINS, 'admins'); assert.equal(IMFData.permissions.MEMBERS, 'members'); assert.equal(IMFData.permissions.PUBLIC, 'public'); }); }); });