intercom 3.9.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +235 -222
- data/Rakefile +1 -1
- data/changes.txt +6 -0
- data/lib/intercom/api_operations/archive.rb +2 -1
- data/lib/intercom/api_operations/delete.rb +16 -0
- data/lib/intercom/api_operations/find.rb +5 -2
- data/lib/intercom/api_operations/find_all.rb +4 -3
- data/lib/intercom/api_operations/list.rb +4 -1
- data/lib/intercom/api_operations/load.rb +4 -2
- data/lib/intercom/api_operations/nested_resource.rb +70 -0
- data/lib/intercom/api_operations/save.rb +5 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +3 -2
- data/lib/intercom/base_collection_proxy.rb +72 -0
- data/lib/intercom/client.rb +20 -25
- data/lib/intercom/client_collection_proxy.rb +17 -39
- data/lib/intercom/company.rb +8 -0
- data/lib/intercom/contact.rb +21 -3
- data/lib/intercom/conversation.rb +4 -0
- data/lib/intercom/data_attribute.rb +7 -0
- data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
- data/lib/intercom/deprecated_resources.rb +13 -0
- data/lib/intercom/errors.rb +3 -0
- data/lib/intercom/extended_api_operations/segments.rb +3 -1
- data/lib/intercom/extended_api_operations/tags.rb +3 -1
- data/lib/intercom/lead.rb +21 -0
- data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
- data/lib/intercom/note.rb +4 -0
- data/lib/intercom/request.rb +37 -33
- data/lib/intercom/scroll_collection_proxy.rb +33 -38
- data/lib/intercom/search_collection_proxy.rb +30 -65
- data/lib/intercom/service/base_service.rb +7 -0
- data/lib/intercom/service/company.rb +0 -12
- data/lib/intercom/service/contact.rb +21 -10
- data/lib/intercom/service/conversation.rb +12 -3
- data/lib/intercom/service/data_attribute.rb +20 -0
- data/lib/intercom/service/lead.rb +41 -0
- data/lib/intercom/service/note.rb +4 -8
- data/lib/intercom/service/subscription.rb +2 -2
- data/lib/intercom/service/tag.rb +9 -9
- data/lib/intercom/service/visitor.rb +17 -8
- data/lib/intercom/tag.rb +4 -0
- data/lib/intercom/traits/api_resource.rb +28 -17
- data/lib/intercom/user.rb +12 -3
- data/lib/intercom/utils.rb +13 -2
- data/lib/intercom/version.rb +1 -1
- data/lib/intercom/visitor.rb +0 -2
- data/lib/intercom.rb +27 -22
- data/spec/spec_helper.rb +738 -513
- data/spec/unit/intercom/admin_spec.rb +2 -2
- data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
- data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
- data/spec/unit/intercom/client_spec.rb +28 -25
- data/spec/unit/intercom/company_spec.rb +13 -15
- data/spec/unit/intercom/contact_spec.rb +289 -33
- data/spec/unit/intercom/conversation_spec.rb +29 -7
- data/spec/unit/intercom/count_spec.rb +4 -4
- data/spec/unit/intercom/data_attribute_spec.rb +40 -0
- data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
- data/spec/unit/intercom/event_spec.rb +9 -11
- data/spec/unit/intercom/job_spec.rb +24 -24
- data/spec/unit/intercom/lead_spec.rb +57 -0
- data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
- data/spec/unit/intercom/message_spec.rb +1 -1
- data/spec/unit/intercom/note_spec.rb +4 -10
- data/spec/unit/intercom/request_spec.rb +1 -1
- data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
- data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
- data/spec/unit/intercom/segment_spec.rb +2 -2
- data/spec/unit/intercom/subscription_spec.rb +5 -6
- data/spec/unit/intercom/tag_spec.rb +22 -14
- data/spec/unit/intercom/team_spec.rb +2 -2
- data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
- data/spec/unit/intercom/user_spec.rb +224 -226
- data/spec/unit/intercom/visitor_spec.rb +49 -0
- data/spec/unit/intercom_spec.rb +5 -3
- metadata +22 -7
- data/lib/intercom/customer.rb +0 -10
- data/lib/intercom/service/customer.rb +0 -14
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Intercom::Lead' do
|
6
|
+
let (:client) { Intercom::Client.new(token: 'token') }
|
7
|
+
|
8
|
+
it 'should be listable' do
|
9
|
+
proxy = client.deprecated__leads.all
|
10
|
+
_(proxy.resource_name).must_equal 'contacts'
|
11
|
+
_(proxy.resource_class).must_equal Intercom::Lead
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not throw ArgumentErrors when there are no parameters' do
|
15
|
+
client.expects(:post)
|
16
|
+
client.deprecated__leads.create
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can update a lead with an id' do
|
20
|
+
lead = Intercom::Lead.new(id: 'de45ae78gae1289cb')
|
21
|
+
client.expects(:put).with('/contacts/de45ae78gae1289cb', 'custom_attributes' => {})
|
22
|
+
client.deprecated__leads.save(lead)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'converting' do
|
26
|
+
let(:lead) { Intercom::Lead.from_api(user_id: 'contact_id') }
|
27
|
+
let(:user) { Intercom::User.from_api(id: 'user_id') }
|
28
|
+
|
29
|
+
it do
|
30
|
+
client.expects(:post).with(
|
31
|
+
'/contacts/convert',
|
32
|
+
contact: { user_id: lead.user_id },
|
33
|
+
user: { 'id' => user.id }
|
34
|
+
).returns(test_user)
|
35
|
+
|
36
|
+
client.deprecated__leads.convert(lead, user)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns a DeprecatedLeadsCollectionProxy for all without making any requests' do
|
41
|
+
client.expects(:execute_request).never
|
42
|
+
all = client.deprecated__leads.all
|
43
|
+
_(all).must_be_instance_of(Intercom::DeprecatedLeadsCollectionProxy)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'deletes a lead' do
|
47
|
+
lead = Intercom::Lead.new('id' => '1')
|
48
|
+
client.expects(:delete).with('/contacts/1', {}).returns(lead)
|
49
|
+
client.deprecated__leads.delete(lead)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sends a request for a hard deletion' do
|
53
|
+
lead = Intercom::Lead.new('id' => '1')
|
54
|
+
client.expects(:post).with('/user_delete_requests', intercom_user_id: '1').returns(id: lead.id)
|
55
|
+
client.deprecated__leads.request_hard_delete(lead)
|
56
|
+
end
|
57
|
+
end
|
@@ -1,29 +1,31 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Intercom::Lib::FlatStore do
|
4
|
-
it
|
5
|
-
data = Intercom::Lib::FlatStore.new
|
6
|
-
proc { data[
|
7
|
-
proc { data[
|
8
|
-
proc { Intercom::Lib::FlatStore.new(
|
6
|
+
it 'raises if you try to set or merge in nested hash structures' do
|
7
|
+
data = Intercom::Lib::FlatStore.new
|
8
|
+
_(proc { data['thing'] = [1] }).must_raise ArgumentError
|
9
|
+
_(proc { data['thing'] = { 1 => 2 } }).must_raise ArgumentError
|
10
|
+
_(proc { Intercom::Lib::FlatStore.new(1 => { 2 => 3 }) }).must_raise ArgumentError
|
9
11
|
end
|
10
12
|
|
11
|
-
it
|
12
|
-
data =Intercom::Lib::FlatStore.new
|
13
|
-
proc { data[1] =
|
13
|
+
it 'raises if you try to use a non string key' do
|
14
|
+
data = Intercom::Lib::FlatStore.new
|
15
|
+
_(proc { data[1] = 'something' }).must_raise ArgumentError
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
data = Intercom::Lib::FlatStore.new
|
18
|
-
data[
|
18
|
+
it 'sets and merges valid entries' do
|
19
|
+
data = Intercom::Lib::FlatStore.new
|
20
|
+
data['a'] = 1
|
19
21
|
data[:b] = 2
|
20
|
-
data[:a].must_equal 1
|
21
|
-
data[
|
22
|
-
data[:b].must_equal 2
|
23
|
-
data = Intercom::Lib::FlatStore.new(
|
24
|
-
data[
|
25
|
-
data[:a].must_equal 1
|
26
|
-
data[
|
27
|
-
data[:b].must_equal 2
|
22
|
+
_(data[:a]).must_equal 1
|
23
|
+
_(data['b']).must_equal 2
|
24
|
+
_(data[:b]).must_equal 2
|
25
|
+
data = Intercom::Lib::FlatStore.new('a' => 1, :b => 2)
|
26
|
+
_(data['a']).must_equal 1
|
27
|
+
_(data[:a]).must_equal 1
|
28
|
+
_(data['b']).must_equal 2
|
29
|
+
_(data[:b]).must_equal 2
|
28
30
|
end
|
29
31
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "Intercom::Message" do
|
4
4
|
|
5
5
|
let (:user) {Intercom::User.new("email" => "jim@example.com", :user_id => "12345", :created_at => Time.now, :name => "Jim Bob")}
|
6
|
-
let
|
6
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
7
7
|
|
8
8
|
it 'creates an user message with symbol keys' do
|
9
9
|
client.expects(:post).with('/messages', {'from' => { :type => 'user', :email => 'jim@example.com'}, 'body' => 'halp'}).returns(:status => 200)
|
@@ -1,13 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "notes" do
|
4
|
-
let
|
5
|
-
|
6
|
-
it "creates a note" do
|
7
|
-
client.expects(:post).with("/notes", {"body" => "Note to leave on user"}).returns({"body" => "<p>Note to leave on user</p>", "created_at" => 1234567890})
|
8
|
-
note = client.notes.create("body" => "Note to leave on user")
|
9
|
-
note.body.must_equal "<p>Note to leave on user</p>"
|
10
|
-
end
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
11
5
|
|
12
6
|
it 'gets a note' do
|
13
7
|
client.expects(:get).with("/notes/123", {}).returns({"id" => "123", "body" => "<p>Note to leave on user</p>", "created_at" => 1234567890})
|
@@ -18,9 +12,9 @@ describe "notes" do
|
|
18
12
|
params = {"body" => "Note body", "email" => "me@example.com", :user_id => "abc123"}
|
19
13
|
note = Intercom::Note.new(params)
|
20
14
|
|
21
|
-
note.to_hash.keys.sort.must_equal params.keys.map(&:to_s).sort
|
22
|
-
params.keys.each do |
|
23
|
-
note.send(key).must_equal params[key]
|
15
|
+
_(note.to_hash.keys.sort).must_equal params.keys.map(&:to_s).sort
|
16
|
+
params.keys.each do |key|
|
17
|
+
_(note.send(key)).must_equal params[key]
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
@@ -9,7 +9,7 @@ describe 'Intercom::Request', '#execute' do
|
|
9
9
|
let(:default_body) { { data: "test" }.to_json }
|
10
10
|
|
11
11
|
def execute!
|
12
|
-
req.execute(uri,
|
12
|
+
req.execute(uri, token: 'test-token')
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should call sleep for rate limit error three times and raise a rate limit error otherwise' do
|
@@ -1,56 +1,57 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Intercom::ScrollCollectionProxy do
|
4
|
-
let
|
6
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
7
|
|
6
|
-
it
|
7
|
-
client.expects(:get).with(
|
8
|
-
|
9
|
-
client.
|
10
|
-
|
8
|
+
it 'stops iterating if no companies returned' do
|
9
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(false))
|
10
|
+
names = []
|
11
|
+
client.companies.scroll.each { |company| names << company.name }
|
12
|
+
_(names).must_equal %w[]
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
14
|
-
client.expects(:get).with(
|
15
|
-
client.expects(:get).with('/
|
16
|
-
|
17
|
-
client.
|
15
|
+
it 'keeps iterating if companies returned' do
|
16
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
|
17
|
+
client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(false))
|
18
|
+
names = []
|
19
|
+
client.companies.scroll.each { |company| names << company.name }
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
21
|
-
client.expects(:get).with(
|
22
|
-
client.
|
22
|
+
it 'supports indexed array access' do
|
23
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
|
24
|
+
_(client.companies.scroll[0].name).must_equal 'company1'
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
26
|
-
client.expects(:get).with(
|
27
|
-
client.expects(:get).with('/
|
28
|
-
|
29
|
-
|
27
|
+
it 'supports map' do
|
28
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
|
29
|
+
client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(false))
|
30
|
+
names = client.companies.scroll.map(&:name)
|
31
|
+
_(names).must_equal %w[company1 company2 company3]
|
30
32
|
end
|
31
33
|
|
32
|
-
it
|
33
|
-
client.expects(:get).with(
|
34
|
-
scroll = client.
|
35
|
-
|
36
|
-
scroll.records.each {|usr|
|
37
|
-
|
34
|
+
it 'returns one page scroll' do
|
35
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
|
36
|
+
scroll = client.companies.scroll.next
|
37
|
+
names = []
|
38
|
+
scroll.records.each { |usr| names << usr.name }
|
39
|
+
_(names).must_equal %w[company1 company2 company3]
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
41
|
-
client.expects(:get).with(
|
42
|
-
client.expects(:get).with('/
|
43
|
-
scroll = client.
|
44
|
-
scroll = client.
|
45
|
-
|
46
|
-
scroll.records.each {|usr| puts usr.email}
|
42
|
+
it 'keeps iterating if called with scroll_param' do
|
43
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
|
44
|
+
client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(true))
|
45
|
+
scroll = client.companies.scroll.next
|
46
|
+
scroll = client.companies.scroll.next('da6bbbac-25f6-4f07-866b-b911082d7')
|
47
|
+
scroll.records.each(&:name)
|
47
48
|
end
|
48
49
|
|
49
|
-
it
|
50
|
-
client.expects(:get).with(
|
51
|
-
scroll = client.
|
52
|
-
|
53
|
-
scroll.records.each {|usr|
|
54
|
-
|
50
|
+
it 'works with an empty list' do
|
51
|
+
client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(false))
|
52
|
+
scroll = client.companies.scroll.next
|
53
|
+
names = []
|
54
|
+
scroll.records.each { |usr| names << usr.name }
|
55
|
+
_(names).must_equal %w[]
|
55
56
|
end
|
56
57
|
end
|
@@ -1,56 +1,60 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Intercom::SearchCollectionProxy do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
|
-
it "
|
7
|
-
client.expects(:post).with("/
|
8
|
-
client.
|
6
|
+
it "sends query to the contact search endpoint" do
|
7
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
|
8
|
+
client.contacts.search(query: {}).first
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
12
|
-
client.expects(:post).with("/
|
13
|
-
client.
|
11
|
+
it "sends query to the conversation search endpoint" do
|
12
|
+
client.expects(:post).with("/conversations/search", { query: {} }).returns(test_conversation_list)
|
13
|
+
client.conversations.search(query: {}).first
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
client.expects(:post).with("/
|
18
|
-
client.
|
16
|
+
it "sends query to the contact search endpoint with sort_field" do
|
17
|
+
client.expects(:post).with("/contacts/search", { query: {}, sort: { field: "name" } }).returns(page_of_contacts(false))
|
18
|
+
client.contacts.search(query: {}, sort_field: "name").first
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
client.expects(:post).with("/
|
23
|
-
client.
|
21
|
+
it "sends query to the contact search endpoint with sort_field and sort_order" do
|
22
|
+
client.expects(:post).with("/contacts/search", { query: {}, sort: { field: "name", order: "ascending" } }).returns(page_of_contacts(false))
|
23
|
+
client.contacts.search(query: {}, sort_field: "name", sort_order: "ascending").first
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
27
|
-
client.expects(:post).with("/
|
28
|
-
client.
|
26
|
+
it "sends query to the contact search endpoint with per_page" do
|
27
|
+
client.expects(:post).with("/contacts/search", { query: {}, pagination: { per_page: 10 }}).returns(page_of_contacts(false))
|
28
|
+
client.contacts.search(query: {}, per_page: 10).first
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sends query to the contact search endpoint with starting_after" do
|
32
|
+
client.expects(:post).with("/contacts/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_contacts(false))
|
33
|
+
client.contacts.search(query: {}, starting_after: "EnCrYpTeDsTrInG").first
|
29
34
|
end
|
30
35
|
|
31
36
|
it "stops iterating if no starting_after value" do
|
32
|
-
client.expects(:post).with("/
|
37
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
|
33
38
|
emails = []
|
34
|
-
client.
|
35
|
-
emails.must_equal %
|
39
|
+
client.contacts.search(query: {}).each { |contact| emails << contact.email }
|
40
|
+
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
|
36
41
|
end
|
37
42
|
|
38
43
|
it "keeps iterating if starting_after value" do
|
39
|
-
client.expects(:post).with("/
|
40
|
-
client.expects(:post).with("/
|
44
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(true))
|
45
|
+
client.expects(:post).with("/contacts/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_contacts(false))
|
41
46
|
emails = []
|
42
|
-
client.
|
47
|
+
client.contacts.search(query: {}).each { |contact| emails << contact.email }
|
43
48
|
end
|
44
49
|
|
45
50
|
it "supports indexed array access" do
|
46
|
-
client.expects(:post).with("/
|
47
|
-
client.
|
51
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
|
52
|
+
_(client.contacts.search(query: {})[0].email).must_equal 'test1@example.com'
|
48
53
|
end
|
49
54
|
|
50
55
|
it "supports map" do
|
51
|
-
client.expects(:post).with("/
|
52
|
-
emails = client.
|
53
|
-
emails.must_equal %
|
56
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
|
57
|
+
emails = client.contacts.search(query: {}).map { |contact| contact.email }
|
58
|
+
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
|
54
59
|
end
|
55
|
-
|
56
60
|
end
|
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Intercom::Segment" do
|
4
4
|
|
5
|
-
let
|
5
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
6
6
|
|
7
7
|
it 'lists segments' do
|
8
8
|
client.expects(:get).with('/segments', {}).returns(segment_list)
|
9
9
|
segments = client.segments.all.to_a
|
10
|
-
segments[0].name.must_equal('Active')
|
10
|
+
_(segments[0].name).must_equal('Active')
|
11
11
|
end
|
12
12
|
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Intercom::Subscription" do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
6
|
it "gets a subscription" do
|
7
7
|
client.expects(:get).with("/subscriptions/nsub_123456789", {}).returns(test_subscription)
|
8
8
|
subscription = client.subscriptions.find(:id => "nsub_123456789")
|
9
|
-
subscription.request.topics[0].must_equal "user.created"
|
10
|
-
subscription.request.topics[1].must_equal "conversation.user.replied"
|
9
|
+
_(subscription.request.topics[0]).must_equal "user.created"
|
10
|
+
_(subscription.request.topics[1]).must_equal "conversation.user.replied"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "creates a subscription" do
|
14
14
|
client.expects(:post).with("/subscriptions", {'url' => "http://example.com", 'topics' => ["user.created"]}).returns(test_subscription)
|
15
15
|
subscription = client.subscriptions.create(:url => "http://example.com", :topics => ["user.created"])
|
16
|
-
subscription.request.topics[0].must_equal "user.created"
|
17
|
-
subscription.request.url.must_equal "http://example.com"
|
16
|
+
_(subscription.request.topics[0]).must_equal "user.created"
|
17
|
+
_(subscription.request.url).must_equal "http://example.com"
|
18
18
|
end
|
19
|
-
|
20
19
|
end
|
@@ -1,23 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
let
|
5
|
+
describe 'Intercom::Tag' do
|
6
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
7
|
+
|
8
|
+
it 'creates a tag' do
|
9
|
+
client.expects(:post).with('/tags', 'name' => 'Test Tag').returns(test_tag)
|
10
|
+
tag = client.tags.create(name: 'Test Tag')
|
11
|
+
_(tag.name).must_equal 'Test Tag'
|
12
|
+
end
|
5
13
|
|
6
|
-
it
|
7
|
-
client.expects(:
|
8
|
-
tag = client.tags.
|
9
|
-
tag.name.must_equal
|
14
|
+
it 'finds a tag by id' do
|
15
|
+
client.expects(:get).with('/tags/4f73428b5e4dfc000b000112', {}).returns(test_tag)
|
16
|
+
tag = client.tags.find(id: '4f73428b5e4dfc000b000112')
|
17
|
+
_(tag.name).must_equal 'Test Tag'
|
10
18
|
end
|
11
19
|
|
12
|
-
it
|
13
|
-
client.expects(:post).with(
|
14
|
-
tag = client.tags.tag(:
|
15
|
-
tag.name.must_equal
|
16
|
-
tag.
|
20
|
+
it 'tags companies' do
|
21
|
+
client.expects(:post).with('/tags', 'name' => 'Test Tag', 'companies' => [{ company_id: 'abc123' }, { company_id: 'def456' }], 'tag_or_untag' => 'tag').returns(test_tag)
|
22
|
+
tag = client.tags.tag(name: 'Test Tag', companies: [{ company_id: 'abc123' }, { company_id: 'def456' }])
|
23
|
+
_(tag.name).must_equal 'Test Tag'
|
24
|
+
_(tag.tagged_company_count).must_equal 2
|
17
25
|
end
|
18
26
|
|
19
|
-
it 'untags
|
20
|
-
client.expects(:post).with(
|
21
|
-
client.tags.untag(:
|
27
|
+
it 'untags companies' do
|
28
|
+
client.expects(:post).with('/tags', 'name' => 'Test Tag', 'companies' => [{ company_id: 'abc123', untag: true }, { company_id: 'def456', untag: true }], 'tag_or_untag' => 'untag').returns(test_tag)
|
29
|
+
client.tags.untag(name: 'Test Tag', companies: [{ company_id: 'abc123' }, { company_id: 'def456' }])
|
22
30
|
end
|
23
31
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Intercom::Team" do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
6
|
it "returns a CollectionProxy for all without making any requests" do
|
7
7
|
client.expects(:execute_request).never
|
8
8
|
all = client.teams.all
|
9
|
-
all.must_be_instance_of(Intercom::ClientCollectionProxy)
|
9
|
+
_(all).must_be_instance_of(Intercom::ClientCollectionProxy)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'gets an team list' do
|
@@ -1,98 +1,100 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Intercom::Traits::ApiResource do
|
4
6
|
let(:object_json) do
|
5
|
-
{
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
{ 'type' => 'company',
|
8
|
+
'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
|
9
|
+
'app_id' => 'some-app-id',
|
10
|
+
'name' => 'SuperSuite',
|
11
|
+
'plan_id' => 1,
|
12
|
+
'remote_company_id' => '8',
|
13
|
+
'remote_created_at' => 103_201,
|
14
|
+
'created_at' => 1_374_056_196,
|
15
|
+
'user_count' => 1,
|
16
|
+
'custom_attributes' => {},
|
17
|
+
'metadata' => {
|
18
|
+
'type' => 'user',
|
19
|
+
'color' => 'cyan'
|
20
|
+
} }
|
19
21
|
end
|
20
22
|
|
21
23
|
let(:object_hash) do
|
22
24
|
{
|
23
|
-
type:
|
24
|
-
id:
|
25
|
-
app_id:
|
26
|
-
name:
|
25
|
+
type: 'company',
|
26
|
+
id: 'aaaaaaaaaaaaaaaaaaaaaaaa',
|
27
|
+
app_id: 'some-app-id',
|
28
|
+
name: 'SuperSuite',
|
27
29
|
plan_id: 1,
|
28
|
-
remote_company_id:
|
29
|
-
remote_created_at:
|
30
|
-
created_at:
|
30
|
+
remote_company_id: '8',
|
31
|
+
remote_created_at: 103_201,
|
32
|
+
created_at: 1_374_056_196,
|
31
33
|
user_count: 1,
|
32
|
-
custom_attributes: { type:
|
34
|
+
custom_attributes: { type: 'ping' },
|
33
35
|
metadata: {
|
34
|
-
type:
|
35
|
-
color:
|
36
|
+
type: 'user',
|
37
|
+
color: 'cyan'
|
36
38
|
}
|
37
39
|
}
|
38
40
|
end
|
39
41
|
|
40
|
-
let(:api_resource) { DummyClass.new.extend(Intercom::Traits::ApiResource)}
|
42
|
+
let(:api_resource) { DummyClass.new.extend(Intercom::Traits::ApiResource) }
|
41
43
|
|
42
44
|
before(:each) { api_resource.from_response(object_json) }
|
43
45
|
|
44
|
-
it
|
45
|
-
assert_equal Time.at(
|
46
|
+
it 'coerces time on parsing json' do
|
47
|
+
assert_equal Time.at(1_374_056_196), api_resource.created_at
|
46
48
|
end
|
47
49
|
|
48
|
-
it
|
49
|
-
assert_equal Time.at(
|
50
|
+
it 'exposes string' do
|
51
|
+
assert_equal Time.at(1_374_056_196), api_resource.created_at
|
50
52
|
end
|
51
53
|
|
52
54
|
it "treats 'metadata' as a plain hash, not a typed object" do
|
53
55
|
assert_equal Hash, api_resource.metadata.class
|
54
56
|
end
|
55
57
|
|
56
|
-
it
|
57
|
-
api_resource.wont_respond_to :spiders
|
58
|
+
it 'dynamically defines accessors when a non-existent property is called that looks like a setter' do
|
59
|
+
_(api_resource).wont_respond_to :spiders
|
58
60
|
api_resource.spiders = 4
|
59
|
-
api_resource.must_respond_to :spiders
|
61
|
+
_(api_resource).must_respond_to :spiders
|
60
62
|
end
|
61
63
|
|
62
|
-
it
|
64
|
+
it 'calls dynamically defined getter when asked' do
|
63
65
|
api_resource.foo = 4
|
64
66
|
assert_equal 4, api_resource.foo
|
65
67
|
end
|
66
68
|
|
67
|
-
it
|
68
|
-
api_resource.foo_at =
|
69
|
-
assert_equal
|
69
|
+
it 'accepts unix timestamps into dynamically defined date setters' do
|
70
|
+
api_resource.foo_at = 1_401_200_468
|
71
|
+
assert_equal 1_401_200_468, api_resource.instance_variable_get(:@foo_at)
|
70
72
|
end
|
71
73
|
|
72
|
-
it
|
73
|
-
api_resource.foo_at =
|
74
|
-
assert_equal Time.at(
|
74
|
+
it 'exposes dates correctly for dynamically defined getters' do
|
75
|
+
api_resource.foo_at = 1_401_200_468
|
76
|
+
assert_equal Time.at(1_401_200_468), api_resource.foo_at
|
75
77
|
end
|
76
78
|
|
77
|
-
it
|
79
|
+
it 'throws regular method missing error when non-existent getter is called that is backed by an instance variable' do
|
78
80
|
api_resource.instance_variable_set(:@bar, 'you cant see me')
|
79
|
-
proc { api_resource.bar }.must_raise NoMethodError
|
81
|
+
_(proc { api_resource.bar }).must_raise NoMethodError
|
80
82
|
end
|
81
83
|
|
82
|
-
it
|
83
|
-
proc { api_resource.flubber }.must_raise Intercom::AttributeNotSetError
|
84
|
+
it 'throws attribute not set error when non-existent getter is called that is not backed by an instance variable' do
|
85
|
+
_(proc { api_resource.flubber }).must_raise Intercom::AttributeNotSetError
|
84
86
|
end
|
85
87
|
|
86
|
-
it
|
87
|
-
proc { api_resource.flubber! }.must_raise NoMethodError
|
88
|
-
proc { api_resource.flubber? }.must_raise NoMethodError
|
88
|
+
it 'throws regular method missing error when non-existent method is called that cannot be an accessor' do
|
89
|
+
_(proc { api_resource.flubber! }).must_raise NoMethodError
|
90
|
+
_(proc { api_resource.flubber? }).must_raise NoMethodError
|
89
91
|
end
|
90
92
|
|
91
|
-
it
|
92
|
-
proc { api_resource.send(:flubber=, 'a', 'b') }.must_raise NoMethodError
|
93
|
+
it 'throws regular method missing error when non-existent setter is called with multiple arguments' do
|
94
|
+
_(proc { api_resource.send(:flubber=, 'a', 'b') }).must_raise NoMethodError
|
93
95
|
end
|
94
96
|
|
95
|
-
it
|
97
|
+
it 'an initialized ApiResource is equal to one generated from a response' do
|
96
98
|
class ConcreteApiResource; include Intercom::Traits::ApiResource; end
|
97
99
|
initialized_api_resource = ConcreteApiResource.new(object_json)
|
98
100
|
except(object_json, 'type').keys.each do |attribute|
|
@@ -100,7 +102,7 @@ describe Intercom::Traits::ApiResource do
|
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
103
|
-
it
|
105
|
+
it 'initialized ApiResource using hash is equal to one generated from response' do
|
104
106
|
class ConcreteApiResource; include Intercom::Traits::ApiResource; end
|
105
107
|
|
106
108
|
api_resource.from_hash(object_hash)
|