UNPKG

twiliojs-api

Version:

Module to invoke twilio.com services

75 lines (66 loc) 2.64 kB
var assert = require("assert"); var nock = require("nock"); var API = require("../index.js"); describe("twilio API", function () { var config = null; beforeEach( function (done) { config = { accountSid: 'accountSid', accountToken: 'pwd' }; done(); }); describe("constructor", function () { it("should throw if no accountSid was accountTokened into config", function ( done ) { try { new API( { credential: "foo"} ); throw new Error ("Had to be thrown") } catch ( e ) { assert.ok(e); assert.ok(e instanceof Error); assert.ok(e.message.indexOf("'config.accountSid'") > -1); done(); } }); it("should throw if invalid accountSid type was accountTokened into config", function ( done ) { try { new API( { credential: "foo", accountSid: 1 }); throw new Error ("Had to be thrown") } catch ( e ) { assert.ok(e); assert.ok(e instanceof Error); assert.ok(e.message.indexOf("'config.accountSid'") > -1); done(); } }); it("should throw if no accountToken was accountTokened into config", function ( done ) { try { new API( { credential: "cred", accountSid: "accountSid" } ); throw new Error ("Had to be thrown") } catch ( e ) { assert.ok(e); assert.ok(e instanceof Error); assert.ok(e.message.indexOf("'config.accountToken'") > -1); done(); } }); it("should throw if invalid accountToken type was accountTokened into config", function ( done ) { try { new API( { credential: "cred", accountSid: "accountSid", accountToken: 1 }); throw new Error ("Had to be thrown") } catch ( e ) { assert.ok(e); assert.ok(e instanceof Error); assert.ok(e.message.indexOf("'config.accountToken'") > -1); done(); } }); it("should be able to create an instance", function ( done ) { var api = new API({ accountSid: "accountSid", accountToken: "accountToken" }); assert.ok(api instanceof API); assert.equal("accountSid", api.config.accountSid); assert.equal("accountToken", api.config.accountToken); done(); }); }); });