Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement possibility to work with Zoho sandbox #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/node-zoho.coffee
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/products/crm/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/crm/crm-product-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
9 changes: 9 additions & 0 deletions spec/unit/node-zoho-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)