Skip to content
Newer
Older
100644 99 lines (81 sloc) 3.02 KB
a449627 @mshafrir Initial commit.
authored
1 require 'spec_helper'
2
3 describe NutshellCrm::Client do
4 before :all do
5 @api_username = ENV['NUTSHELL_USERNAME']
6 @api_key = ENV['NUTSHELL_APIKEY']
bf9cd6a @mshafrir Remove API key from spec.
authored
7 @nutshell = NutshellCrm::Client.new @api_username, @api_key
a449627 @mshafrir Initial commit.
authored
8 @categories = ['Contacts', 'Accounts', 'Leads']
9 end
10
11 context 'client authentication errors' do
12 it 'should set up a new client instance with an invalid username and raise an error' do
13 lambda { NutshellCrm::Client.new('invalid@example.com', 'APIKEY123456') }.should raise_error
14 end
15
5d38577 @mshafrir Initial set of specs
authored
16 =begin
a449627 @mshafrir Initial commit.
authored
17 it 'should set up a new client instance with a valid username but invalid API key and raise an error' do
5d38577 @mshafrir Initial set of specs
authored
18 nutshell = NutshellCrm::Client.new(@api_username, 'APIKEY123456')
19 lambda { nutshell.find_leads({status: 0}) }.should raise_error
a449627 @mshafrir Initial commit.
authored
20 end
5d38577 @mshafrir Initial set of specs
authored
21 =end
a449627 @mshafrir Initial commit.
authored
22 end
23
24 subject { @nutshell }
25
26 context 'after a new Nutshell client has been instantiated' do
27 it 'should get a valid API service url that starts with https://' do
28 @nutshell.api_url.should match 'https://'
29 end
30
a6556b0 @mshafrir Create a test for new stub_responses property
authored
31 it 'should consider global stub_response property settings' do
32 @nutshell.stub_responses = false
33 @nutshell.find_leads({status: 0}).first['stub'].should_not be true
34 @nutshell.stub_responses = true
35 @nutshell.find_leads({status: 0}).first['stub'].should be true
36 @nutshell.stub_responses = nil
37 end
38
a449627 @mshafrir Initial commit.
authored
39 it 'should find open leads' do
40 @nutshell.find_leads({status: 0}).should_not be_empty
41 end
42
43 it 'should describe custom fields' do
44 custom_fields = @nutshell.describe_custom_fields
45 (custom_fields.all? {|k,v| @categories.include? k}).should be_true
46 end
47
48 it 'should find tags' do
49 tags = @nutshell.find_tags
50 (tags.all? {|k,v| @categories.include? k}).should be_true
51 end
52
53 it 'should get update times for each provisioning bin' do
54 @nutshell.get_update_times.should_not be_empty
55 end
5d38577 @mshafrir Initial set of specs
authored
56
57 it 'should return universal search results' do
58 @nutshell.search_universal('A').should_not be_empty
59 end
60
61 it 'should create a new tag and find it' do
62 lambda {
63 @nutshell.new_tag({name: 'FOO2', entityType: 'Leads'})
64 @nutshell.new_tag({name: 'FOO2', entityType: 'Leads'})
65 }.should raise_error
66 end
67
68 it 'should return product info' do
69 product = @nutshell.get_product(1)
70 product.should_not be_empty
71 end
72
73 it 'should return mobile settings' do
74 mobile_settings = @nutshell.get_mobile_settings
75 mobile_settings.should_not be_empty
76 end
77
78 it 'should return the logged in user' do
79 user = @nutshell.get_user
80 end
81
82 it 'should get and edit a lead' do
83 lead_id = 1001
84 lead = @nutshell.get_lead(lead_id)
85 rev = lead['rev']
86 @nutshell.edit_lead(lead_id, rev, {:description => 'Testing edit.'})
87 end
88
89 it 'should return the sources' do
90 @nutshell.search_sources('Cold')
91 end
14e8d6f @mshafrir Update a lead's process step status
authored
92
93 it 'should update a process step' do
94 step = @nutshell.get_lead(1001)['processes'][0]['steps'][0]
95 step['status'] = 2
96 @nutshell.edit_step(step['id'], step['rev'], step)
97 end
a449627 @mshafrir Initial commit.
authored
98 end
99 end
Something went wrong with that request. Please try again.