|
1 | | -require 'spec_helper' |
| 1 | +require "spec_helper" |
2 | 2 |
|
3 | 3 | describe Intercom::Company do |
4 | | - let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') } |
| 4 | + let (:client) { Intercom::Client.new(app_id: "app_id", api_key: "api_key") } |
5 | 5 |
|
6 | | - describe 'when no response raises error' do |
7 | | - it 'on find' do |
8 | | - client.expects(:get).with("/companies", {:company_id => '4'}).returns(nil) |
9 | | - proc {client.companies.find(:company_id => '4')}.must_raise Intercom::HttpError |
| 6 | + describe "when no response raises error" do |
| 7 | + it "on find" do |
| 8 | + client.expects(:get).with("/companies", {:company_id => "4"}).returns(nil) |
| 9 | + proc {client.companies.find(:company_id => "4")}.must_raise Intercom::HttpError |
10 | 10 | end |
11 | 11 |
|
12 | | - it 'on find_all' do |
| 12 | + it "on find_all" do |
13 | 13 | client.expects(:get).with("/companies", {}).returns(nil) |
14 | 14 | proc {client.companies.all.each {|company| }}.must_raise Intercom::HttpError |
15 | 15 | end |
16 | 16 |
|
17 | | - it 'on load' do |
18 | | - client.expects(:get).with("/companies", {:company_id => '4'}).returns({'type' =>'user', 'id' =>'aaaaaaaaaaaaaaaaaaaaaaaa', 'company_id' => '4', 'name' => 'MyCo'}) |
19 | | - company = client.companies.find(:company_id => '4') |
20 | | - client.expects(:get).with('/companies/aaaaaaaaaaaaaaaaaaaaaaaa', {}).returns(nil) |
| 17 | + it "on load" do |
| 18 | + client.expects(:get).with("/companies", {:company_id => "4"}).returns({"type" =>"user", "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa", "company_id" => "4", "name" => "MyCo"}) |
| 19 | + company = client.companies.find(:company_id => "4") |
| 20 | + client.expects(:get).with("/companies/aaaaaaaaaaaaaaaaaaaaaaaa", {}).returns(nil) |
21 | 21 | proc {client.companies.load(company)}.must_raise Intercom::HttpError |
22 | 22 | end |
23 | 23 | end |
24 | 24 |
|
25 | | - it 'gets users in a company' do |
| 25 | + it "gets users in a company by intercom ID" do |
26 | 26 | client.expects(:get).with("/companies/abc123/users", {}).returns(page_of_users(false)) |
27 | | - client.companies.users('abc123').each do |u| |
28 | | - end |
| 27 | + client.companies.users_by_intercom_company_id("abc123").each { |u| } |
| 28 | + end |
| 29 | + |
| 30 | + it "gets users in a company by external company ID" do |
| 31 | + client.expects(:get).with("/companies", { company_id: "abc123", type: "user" }).returns(page_of_users(false)) |
| 32 | + client.companies.users_by_company_id("abc123").each { |u| } |
29 | 33 | end |
30 | 34 |
|
31 | | - it 'finds a company' do |
| 35 | + it "finds a company" do |
32 | 36 | client.expects(:get).with("/companies/531ee472cce572a6ec000006", {}).returns(test_company) |
33 | | - company = client.companies.find(id: '531ee472cce572a6ec000006') |
| 37 | + company = client.companies.find(id: "531ee472cce572a6ec000006") |
34 | 38 | company.name.must_equal("Blue Sun") |
35 | 39 | end |
36 | 40 | end |
0 commit comments