From 8040b6aea2f7dde6dbe8a474d668b6aef3186365 Mon Sep 17 00:00:00 2001 From: Pavlo Zhukov Date: Tue, 24 Jul 2018 22:12:14 +0300 Subject: [PATCH] Implement possibility to work with Zoho sandbox --- lib/node-zoho.coffee | 4 ++++ lib/products/crm/index.coffee | 3 ++- spec/unit/crm/crm-product-spec.coffee | 4 ++++ spec/unit/node-zoho-spec.coffee | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/node-zoho.coffee b/lib/node-zoho.coffee index 8dfd35c..36c21ac 100644 --- a/lib/node-zoho.coffee +++ b/lib/node-zoho.coffee @@ -1,11 +1,15 @@ class Zoho authToken: null + isSandbox: false region: 'com' constructor: (options = {}) -> if options.region? @region = options.region + if options.isSandbox? + @isSandbox = options.isSandbox + @authDefaults = host: "accounts.zoho.#{@region}" port: 443 diff --git a/lib/products/crm/index.coffee b/lib/products/crm/index.coffee index 4acff0f..bf2cc82 100644 --- a/lib/products/crm/index.coffee +++ b/lib/products/crm/index.coffee @@ -23,8 +23,9 @@ class CrmProduct extends BaseProduct return 'crmapi' getBaseUrl: -> + sandboxPart = if @zoho.isSandbox then 'sandbox' else '' return { - hostname: "crm.zoho.#{@zoho.region}" + hostname: "crm#{sandboxPart}.zoho.#{@zoho.region}" protocol: 'https' query: { authtoken: @zoho.authToken diff --git a/spec/unit/crm/crm-product-spec.coffee b/spec/unit/crm/crm-product-spec.coffee index 105c0c2..510be30 100644 --- a/spec/unit/crm/crm-product-spec.coffee +++ b/spec/unit/crm/crm-product-spec.coffee @@ -42,6 +42,10 @@ describe 'crm', -> it 'returns hosnamet: crm.zoho.com', -> expect(Crm.getBaseUrl().hostname).toBe('crm.zoho.com') + it 'returns hostname: crm.zoho.com', -> + sandboxCrm = new CrmProduct(Object.assign({isSandbox: true}, zoho)) + expect(sandboxCrm.getBaseUrl().hostname).toBe('crmsandbox.zoho.com') + it 'protocol https', -> expect(Crm.getBaseUrl().protocol).toBe('https') diff --git a/spec/unit/node-zoho-spec.coffee b/spec/unit/node-zoho-spec.coffee index 27be1cd..42d5752 100644 --- a/spec/unit/node-zoho-spec.coffee +++ b/spec/unit/node-zoho-spec.coffee @@ -86,3 +86,12 @@ describe "node-zoho", -> options.region = 'eu' zohoApi = new zoho(options) expect(zohoApi.region).toEqual('eu') + + describe "test Zoho sandbox mode", -> + it "has default disabled sandbox mode", -> + expect(zohoApi.isSandbox).toEqual(false) + + it "has enabled sandbox mode", -> + tempOptions = Object.assign({isSandbox: true}, options) + tempZohoApi = new zoho(tempOptions) + expect(tempZohoApi.isSandbox).toEqual(true)