Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1d64522ddc
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 102 lines (83 sloc) 3.284 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
require 'spec_helper'

describe NutshellCrm::Client do
  before :all do
    @api_username = ENV['NUTSHELL_USERNAME']
    @api_key = ENV['NUTSHELL_APIKEY']
    @nutshell = NutshellCrm::Client.new @api_username, @api_key
    @categories = ['Contacts', 'Accounts', 'Leads']
  end

  context 'client authentication errors' do
    it 'should set up a new client instance with an invalid username and raise an error' do
      lambda { NutshellCrm::Client.new('invalid@example.com', 'APIKEY123456') }.should raise_error
    end

    it 'should set up a new client instance with a valid username but invalid API key and raise an error' do
      nutshell = NutshellCrm::Client.new(@api_username, 'APIKEY123456')
      lambda { nutshell.find_leads({:status => 0}) }.should raise_error
    end
  end

  subject { @nutshell }

  context 'after a new Nutshell client has been instantiated' do
    it 'should get a valid API service url that starts with https://' do
      @nutshell.api_url.should match 'https://'
    end

    it 'should consider global stub_response property settings' do
      @nutshell.stub_responses = false
      @nutshell.find_leads({:status => 0}).first['stub'].should_not be true
      @nutshell.stub_responses = true
      @nutshell.find_leads({:status => 0}).first['stub'].should be true
      @nutshell.stub_responses = nil
    end

    it 'should find open leads' do
      @nutshell.find_leads({:status => 0}).should_not be_empty
    end

    it 'should describe custom fields' do
      custom_fields = @nutshell.describe_custom_fields
      (custom_fields.all? {|k,v| @categories.include? k}).should be_true
    end

    it 'should find tags' do
      tags = @nutshell.find_tags
      (tags.all? {|k,v| @categories.include? k}).should be_true
    end

    it 'should get update times for each provisioning bin' do
      @nutshell.get_update_times.should_not be_empty
    end

    it 'should return universal search results' do
      @nutshell.search_universal('A').should_not be_empty
    end

    it 'should create a new tag and find it' do
      lambda {
        @nutshell.new_tag({:name => 'FOO2', :entityType => 'Leads'})
        @nutshell.new_tag({:name => 'FOO2', :entityType => 'Leads'})
      }.should raise_error
    end

    it 'should return product info' do
      product = @nutshell.get_product(1)
      product.should_not be_empty
    end

    it 'should return mobile settings' do
      mobile_settings = @nutshell.get_mobile_settings
      mobile_settings.should_not be_empty
    end

    it 'should return the logged in user' do
      user = @nutshell.get_user
    end

    it 'should get and edit a lead' do
      lead_id = 1001
      lead = @nutshell.get_lead(lead_id)
      rev = lead['rev']
      @nutshell.edit_lead(lead_id, rev, {:description => 'Testing edit.'})
    end

    it 'should return the sources' do
      @nutshell.search_sources('Cold')
    end

    it 'should update a process step' do
      step = @nutshell.get_lead(1001)['processes'][0]['steps'][0]
      current_status = step['status'].to_i

      if current_status < 2
        @nutshell.edit_step(step['id'], step['rev'], {:status => 2})
      else
        lambda { @nutshell.edit_step(step['id'], step['rev'], {:status => 2}) }.should raise_error
      end
    end
  end
end
Something went wrong with that request. Please try again.