1 | xml2js = require("xml2js")
|
2 | zoho = require("../../lib/node-zoho")
|
3 |
|
4 | zohoApi = undefined
|
5 |
|
6 | describe "node-zoho", ->
|
7 |
|
8 | results = errors = done = undefined
|
9 |
|
10 | options =
|
11 | authToken: "TESTTOKEN"
|
12 |
|
13 | lead =
|
14 | "Lead Source" : "Site Registration"
|
15 | "First Name" : "Hannah"
|
16 | "Last Name" : "Smith"
|
17 | Email: "belfordz66@gmail.com"
|
18 |
|
19 | beforeEach ->
|
20 | zohoApi = new zoho(options)
|
21 | done = false
|
22 | results = errors = undefined
|
23 |
|
24 | describe "constructor", ->
|
25 |
|
26 | it "exists", ->
|
27 | expect(typeof zoho).toBe("function")
|
28 |
|
29 | it "sets @authToken", ->
|
30 | expect(zohoApi.authToken).toEqual(options.authToken)
|
31 |
|
32 | describe "instance", ->
|
33 |
|
34 | describe 'execute', ->
|
35 | _module = product = undefined
|
36 |
|
37 | beforeEach ->
|
38 | _module = { insertRecords: () ->}
|
39 | product = { getModule: () -> return _module }
|
40 | spyOn(zohoApi,'getProduct').andReturn(product)
|
41 | spyOn(_module,'insertRecords')
|
42 |
|
43 | it 'calls through', ->
|
44 | myCB = () ->
|
45 | return
|
46 | zohoApi.execute('crm','Leads','insertRecords',[], myCB)
|
47 | expect(_module.insertRecords).toHaveBeenCalledWith([],myCB)
|
48 |
|
49 | describe 'getProduct', ->
|
50 | it('returns instance product', ->
|
51 | )
|
52 |
|
53 | it('has product initialized with zoho instance', ->
|
54 | )
|
55 |
|
56 | it('throws error if product not found', ->
|
57 | )
|
58 |
|
59 | xdescribe "generateAuthToken", ->
|
60 | beforeEach ->
|
61 | spyOn(help, "request").andCallFake( ->
|
62 | cb = arguments[arguments.length-1]
|
63 |
|
64 | if typeof cb != "function"
|
65 | throw new Error("mockModelCb: the cb called is not a function.")
|
66 |
|
67 | setImmediate(cb, null, "AUTHTOKEN:123\n")
|
68 | )
|
69 |
|
70 | it "makes a call to help.request with proper data", ->
|
71 | runs ->
|
72 | zohoApi.generateAuthToken("cool@picatic.com", "seriously, cool", (err, res) ->
|
73 | results = res
|
74 | errors = err
|
75 | done = true
|
76 | )
|
77 | waitsFor -> return done
|
78 | runs ->
|
79 | expect(help.request).toHaveBeenCalledWith({ host : 'accounts.zoho.com', port : 443, path : '/apiauthtoken/nb/create?SCOPE=ZohoCRM/crmapi&EMAIL_ID=cool@picatic.com&PASSWORD=seriously, cool', method : 'POST' }, jasmine.any(Function))
|
80 |
|
81 | describe "test Zoho region", ->
|
82 | it "has default region", ->
|
83 | expect(zohoApi.region).toEqual('com')
|
84 |
|
85 | it "has specified region", ->
|
86 | options.region = 'eu'
|
87 | zohoApi = new zoho(options)
|
88 | expect(zohoApi.region).toEqual('eu')
|