diff --git a/CHANGELOG.md b/CHANGELOG.md index ec5239ae..38f19e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 2.60 +- ADDED: Change host via the config object, using `apiHost` & `restHost` + ## 2.5.3 - FIXED: URI Encode Signed SMS Message diff --git a/README.md b/README.md index a4f35ed4..90f9c26a 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,11 @@ Options are: warn: function() {args...} }, // Set a custom timeout for requests to Nexmo in milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms. - timeout: integer + timeout: integer, + // Set a custom host for requests instead of api.nexmo.com + apiHost: string, + // Set a custom host for requests instead of rest.nexmo.com + restHost: string } ``` diff --git a/examples/config.js b/examples/config.js index 49d63294..b3fbb04b 100644 --- a/examples/config.js +++ b/examples/config.js @@ -18,7 +18,9 @@ var config = { CODE: process.env.CODE || '', APP_ID: process.env.APP_ID || '', PRIVATE_KEY: process.env.PRIVATE_KEY || '', - DEBUG: process.env.DEBUG === 'true' + DEBUG: process.env.DEBUG === 'true', + REST_HOST: process.env.REST_HOST || 'rest.nexmo.com', + API_HOST: process.env.API_HOST || 'api.nexmo.com' }; module.exports = config; diff --git a/examples/ex-change-api-host.js b/examples/ex-change-api-host.js new file mode 100644 index 00000000..6261dfcf --- /dev/null +++ b/examples/ex-change-api-host.js @@ -0,0 +1,50 @@ +module.exports = function(callback, config) { + + var Nexmo = require('../lib/Nexmo'); + + var nexmo = new Nexmo({ + apiKey: config.API_KEY, + apiSecret: config.API_SECRET + }, { + debug: config.DEBUG, + apiHost: config.API_HOST + }); + + nexmo.applications.create({ + name: 'My nexmo-node Example V2 App', + capabilities: { + voice: { + webhooks: { + answer_url: { + address: "https://example.com", + http_method: "GET" + }, + event_url: { + address: "https://example.com", + http_method: "POST" + } + } + }, + messages: { + webhooks: { + inbound_url: { + address: "https://example.com", + http_method: "POST" + }, + status_url: { + address: "https://example.com", + http_method: "POST" + } + } + }, + rtc: { + webhooks: { + event_url: { + address: "https://example.com", + http_method: "POST" + } + } + } + } + }, callback); +}; diff --git a/examples/ex-change-rest-host.js b/examples/ex-change-rest-host.js new file mode 100644 index 00000000..d9e6e45a --- /dev/null +++ b/examples/ex-change-rest-host.js @@ -0,0 +1,14 @@ +module.exports = function(callback, config) { + + var Nexmo = require('../lib/Nexmo'); + + var nexmo = new Nexmo({ + apiKey: config.API_KEY, + apiSecret: config.API_SECRET + }, { + debug: config.DEBUG, + restHost: config.REST_HOST + }); + + nexmo.message.sendSms(config.FROM_NUMBER, config.TO_NUMBER, 'testing', callback); +}; diff --git a/examples/run-examples.js b/examples/run-examples.js index 7eb70e51..59ac8b0c 100644 --- a/examples/run-examples.js +++ b/examples/run-examples.js @@ -53,6 +53,8 @@ function runExample(exampleFile, callback) { // By default all examples are run. // Use this array to run a select number of examples. exampleFiles = [ + // 'ex-change-api-host.js', + // 'ex-change-rest-host.js', // 'ex-check-balance.js', // 'ex-create-update-delete-app.js', // 'ex-dtmf-to-call.js', diff --git a/package-lock.json b/package-lock.json index e0869fd0..3fa4df80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nexmo", - "version": "2.5.3", + "version": "2.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7ea9bed6..e4c32705 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nexmo", "author": "nexmo", - "version": "2.5.3", + "version": "2.6.0", "main": "lib/Nexmo", "types": "./typings/index.d.ts", "keywords": [ diff --git a/src/App.js b/src/App.js index 5f5e99dc..ad508332 100644 --- a/src/App.js +++ b/src/App.js @@ -133,7 +133,7 @@ class App { const authorization = `${this.creds.apiKey}:${this.creds.apiSecret}`; var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: App.PATH, method: "POST", body: params, @@ -172,7 +172,7 @@ class App { } var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: Utils.createPathWithQuery(App.PATH, params), method: "GET", body: undefined, @@ -210,7 +210,7 @@ class App { const authorization = `${this.creds.apiKey}:${this.creds.apiSecret}`; var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: `${App.PATH}/${appId}`, method: "PUT", body: params, @@ -236,7 +236,7 @@ class App { const authorization = `${this.creds.apiKey}:${this.creds.apiSecret}`; var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: `${App.PATH}/${appId}`, method: "DELETE", body: "{}", diff --git a/src/CallsResource.js b/src/CallsResource.js index 8a8b08b7..d292459f 100644 --- a/src/CallsResource.js +++ b/src/CallsResource.js @@ -51,7 +51,7 @@ class CallsResource { params = JSON.stringify(params); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: CallsResource.PATH, method: "POST", body: params, @@ -87,7 +87,7 @@ class CallsResource { } var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: `${CallsResource.PATH}${pathExt}`, method: "GET", headers: { @@ -109,7 +109,7 @@ class CallsResource { params = JSON.stringify(params); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: `${CallsResource.PATH}/${callId}`, method: "PUT", body: params, diff --git a/src/DtmfResource.js b/src/DtmfResource.js index c98d8584..fb738cec 100644 --- a/src/DtmfResource.js +++ b/src/DtmfResource.js @@ -30,7 +30,7 @@ class DtmfResource { params = JSON.stringify(params); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: DtmfResource.PATH.replace("{call_uuid}", callId), method: "PUT", body: params, diff --git a/src/FilesResource.js b/src/FilesResource.js index e496c857..383a3dad 100644 --- a/src/FilesResource.js +++ b/src/FilesResource.js @@ -35,7 +35,7 @@ class FilesResource { fileIdOrUrl = fileIdOrUrl.split("/").pop(-1); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: `${FilesResource.PATH}/${fileIdOrUrl}`, method: "GET", headers: { diff --git a/src/Nexmo.js b/src/Nexmo.js index 067b07d2..1aa56dcf 100644 --- a/src/Nexmo.js +++ b/src/Nexmo.js @@ -64,17 +64,26 @@ class Nexmo { // This is legacy, everything should use rest or api going forward this.options.httpClient = new HttpClient( - Object.assign({ host: "rest.nexmo.com" }, this.options), + Object.assign( + { host: this.options.restHost || "rest.nexmo.com" }, + this.options + ), this.credentials ); // We have two different hosts, so we use two different HttpClients this.options.api = new HttpClient( - Object.assign({ host: "api.nexmo.com" }, this.options), + Object.assign( + { host: this.options.apiHost || "api.nexmo.com" }, + this.options + ), this.credentials ); this.options.rest = new HttpClient( - Object.assign({ host: "rest.nexmo.com" }, this.options), + Object.assign( + { host: this.options.restHost || "rest.nexmo.com" }, + this.options + ), this.credentials ); diff --git a/src/StreamResource.js b/src/StreamResource.js index 3208501c..ca7fbd4d 100644 --- a/src/StreamResource.js +++ b/src/StreamResource.js @@ -30,7 +30,7 @@ class StreamResource { params = JSON.stringify(params); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: StreamResource.PATH.replace("{call_uuid}", callId), method: "PUT", body: params, @@ -51,7 +51,7 @@ class StreamResource { */ stop(callId, callback) { var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: StreamResource.PATH.replace("{call_uuid}", callId), method: "DELETE", headers: { diff --git a/src/TalkResource.js b/src/TalkResource.js index deae7571..40d50c3b 100644 --- a/src/TalkResource.js +++ b/src/TalkResource.js @@ -30,7 +30,7 @@ class TalkResource { params = JSON.stringify(params); var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: TalkResource.PATH.replace("{call_uuid}", callId), method: "PUT", body: params, @@ -51,7 +51,7 @@ class TalkResource { */ stop(callId, callback) { var config = { - host: "api.nexmo.com", + host: this.options.apiHost || "api.nexmo.com", path: TalkResource.PATH.replace("{call_uuid}", callId), method: "DELETE", headers: { diff --git a/src/index.js b/src/index.js index d38355c8..14854f13 100644 --- a/src/index.js +++ b/src/index.js @@ -2,13 +2,34 @@ var querystring = require("querystring"); -var msgpath = { host: "rest.nexmo.com", path: "/sms/json" }; -var shortcodePath = { host: "rest.nexmo.com", path: "/sc/us/${type}/json" }; -var ttsEndpoint = { host: "api.nexmo.com", path: "/tts/json" }; -var ttsPromptEndpoint = { host: "api.nexmo.com", path: "/tts-prompt/json" }; -var callEndpoint = { host: "rest.nexmo.com", path: "/call/json" }; -var verifyEndpoint = { host: "api.nexmo.com", path: "/verify/json" }; -var checkVerifyEndpoint = { host: "api.nexmo.com", path: "/verify/check/json" }; +var msgpath = { + host: "rest.nexmo.com", + path: "/sms/json" +}; +var shortcodePath = { + host: "rest.nexmo.com", + path: "/sc/us/${type}/json" +}; +var ttsEndpoint = { + host: "api.nexmo.com", + path: "/tts/json" +}; +var ttsPromptEndpoint = { + host: "api.nexmo.com", + path: "/tts-prompt/json" +}; +var callEndpoint = { + host: "rest.nexmo.com", + path: "/call/json" +}; +var verifyEndpoint = { + host: "api.nexmo.com", + path: "/verify/json" +}; +var checkVerifyEndpoint = { + host: "api.nexmo.com", + path: "/verify/check/json" +}; var controlVerifyEndpoint = { host: "api.nexmo.com", path: "/verify/control/json" @@ -17,10 +38,22 @@ var searchVerifyEndpoint = { host: "api.nexmo.com", path: "/verify/search/json" }; -var niEndpoint = { host: "api.nexmo.com", path: "/ni/advanced/async/json" }; -var niBasicEndpoint = { host: "api.nexmo.com", path: "/ni/basic/json" }; -var niStandardEndpoint = { host: "api.nexmo.com", path: "/ni/standard/json" }; -var niAdvancedEndpoint = { host: "api.nexmo.com", path: "/ni/advanced/json" }; +var niEndpoint = { + host: "api.nexmo.com", + path: "/ni/advanced/async/json" +}; +var niBasicEndpoint = { + host: "api.nexmo.com", + path: "/ni/basic/json" +}; +var niStandardEndpoint = { + host: "api.nexmo.com", + path: "/ni/standard/json" +}; +var niAdvancedEndpoint = { + host: "api.nexmo.com", + path: "/ni/advanced/json" +}; var up = {}; var numberPattern = new RegExp("^[0-9 +()-]*$"); @@ -59,7 +92,7 @@ var ERROR_MESSAGES = { product: "Invalid product. Should be one of [voice, sms]" }; -exports.initialize = function(pkey, psecret, options) { +exports.initialize = function(pkey, psecret, options, hosts) { if (!pkey || !psecret) { throw "key and secret cannot be empty, set valid values"; } @@ -68,6 +101,25 @@ exports.initialize = function(pkey, psecret, options) { api_secret: psecret }; _options = options; + + if (_options.restHost) { + msgpath.host = _options.restHost; + shortcodePath.host = _options.restHost; + callEndpoint.host = _options.restHost; + } + + if (_options.apiHost) { + ttsEndpoint.host = _options.apiHost; + ttsPromptEndpoint.host = _options.apiHost; + verifyEndpoint.host = _options.apiHost; + checkVerifyEndpoint.host = _options.apiHost; + controlVerifyEndpoint.host = _options.apiHost; + searchVerifyEndpoint.host = _options.apiHost; + niEndpoint.host = _options.apiHost; + niBasicEndpoint.host = _options.apiHost; + niStandardEndpoint.host = _options.apiHost; + niAdvancedEndpoint.host = _options.apiHost; + } }; exports.sendBinaryMessage = function(sender, recipient, body, udh, callback) { @@ -577,18 +629,3 @@ function sendError(callback, err, returnData) { throw err; } } - -exports.setHost = function(aHost) { - msgpath.host = aHost; - shortcodePath.host = aHost; - ttsEndpoint.host = aHost; - ttsPromptEndpoint.host = aHost; - callEndpoint.host = aHost; - verifyEndpoint.host = aHost; - checkVerifyEndpoint.host = aHost; - controlVerifyEndpoint.host = aHost; - searchVerifyEndpoint.host = aHost; - niEndpoint.host = aHost; - niBasicEndpoint.host = aHost; - niStandardEndpoint.host = aHost; -}; diff --git a/test/App-test.js b/test/App-test.js index 72f55831..d359c5ad 100644 --- a/test/App-test.js +++ b/test/App-test.js @@ -147,6 +147,36 @@ describe("applications.create", function() { null ); }); + + it("should support host override", function() { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + applications = new App(creds, options); + applications.create({}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "POST", + host: "api.example.com", + path: App.PATH, + headers: { + "Content-Type": "application/json", + Authorization: "Basic " + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback, + emptyCallback, + false, + null + ); + }); }); describe("applications.update", function() { @@ -265,6 +295,36 @@ describe("applications.update", function() { null ); }); + + it("should support host override", function() { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + applications = new App(creds, options); + applications.update("app_id", {}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "PUT", + host: "api.example.com", + path: `${App.PATH}/app_id`, + headers: { + "Content-Type": "application/json", + Authorization: "Basic " + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback, + emptyCallback, + false, + null + ); + }); }); describe("applications.get", function() { @@ -349,6 +409,37 @@ describe("applications.get", function() { null ); }); + + it("should support host override", function() { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let applications = new App(creds, options); + applications.get("app_id", emptyCallback, true); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "GET", + host: "api.example.com", + path: `${App.PATH}/app_id`, + body: undefined, + headers: { + "Content-Type": "application/json", + Authorization: "Basic " + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback, + emptyCallback, + false, + null + ); + }); }); describe("applications.delete", function() { @@ -381,6 +472,33 @@ describe("applications.delete", function() { emptyCallback ); }); + + it("should allow host override", function() { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let applications = new App(creds, options); + applications.delete("app_id", emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "DELETE", + host: "api.example.com", + path: `${App.PATH}/app_id`, + headers: { + "Content-Type": "application/json", + Authorization: "Basic " + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); }); describe("applications._convertMethodSignature", function() { diff --git a/test/CallResource-test.js b/test/CallResource-test.js index 22b250c0..0f8e68b1 100644 --- a/test/CallResource-test.js +++ b/test/CallResource-test.js @@ -32,6 +32,84 @@ describe("CallsResource", () => { calls = new CallsResource(creds, options); }); + it("should support host override for calls.create", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + calls = new CallsResource(creds, options); + calls.create({}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "POST", + host: "api.example.com", + headers: { + "Content-Type": "application/json" + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + + it("should support host override for calls.update", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + calls = new CallsResource(creds, options); + calls.update("call_id", {}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "PUT", + host: "api.example.com", + path: `${CallsResource.PATH}/call_id`, + headers: { + "Content-Type": "application/json" + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + + it("should support host override for calls.update", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + calls = new CallsResource(creds, options); + calls.get("call_id", emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + method: "GET", + host: "api.example.com", + body: undefined, + path: `${CallsResource.PATH}/call_id`, + headers: { + "Content-Type": "application/json" + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + it("should allow a call to be created", () => { var params = { to: { diff --git a/test/DtmfResource-test.js b/test/DtmfResource-test.js index da4267e0..d52c3620 100644 --- a/test/DtmfResource-test.js +++ b/test/DtmfResource-test.js @@ -50,4 +50,31 @@ describe("DtmfResource", () => { emptyCallback ); }); + + it("should support host override", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let dtmf = new DtmfResource(creds, options); + const callId = "2342342-lkjhlkjh-32423"; + dtmf.send(callId, {}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + path: DtmfResource.PATH.replace("{call_uuid}", callId), + method: "PUT", + host: "api.example.com", + headers: { + "Content-Type": "application/json" + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); }); diff --git a/test/FilesResource-test.js b/test/FilesResource-test.js index fb13f1f4..68262431 100644 --- a/test/FilesResource-test.js +++ b/test/FilesResource-test.js @@ -29,6 +29,33 @@ describe("FileResource", () => { files = new FilesResource(creds, options); }); + it("should support host override", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let files = new FilesResource(creds, options); + const fileId = "2342342-lkjhlkjh-32423"; + files.get(fileId, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, { + method: "GET", + body: undefined, + host: "api.example.com", + path: `${FilesResource.PATH}/${fileId}`, + headers: { + "Content-Type": "application/octet-stream", + Authorization: "Bearer " + } + }); + + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + it("should get a single file using a file ID", () => { const fileId = "2342342-lkjhlkjh-32423"; files.get(fileId, emptyCallback); diff --git a/test/Nexmo-test.js b/test/Nexmo-test.js index 21b37d9b..57dfb7f8 100644 --- a/test/Nexmo-test.js +++ b/test/Nexmo-test.js @@ -229,6 +229,34 @@ describe("Nexmo Object instance", function() { ); }); + it("should allow api host change", function() { + var options = { + apiHost: "some.host.com" + }; + var nexmo = new Nexmo( + { + apiKey: "test", + apiSecret: "test" + }, + options + ); + expect(nexmo.options.apiHost).to.equal("some.host.com"); + }); + + it("should allow rest host change", function() { + var options = { + restHost: "some.host.com" + }; + var nexmo = new Nexmo( + { + apiKey: "test", + apiSecret: "test" + }, + options + ); + expect(nexmo.options.restHost).to.equal("some.host.com"); + }); + it("should create a JWT", () => { var nexmo = new Nexmo({ apiKey: "test", diff --git a/test/StreamResource-test.js b/test/StreamResource-test.js index 85bacc56..b38f7b90 100644 --- a/test/StreamResource-test.js +++ b/test/StreamResource-test.js @@ -51,6 +51,34 @@ describe("StreamResource", () => { ); }); + it("should support host override in stream.start", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let stream = new StreamResource(creds, options); + const callId = "2342342-lkjhlkjh-32423"; + stream.start(callId, {}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + path: StreamResource.PATH.replace("{call_uuid}", callId), + method: "PUT", + host: "api.example.com", + headers: { + "Content-Type": "application/json" + } + } + ); + + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + it("should be possible to stop a stream", () => { const callId = "2342342-lkjhlkjh-32423"; stream.stop(callId, emptyCallback); @@ -66,4 +94,27 @@ describe("StreamResource", () => { emptyCallback ); }); + + it("should support host override on stream.stop", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let stream = new StreamResource(creds, options); + const callId = "2342342-lkjhlkjh-32423"; + stream.stop(callId, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, { + method: "DELETE", + body: undefined, + host: "api.example.com", + path: StreamResource.PATH.replace("{call_uuid}", callId) + }); + + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); }); diff --git a/test/TalkResource-test.js b/test/TalkResource-test.js index 4e75face..09ff7c8a 100644 --- a/test/TalkResource-test.js +++ b/test/TalkResource-test.js @@ -50,6 +50,33 @@ describe("TalkResource", () => { ); }); + it("should support host override on talk.start", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let talk = new TalkResource(creds, options); + const callId = "2342342-lkjhlkjh-32423"; + talk.start(callId, {}, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch( + {}, + { + path: TalkResource.PATH.replace("{call_uuid}", callId), + method: "PUT", + host: "api.example.com", + headers: { + "Content-Type": "application/json" + } + } + ); + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); + it("should be able to start a talk with unicode characters", () => { const callId = "2342342-lkjhlkjh-32423"; var params = { @@ -86,4 +113,27 @@ describe("TalkResource", () => { emptyCallback ); }); + + it("should support host override on talk.stop", () => { + let httpClientStub = sinon.createStubInstance(HttpClient); + let options = { + httpClient: httpClientStub, + apiHost: "api.example.com" + }; + let talk = new TalkResource(creds, options); + const callId = "2342342-lkjhlkjh-32423"; + talk.stop(callId, emptyCallback); + + var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, { + method: "DELETE", + host: "api.example.com", + body: undefined, + path: TalkResource.PATH.replace("{call_uuid}", callId) + }); + + expect(httpClientStub.request).to.have.been.calledWith( + sinon.match(expectedRequestArgs), + emptyCallback + ); + }); });