Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 102 lines (83 sloc) 3.284 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
16 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
17 nutshell = NutshellCrm::Client.new(@api_username, 'APIKEY123456')
2717512 @mshafrir Use Ruby 1.8.7 hash.
authored
18 lambda { nutshell.find_leads({:status => 0}) }.should raise_error
a449627 @mshafrir Initial commit.
authored
19 end
20 end
21
22 subject { @nutshell }
23
24 context 'after a new Nutshell client has been instantiated' do
25 it 'should get a valid API service url that starts with https://' do
26 @nutshell.api_url.should match 'https://'
27 end
28
a6556b0 @mshafrir Create a test for new stub_responses property
authored
29 it 'should consider global stub_response property settings' do
30 @nutshell.stub_responses = false
fce25aa @mshafrir Fix update process step spec. Switch to Ruby 1.8.7 hash syntax.
authored
31 @nutshell.find_leads({:status => 0}).first['stub'].should_not be true
a6556b0 @mshafrir Create a test for new stub_responses property
authored
32 @nutshell.stub_responses = true
fce25aa @mshafrir Fix update process step spec. Switch to Ruby 1.8.7 hash syntax.
authored
33 @nutshell.find_leads({:status => 0}).first['stub'].should be true
a6556b0 @mshafrir Create a test for new stub_responses property
authored
34 @nutshell.stub_responses = nil
35 end
36
a449627 @mshafrir Initial commit.
authored
37 it 'should find open leads' do
fce25aa @mshafrir Fix update process step spec. Switch to Ruby 1.8.7 hash syntax.
authored
38 @nutshell.find_leads({:status => 0}).should_not be_empty
a449627 @mshafrir Initial commit.
authored
39 end
40
41 it 'should describe custom fields' do
42 custom_fields = @nutshell.describe_custom_fields
43 (custom_fields.all? {|k,v| @categories.include? k}).should be_true
44 end
45
46 it 'should find tags' do
47 tags = @nutshell.find_tags
48 (tags.all? {|k,v| @categories.include? k}).should be_true
49 end
50
51 it 'should get update times for each provisioning bin' do
52 @nutshell.get_update_times.should_not be_empty
53 end
5d38577 @mshafrir Initial set of specs
authored
54
55 it 'should return universal search results' do
56 @nutshell.search_universal('A').should_not be_empty
57 end
58
59 it 'should create a new tag and find it' do
60 lambda {
fce25aa @mshafrir Fix update process step spec. Switch to Ruby 1.8.7 hash syntax.
authored
61 @nutshell.new_tag({:name => 'FOO2', :entityType => 'Leads'})
62 @nutshell.new_tag({:name => 'FOO2', :entityType => 'Leads'})
5d38577 @mshafrir Initial set of specs
authored
63 }.should raise_error
64 end
65
66 it 'should return product info' do
67 product = @nutshell.get_product(1)
68 product.should_not be_empty
69 end
70
71 it 'should return mobile settings' do
72 mobile_settings = @nutshell.get_mobile_settings
73 mobile_settings.should_not be_empty
74 end
75
76 it 'should return the logged in user' do
77 user = @nutshell.get_user
78 end
79
80 it 'should get and edit a lead' do
81 lead_id = 1001
82 lead = @nutshell.get_lead(lead_id)
83 rev = lead['rev']
84 @nutshell.edit_lead(lead_id, rev, {:description => 'Testing edit.'})
85 end
86
87 it 'should return the sources' do
88 @nutshell.search_sources('Cold')
89 end
14e8d6f @mshafrir Update a lead's process step status
authored
90
91 it 'should update a process step' do
92 step = @nutshell.get_lead(1001)['processes'][0]['steps'][0]
fce25aa @mshafrir Fix update process step spec. Switch to Ruby 1.8.7 hash syntax.
authored
93 current_status = step['status'].to_i
94
95 if current_status < 2
96 @nutshell.edit_step(step['id'], step['rev'], {:status => 2})
97 else
98 lambda { @nutshell.edit_step(step['id'], step['rev'], {:status => 2}) }.should raise_error
99 end
14e8d6f @mshafrir Update a lead's process step status
authored
100 end
a449627 @mshafrir Initial commit.
authored
101 end
102 end
Something went wrong with that request. Please try again.