spec/unit/intercom/company_spec.rb in intercom-3.5.26 vs spec/unit/intercom/company_spec.rb in intercom-3.6.0

- old
+ new

@@ -1,36 +1,40 @@ -require 'spec_helper' +require "spec_helper" describe Intercom::Company do - let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') } + let (:client) { Intercom::Client.new(app_id: "app_id", api_key: "api_key") } - describe 'when no response raises error' do - it 'on find' do - client.expects(:get).with("/companies", {:company_id => '4'}).returns(nil) - proc {client.companies.find(:company_id => '4')}.must_raise Intercom::HttpError + describe "when no response raises error" do + it "on find" do + client.expects(:get).with("/companies", {:company_id => "4"}).returns(nil) + proc {client.companies.find(:company_id => "4")}.must_raise Intercom::HttpError end - it 'on find_all' do + it "on find_all" do client.expects(:get).with("/companies", {}).returns(nil) proc {client.companies.all.each {|company| }}.must_raise Intercom::HttpError end - it 'on load' do - client.expects(:get).with("/companies", {:company_id => '4'}).returns({'type' =>'user', 'id' =>'aaaaaaaaaaaaaaaaaaaaaaaa', 'company_id' => '4', 'name' => 'MyCo'}) - company = client.companies.find(:company_id => '4') - client.expects(:get).with('/companies/aaaaaaaaaaaaaaaaaaaaaaaa', {}).returns(nil) + it "on load" do + client.expects(:get).with("/companies", {:company_id => "4"}).returns({"type" =>"user", "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa", "company_id" => "4", "name" => "MyCo"}) + company = client.companies.find(:company_id => "4") + client.expects(:get).with("/companies/aaaaaaaaaaaaaaaaaaaaaaaa", {}).returns(nil) proc {client.companies.load(company)}.must_raise Intercom::HttpError end end - it 'gets users in a company' do + it "gets users in a company by intercom ID" do client.expects(:get).with("/companies/abc123/users", {}).returns(page_of_users(false)) - client.companies.users('abc123').each do |u| - end + client.companies.users_by_intercom_company_id("abc123").each { |u| } end - it 'finds a company' do + it "gets users in a company by external company ID" do + client.expects(:get).with("/companies", { company_id: "abc123", type: "user" }).returns(page_of_users(false)) + client.companies.users_by_company_id("abc123").each { |u| } + end + + it "finds a company" do client.expects(:get).with("/companies/531ee472cce572a6ec000006", {}).returns(test_company) - company = client.companies.find(id: '531ee472cce572a6ec000006') + company = client.companies.find(id: "531ee472cce572a6ec000006") company.name.must_equal("Blue Sun") end end