intercom 3.5.10 → 4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
- data/Gemfile +1 -4
- data/README.md +418 -216
- data/RELEASING.md +9 -0
- data/Rakefile +1 -1
- data/changes.txt +141 -0
- data/intercom.gemspec +1 -2
- data/lib/intercom.rb +34 -19
- data/lib/intercom/api_operations/archive.rb +16 -0
- data/lib/intercom/api_operations/delete.rb +4 -1
- 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/request_hard_delete.rb +12 -0
- data/lib/intercom/api_operations/save.rb +6 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +18 -0
- data/lib/intercom/article.rb +7 -0
- data/lib/intercom/base_collection_proxy.rb +72 -0
- data/lib/intercom/client.rb +66 -18
- data/lib/intercom/client_collection_proxy.rb +17 -39
- data/lib/intercom/collection.rb +7 -0
- data/lib/intercom/company.rb +8 -0
- data/lib/intercom/contact.rb +22 -3
- data/lib/intercom/conversation.rb +5 -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 +44 -4
- 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 +162 -95
- data/lib/intercom/scroll_collection_proxy.rb +38 -42
- data/lib/intercom/search_collection_proxy.rb +47 -0
- data/lib/intercom/section.rb +23 -0
- data/lib/intercom/segment.rb +4 -0
- data/lib/intercom/service/article.rb +20 -0
- data/lib/intercom/service/base_service.rb +13 -0
- data/lib/intercom/service/collection.rb +24 -0
- data/lib/intercom/service/company.rb +4 -2
- data/lib/intercom/service/contact.rb +29 -6
- data/lib/intercom/service/conversation.rb +23 -2
- data/lib/intercom/service/data_attribute.rb +20 -0
- data/lib/intercom/service/event.rb +12 -0
- data/lib/intercom/service/lead.rb +41 -0
- data/lib/intercom/service/note.rb +4 -8
- data/lib/intercom/service/section.rb +7 -0
- data/lib/intercom/service/tag.rb +8 -8
- data/lib/intercom/service/team.rb +17 -0
- data/lib/intercom/service/user.rb +4 -2
- data/lib/intercom/service/visitor.rb +15 -6
- data/lib/intercom/tag.rb +4 -0
- data/lib/intercom/team.rb +7 -0
- data/lib/intercom/traits/api_resource.rb +48 -27
- data/lib/intercom/traits/dirty_tracking.rb +8 -1
- 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/spec/spec_helper.rb +881 -436
- data/spec/unit/intercom/admin_spec.rb +2 -2
- data/spec/unit/intercom/article_spec.rb +40 -0
- 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 +76 -9
- data/spec/unit/intercom/collection_spec.rb +32 -0
- data/spec/unit/intercom/company_spec.rb +29 -21
- data/spec/unit/intercom/contact_spec.rb +365 -29
- data/spec/unit/intercom/conversation_spec.rb +70 -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 +25 -8
- 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 +150 -9
- data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
- data/spec/unit/intercom/search_collection_proxy_spec.rb +60 -0
- data/spec/unit/intercom/section_spec.rb +32 -0
- 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 +21 -0
- data/spec/unit/intercom/traits/api_resource_spec.rb +129 -47
- data/spec/unit/intercom/user_spec.rb +227 -217
- data/spec/unit/intercom/visitor_spec.rb +49 -0
- data/spec/unit/intercom_spec.rb +5 -3
- metadata +63 -26
- data/.travis.yml +0 -6
- data/lib/intercom/extended_api_operations/users.rb +0 -16
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,13 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Intercom::Conversation" do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
6
|
it "gets a conversation" do
|
7
7
|
client.expects(:get).with("/conversations/147", {}).returns(test_conversation)
|
8
8
|
client.conversations.find(:id => "147")
|
9
9
|
end
|
10
10
|
|
11
|
+
it "gets all conversations" do
|
12
|
+
client.expects(:get).with("/conversations", {}).returns(test_conversation_list)
|
13
|
+
client.conversations.all.each { |c| }
|
14
|
+
end
|
15
|
+
|
11
16
|
it 'marks a conversation as read' do
|
12
17
|
client.expects(:put).with('/conversations/147', { read: true })
|
13
18
|
client.conversations.mark_read('147')
|
@@ -23,6 +28,11 @@ describe "Intercom::Conversation" do
|
|
23
28
|
client.conversations.reply(id: '147', type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', attachment_urls: ["http://www.example.com/attachment.jpg"])
|
24
29
|
end
|
25
30
|
|
31
|
+
it 'sends a reply to a users last conversation from an admin' do
|
32
|
+
client.expects(:post).with('/conversations/last/reply', { type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123' }).returns(test_conversation)
|
33
|
+
client.conversations.reply_to_last(type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123')
|
34
|
+
end
|
35
|
+
|
26
36
|
it 'opens a conversation' do
|
27
37
|
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'open', conversation_id: '147', admin_id: '123'}).returns(test_conversation)
|
28
38
|
client.conversations.open(id: '147', admin_id: '123')
|
@@ -38,11 +48,64 @@ describe "Intercom::Conversation" do
|
|
38
48
|
client.conversations.assign(id: '147', admin_id: '123', assignee_id: '124')
|
39
49
|
end
|
40
50
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
it 'snoozes a conversation' do
|
52
|
+
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'snoozed', conversation_id: '147', admin_id: '123', snoozed_until: tomorrow}).returns(test_conversation)
|
53
|
+
client.conversations.snooze(id: '147', admin_id: '123', snoozed_until: tomorrow)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'runs assignment rules on a conversation' do
|
57
|
+
client.expects(:post).with('/conversations/147/run_assignment_rules', {}).returns(test_conversation)
|
58
|
+
client.conversations.run_assignment_rules('147')
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'nested resources' do
|
62
|
+
let(:conversation) { Intercom::Conversation.new('id' => '1', 'client' => client) }
|
63
|
+
let(:tag) { Intercom::Tag.new('id' => '1') }
|
47
64
|
|
65
|
+
it 'adds a tag to a conversation' do
|
66
|
+
client.expects(:post).with("/conversations/1/tags", { 'id': tag.id, 'admin_id': test_admin['id'] }).returns(tag.to_hash)
|
67
|
+
conversation.add_tag({ "id": tag.id, "admin_id": test_admin['id'] })
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'does not add a tag to a conversation if no admin_id is passed' do
|
71
|
+
client.expects(:post).with("/conversations/1/tags", { 'id': tag.id }).returns(nil)
|
72
|
+
_(proc { conversation.add_tag({ "id": tag.id }) }).must_raise Intercom::HttpError
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'removes a tag from a conversation' do
|
76
|
+
client.expects(:delete).with("/conversations/1/tags/1", { "id": tag.id, "admin_id": test_admin['id'] }).returns(tag.to_hash)
|
77
|
+
conversation.remove_tag({ "id": tag.id, "admin_id": test_admin['id'] })
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'does not remove a tag from a conversation if no admin_id is passed' do
|
81
|
+
client.expects(:delete).with("/conversations/1/tags/1", { "id": tag.id }).returns(nil)
|
82
|
+
_(proc { conversation.remove_tag({ "id": tag.id }) }).must_raise Intercom::HttpError
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'contacts' do
|
86
|
+
let(:response) do
|
87
|
+
{
|
88
|
+
customers: [
|
89
|
+
{ type: test_contact['type'], id: test_contact['id'] }
|
90
|
+
]
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'adds a contact to a conversation' do
|
95
|
+
client.expects(:post)
|
96
|
+
.with("/conversations/1/customers",
|
97
|
+
{ admin_id: test_admin['id'], customer: { intercom_user_id: test_contact['id'] } })
|
98
|
+
.returns(response.to_hash)
|
99
|
+
conversation.add_contact(admin_id: test_admin['id'], customer: { intercom_user_id: test_contact['id'] })
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'removes a contact from a conversation' do
|
103
|
+
client.expects(:delete)
|
104
|
+
.with("/conversations/1/customers/aaaaaaaaaaaaaaaaaaaaaaaa",
|
105
|
+
{ id: 'aaaaaaaaaaaaaaaaaaaaaaaa', admin_id: '1234' })
|
106
|
+
.returns(response.to_hash)
|
107
|
+
conversation.remove_contact(id: test_contact['id'], admin_id: test_admin['id'])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
48
111
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Intercom::Count" do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
6
|
it 'should get app wide counts' do
|
7
7
|
client.expects(:get).with("/counts", {}).returns(test_app_count)
|
8
8
|
counts = client.counts.for_app
|
9
|
-
counts.tag['count'].must_equal(341)
|
9
|
+
_(counts.tag['count']).must_equal(341)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should get type counts' do
|
13
13
|
client.expects(:get).with("/counts", {type: 'user', count: 'segment'}).returns(test_segment_count)
|
14
14
|
counts = client.counts.for_type(type: 'user', count: 'segment')
|
15
|
-
counts.user['segment'][4]["segment 1"].must_equal(1)
|
15
|
+
_(counts.user['segment'][4]["segment 1"]).must_equal(1)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not include count param when nil' do
|
19
19
|
client.expects(:get).with("/counts", {type: 'conversation'}).returns(test_conversation_count)
|
20
20
|
counts = client.counts.for_type(type: 'conversation')
|
21
|
-
counts.conversation.must_equal({
|
21
|
+
_(counts.conversation).must_equal({
|
22
22
|
"assigned" => 1,
|
23
23
|
"closed" => 15,
|
24
24
|
"open" => 1,
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Intercom::DataAttribute" do
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
|
+
|
6
|
+
it "returns a CollectionProxy for all without making any requests" do
|
7
|
+
client.expects(:execute_request).never
|
8
|
+
all = client.data_attributes.all
|
9
|
+
_(all).must_be_instance_of(Intercom::ClientCollectionProxy)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it "creates a new data attribute" do
|
14
|
+
client.expects(:post).with("/data_attributes", { "name" => "blah", "model" => "contact", "data_type" => "string" }).returns(status: 200)
|
15
|
+
client.data_attributes.create("name": "blah",
|
16
|
+
"model": "contact",
|
17
|
+
"data_type": "string" )
|
18
|
+
end
|
19
|
+
|
20
|
+
it "updates an existing attribute" do
|
21
|
+
attribute = Intercom::DataAttribute.new("id": 123,
|
22
|
+
"name": "blah",
|
23
|
+
"model": "contact",
|
24
|
+
"data_type": "string")
|
25
|
+
client.expects(:put).with("/data_attributes/#{attribute.id}", { "name" => "New name", "model" => "contact", "data_type" => "string" })
|
26
|
+
attribute.name = "New name"
|
27
|
+
client.data_attributes.save(attribute)
|
28
|
+
_(attribute.name).must_equal "New name"
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'gets a list of attributes' do
|
32
|
+
client.expects(:get).with("/data_attributes", {}).returns(test_data_attribute_list)
|
33
|
+
client.data_attributes.all.each { |d| }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'finds all customer or company attributes' do
|
37
|
+
client.expects(:get).with("/data_attributes", { "model": "contact" }).returns(test_data_attribute_list)
|
38
|
+
client.data_attributes.find_all({"model": "contact"}).each { |d| }
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Intercom::ClientCollectionProxy do
|
6
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
7
|
+
let(:lead_json) do
|
8
|
+
{ 'type' => 'contact.list', 'contacts' => [{ 'type' => 'contact', 'id' => 'id' }] }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'stops iterating if no next link' do
|
12
|
+
client.expects(:get).with('/contacts', {}).returns(lead_json)
|
13
|
+
client.deprecated__leads.all.each do |company|
|
14
|
+
_(company.class).must_equal Intercom::Lead
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,13 +4,32 @@ describe "Intercom::Event" 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
6
|
let(:created_time) {Time.now - 300}
|
7
|
-
let
|
7
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
8
8
|
|
9
9
|
it 'gets events for a user' do
|
10
10
|
client.expects(:get).with('/events', type: 'user', email: 'joe@example.com').returns(test_event_list)
|
11
11
|
client.events.find_all(type: 'user', email: 'joe@example.com').first
|
12
12
|
end
|
13
13
|
|
14
|
+
it "has the correct collection proxy class" do
|
15
|
+
_(client.events.collection_proxy_class).must_equal Intercom::EventCollectionProxy
|
16
|
+
end
|
17
|
+
|
18
|
+
it "stops iterating if no next link" do
|
19
|
+
client.expects(:get).with("/events", type: 'user', email: 'joe@example.com').returns(page_of_events(false))
|
20
|
+
event_names = []
|
21
|
+
client.events.find_all(type: 'user', email: 'joe@example.com').each { |event| event_names << event.event_name }
|
22
|
+
_(event_names).must_equal %W(invited-friend)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "keeps iterating if next link" do
|
26
|
+
client.expects(:get).with("/events", type: 'user', email: 'joe@example.com').returns(page_of_events(true))
|
27
|
+
client.expects(:get).with("https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550", {}).returns(page_of_events(false))
|
28
|
+
event_names = []
|
29
|
+
client.events.find_all(type: 'user', email: 'joe@example.com').each { |event| event_names << event.event_name }
|
30
|
+
_(event_names).must_equal %W(invited-friend invited-friend)
|
31
|
+
end
|
32
|
+
|
14
33
|
it "creates an event with metadata" do
|
15
34
|
client.expects(:post).with('/events', {'event_name' => 'Eventful 1', 'created_at' => created_time.to_i, 'email' => 'joe@example.com', 'metadata' => {'invitee_email' => 'pi@example.org', :invite_code => 'ADDAFRIEND', 'found_date' => 12909364407}}).returns(:status => 202)
|
16
35
|
|
@@ -55,15 +74,15 @@ describe "Intercom::Event" do
|
|
55
74
|
"state"=>"completed"
|
56
75
|
}
|
57
76
|
]
|
58
|
-
|
77
|
+
}
|
59
78
|
}
|
60
79
|
let(:bulk_request) {
|
61
|
-
|
80
|
+
{
|
62
81
|
items: [
|
63
82
|
{
|
64
83
|
method: "post",
|
65
84
|
data_type: "event",
|
66
|
-
data:{
|
85
|
+
data: {
|
67
86
|
event_name: "ordered-item",
|
68
87
|
created_at: 1438944980,
|
69
88
|
user_id: "314159",
|
@@ -76,7 +95,7 @@ describe "Intercom::Event" do
|
|
76
95
|
{
|
77
96
|
method: "post",
|
78
97
|
data_type: "event",
|
79
|
-
data:{
|
98
|
+
data: {
|
80
99
|
event_name: "invited-friend",
|
81
100
|
created_at: 1438944979,
|
82
101
|
user_id: "314159",
|
@@ -124,9 +143,7 @@ describe "Intercom::Event" do
|
|
124
143
|
end
|
125
144
|
|
126
145
|
it "does not submit delete jobs" do
|
127
|
-
lambda { client.events.submit_bulk_job(delete_items: events) }.must_raise ArgumentError
|
146
|
+
_(lambda { client.events.submit_bulk_job(delete_items: events) }).must_raise ArgumentError
|
128
147
|
end
|
129
|
-
|
130
148
|
end
|
131
|
-
|
132
149
|
end
|
@@ -1,41 +1,41 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "jobs" do
|
4
|
-
let
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
let (:job) {
|
6
6
|
{
|
7
|
-
"app_id"=>"app_id",
|
8
|
-
"id"=>"super_awesome_job",
|
9
|
-
"created_at"=>1446033421,
|
10
|
-
"completed_at"=>1446048736,
|
11
|
-
"closing_at"=>1446034321,
|
12
|
-
"updated_at"=>1446048736,
|
13
|
-
"name"=>"api_bulk_job",
|
14
|
-
"state"=>"completed",
|
15
|
-
"links"=>
|
7
|
+
"app_id" => "app_id",
|
8
|
+
"id" => "super_awesome_job",
|
9
|
+
"created_at" => 1446033421,
|
10
|
+
"completed_at" => 1446048736,
|
11
|
+
"closing_at" => 1446034321,
|
12
|
+
"updated_at" => 1446048736,
|
13
|
+
"name" => "api_bulk_job",
|
14
|
+
"state" => "completed",
|
15
|
+
"links" =>
|
16
16
|
{
|
17
|
-
"error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
|
18
|
-
"self"=>"https://api.intercom.io/jobs/super_awesome_job"
|
17
|
+
"error" => "https://api.intercom.io/jobs/super_awesome_job/error",
|
18
|
+
"self" => "https://api.intercom.io/jobs/super_awesome_job"
|
19
19
|
},
|
20
|
-
"tasks"=>
|
20
|
+
"tasks" =>
|
21
21
|
[
|
22
22
|
{
|
23
|
-
"id"=>"super_awesome_task",
|
24
|
-
"item_count"=>2,
|
25
|
-
"created_at"=>1446033421,
|
26
|
-
"started_at"=>1446033709,
|
27
|
-
"completed_at"=>1446033709,
|
28
|
-
"state"=>"completed"
|
23
|
+
"id" => "super_awesome_task",
|
24
|
+
"item_count" => 2,
|
25
|
+
"created_at" => 1446033421,
|
26
|
+
"started_at" => 1446033709,
|
27
|
+
"completed_at" => 1446033709,
|
28
|
+
"state" => "completed"
|
29
29
|
}
|
30
30
|
]
|
31
|
-
|
31
|
+
}
|
32
32
|
}
|
33
33
|
let (:error_feed) {
|
34
34
|
{
|
35
|
-
"app_id"=>"app_id",
|
36
|
-
"job_id"=>"super_awesome_job",
|
37
|
-
"pages"=>{},
|
38
|
-
"items"=>[]
|
35
|
+
"app_id" => "app_id",
|
36
|
+
"job_id" => "super_awesome_job",
|
37
|
+
"pages" => {},
|
38
|
+
"items" => []
|
39
39
|
}
|
40
40
|
}
|
41
41
|
|
@@ -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)
|