intercom 3.9.3 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +340 -222
- data/Rakefile +1 -1
- data/changes.txt +21 -0
- data/lib/intercom.rb +33 -22
- 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 +6 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +3 -2
- data/lib/intercom/article.rb +7 -0
- data/lib/intercom/base_collection_proxy.rb +72 -0
- data/lib/intercom/client.rb +32 -25
- 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 +21 -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 +6 -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 +38 -32
- data/lib/intercom/scroll_collection_proxy.rb +33 -38
- data/lib/intercom/search_collection_proxy.rb +30 -65
- data/lib/intercom/section.rb +23 -0
- data/lib/intercom/service/article.rb +20 -0
- data/lib/intercom/service/base_service.rb +7 -0
- data/lib/intercom/service/collection.rb +24 -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/section.rb +7 -0
- 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 +44 -18
- 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 +843 -520
- 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 +28 -25
- data/spec/unit/intercom/collection_spec.rb +32 -0
- data/spec/unit/intercom/company_spec.rb +13 -15
- data/spec/unit/intercom/contact_spec.rb +344 -33
- data/spec/unit/intercom/conversation_spec.rb +55 -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 +10 -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/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 +2 -2
- data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
- 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 +34 -8
- data/lib/intercom/customer.rb +0 -10
- data/lib/intercom/service/customer.rb +0 -14
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,283 +1,284 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Intercom::User' do
|
6
|
+
let (:client) { Intercom::Client.new(token: 'token') }
|
5
7
|
|
6
8
|
it "to_hash'es itself" do
|
7
9
|
created_at = Time.now
|
8
|
-
user = Intercom::User.new(:
|
10
|
+
user = Intercom::User.new(email: 'jim@example.com', user_id: '12345', created_at: created_at, name: 'Jim Bob')
|
9
11
|
as_hash = user.to_hash
|
10
|
-
as_hash[
|
11
|
-
as_hash[
|
12
|
-
as_hash[
|
13
|
-
as_hash[
|
12
|
+
_(as_hash['email']).must_equal 'jim@example.com'
|
13
|
+
_(as_hash['user_id']).must_equal '12345'
|
14
|
+
_(as_hash['created_at']).must_equal created_at.to_i
|
15
|
+
_(as_hash['name']).must_equal 'Jim Bob'
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
18
|
+
it 'presents created_at and last_impression_at as Date' do
|
17
19
|
now = Time.now
|
18
|
-
user = Intercom::User.from_api(:
|
19
|
-
user.created_at.must_be_kind_of Time
|
20
|
-
user.created_at.to_s.must_equal now.to_s
|
21
|
-
user.last_impression_at.must_be_kind_of Time
|
22
|
-
user.last_impression_at.to_s.must_equal now.to_s
|
20
|
+
user = Intercom::User.from_api(created_at: now, last_impression_at: now)
|
21
|
+
_(user.created_at).must_be_kind_of Time
|
22
|
+
_(user.created_at.to_s).must_equal now.to_s
|
23
|
+
_(user.last_impression_at).must_be_kind_of Time
|
24
|
+
_(user.last_impression_at.to_s).must_equal now.to_s
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it 'is throws a Intercom::AttributeNotSetError on trying to access an attribute that has not been set' do
|
26
28
|
user = Intercom::User.new
|
27
|
-
proc { user.foo_property }.must_raise Intercom::AttributeNotSetError
|
29
|
+
_(proc { user.foo_property }).must_raise Intercom::AttributeNotSetError
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it 'presents a complete user record correctly' do
|
31
33
|
user = Intercom::User.from_api(test_user)
|
32
|
-
user.user_id.must_equal 'id-from-customers-app'
|
33
|
-
user.email.must_equal 'bob@example.com'
|
34
|
-
user.name.must_equal 'Joe Schmoe'
|
35
|
-
user.app_id.must_equal 'the-app-id'
|
36
|
-
user.session_count.must_equal 123
|
37
|
-
user.created_at.to_i.must_equal
|
38
|
-
user.remote_created_at.to_i.must_equal
|
39
|
-
user.updated_at.to_i.must_equal
|
40
|
-
|
41
|
-
user.avatar.must_be_kind_of Intercom::Avatar
|
42
|
-
user.avatar.image_url.must_equal 'https://graph.facebook.com/1/picture?width=24&height=24'
|
43
|
-
|
44
|
-
user.companies.must_be_kind_of Array
|
45
|
-
user.companies.size.must_equal 1
|
46
|
-
user.companies[0].must_be_kind_of Intercom::Company
|
47
|
-
user.companies[0].company_id.must_equal
|
48
|
-
user.companies[0].id.must_equal
|
49
|
-
user.companies[0].app_id.must_equal
|
50
|
-
user.companies[0].name.must_equal
|
51
|
-
user.companies[0].remote_created_at.to_i.must_equal
|
52
|
-
user.companies[0].created_at.to_i.must_equal
|
53
|
-
user.companies[0].updated_at.to_i.must_equal
|
54
|
-
user.companies[0].last_request_at.to_i.must_equal
|
55
|
-
user.companies[0].monthly_spend.must_equal 0
|
56
|
-
user.companies[0].session_count.must_equal 0
|
57
|
-
user.companies[0].user_count.must_equal 1
|
58
|
-
user.companies[0].tag_ids.must_equal []
|
59
|
-
|
60
|
-
user.custom_attributes.must_be_kind_of Intercom::Lib::FlatStore
|
61
|
-
user.custom_attributes[
|
62
|
-
user.custom_attributes[
|
63
|
-
|
64
|
-
user.social_profiles.size.must_equal 4
|
34
|
+
_(user.user_id).must_equal 'id-from-customers-app'
|
35
|
+
_(user.email).must_equal 'bob@example.com'
|
36
|
+
_(user.name).must_equal 'Joe Schmoe'
|
37
|
+
_(user.app_id).must_equal 'the-app-id'
|
38
|
+
_(user.session_count).must_equal 123
|
39
|
+
_(user.created_at.to_i).must_equal 1_401_970_114
|
40
|
+
_(user.remote_created_at.to_i).must_equal 1_393_613_864
|
41
|
+
_(user.updated_at.to_i).must_equal 1_401_970_114
|
42
|
+
|
43
|
+
_(user.avatar).must_be_kind_of Intercom::Avatar
|
44
|
+
_(user.avatar.image_url).must_equal 'https://graph.facebook.com/1/picture?width=24&height=24'
|
45
|
+
|
46
|
+
_(user.companies).must_be_kind_of Array
|
47
|
+
_(user.companies.size).must_equal 1
|
48
|
+
_(user.companies[0]).must_be_kind_of Intercom::Company
|
49
|
+
_(user.companies[0].company_id).must_equal '123'
|
50
|
+
_(user.companies[0].id).must_equal 'bbbbbbbbbbbbbbbbbbbbbbbb'
|
51
|
+
_(user.companies[0].app_id).must_equal 'the-app-id'
|
52
|
+
_(user.companies[0].name).must_equal 'Company 1'
|
53
|
+
_(user.companies[0].remote_created_at.to_i).must_equal 1_390_936_440
|
54
|
+
_(user.companies[0].created_at.to_i).must_equal 1_401_970_114
|
55
|
+
_(user.companies[0].updated_at.to_i).must_equal 1_401_970_114
|
56
|
+
_(user.companies[0].last_request_at.to_i).must_equal 1_401_970_113
|
57
|
+
_(user.companies[0].monthly_spend).must_equal 0
|
58
|
+
_(user.companies[0].session_count).must_equal 0
|
59
|
+
_(user.companies[0].user_count).must_equal 1
|
60
|
+
_(user.companies[0].tag_ids).must_equal []
|
61
|
+
|
62
|
+
_(user.custom_attributes).must_be_kind_of Intercom::Lib::FlatStore
|
63
|
+
_(user.custom_attributes['a']).must_equal 'b'
|
64
|
+
_(user.custom_attributes['b']).must_equal 2
|
65
|
+
|
66
|
+
_(user.social_profiles.size).must_equal 4
|
65
67
|
twitter_account = user.social_profiles.first
|
66
|
-
twitter_account.must_be_kind_of Intercom::SocialProfile
|
67
|
-
twitter_account.name.must_equal
|
68
|
-
twitter_account.username.must_equal
|
69
|
-
twitter_account.url.must_equal
|
70
|
-
|
71
|
-
user.location_data.must_be_kind_of Intercom::LocationData
|
72
|
-
user.location_data.city_name.must_equal
|
73
|
-
user.location_data.continent_code.must_equal
|
74
|
-
user.location_data.country_name.must_equal
|
75
|
-
user.location_data.latitude.must_equal
|
76
|
-
user.location_data.longitude.must_equal
|
77
|
-
user.location_data.country_code.must_equal
|
78
|
-
|
79
|
-
user.unsubscribed_from_emails.must_equal true
|
80
|
-
user.user_agent_data.must_equal
|
68
|
+
_(twitter_account).must_be_kind_of Intercom::SocialProfile
|
69
|
+
_(twitter_account.name).must_equal 'twitter'
|
70
|
+
_(twitter_account.username).must_equal 'abc'
|
71
|
+
_(twitter_account.url).must_equal 'http://twitter.com/abc'
|
72
|
+
|
73
|
+
_(user.location_data).must_be_kind_of Intercom::LocationData
|
74
|
+
_(user.location_data.city_name).must_equal 'Dublin'
|
75
|
+
_(user.location_data.continent_code).must_equal 'EU'
|
76
|
+
_(user.location_data.country_name).must_equal 'Ireland'
|
77
|
+
_(user.location_data.latitude).must_equal '90'
|
78
|
+
_(user.location_data.longitude).must_equal '10'
|
79
|
+
_(user.location_data.country_code).must_equal 'IRL'
|
80
|
+
|
81
|
+
_(user.unsubscribed_from_emails).must_equal true
|
82
|
+
_(user.user_agent_data).must_equal 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'
|
81
83
|
end
|
82
84
|
|
83
85
|
it 'allows update_last_request_at' do
|
84
|
-
client.expects(:post).with(
|
85
|
-
client.
|
86
|
+
client.expects(:post).with('/users', 'user_id' => '1224242', 'update_last_request_at' => true, 'custom_attributes' => {}).returns('user_id' => 'i-1224242', 'last_request_at' => 1_414_509_439)
|
87
|
+
client.deprecated__users.create(user_id: '1224242', update_last_request_at: true)
|
86
88
|
end
|
87
89
|
|
88
|
-
it
|
90
|
+
it 'allows easy setting of custom data' do
|
89
91
|
now = Time.now
|
90
92
|
user = Intercom::User.new
|
91
|
-
user.custom_attributes[
|
92
|
-
user.custom_attributes[
|
93
|
-
user.custom_attributes[
|
94
|
-
user.to_hash[
|
93
|
+
user.custom_attributes['mad'] = 123
|
94
|
+
user.custom_attributes['other'] = now.to_i
|
95
|
+
user.custom_attributes['thing'] = 'yay'
|
96
|
+
_(user.to_hash['custom_attributes']).must_equal 'mad' => 123, 'other' => now.to_i, 'thing' => 'yay'
|
95
97
|
end
|
96
98
|
|
97
|
-
it
|
98
|
-
user = Intercom::User.new
|
99
|
+
it 'allows easy setting of multiple companies' do
|
100
|
+
user = Intercom::User.new
|
99
101
|
companies = [
|
100
|
-
{
|
101
|
-
{
|
102
|
+
{ 'name' => 'Intercom', 'company_id' => '6' },
|
103
|
+
{ 'name' => 'Test', 'company_id' => '9' }
|
102
104
|
]
|
103
105
|
user.companies = companies
|
104
|
-
user.to_hash[
|
106
|
+
_(user.to_hash['companies']).must_equal companies
|
105
107
|
end
|
106
108
|
|
107
|
-
it
|
108
|
-
user = Intercom::User.new
|
109
|
+
it 'rejects nested data structures in custom_attributes' do
|
110
|
+
user = Intercom::User.new
|
109
111
|
|
110
|
-
proc { user.custom_attributes[
|
111
|
-
proc { user.custom_attributes[
|
112
|
-
proc { user.custom_attributes[
|
112
|
+
_(proc { user.custom_attributes['thing'] = [1] }).must_raise(ArgumentError)
|
113
|
+
_(proc { user.custom_attributes['thing'] = { 1 => 2 } }).must_raise(ArgumentError)
|
114
|
+
_(proc { user.custom_attributes['thing'] = { 1 => { 2 => 3 } } }).must_raise(ArgumentError)
|
113
115
|
|
114
116
|
user = Intercom::User.from_api(test_user)
|
115
|
-
proc { user.custom_attributes[
|
117
|
+
_(proc { user.custom_attributes['thing'] = [1] }).must_raise(ArgumentError)
|
116
118
|
end
|
117
119
|
|
118
|
-
describe
|
120
|
+
describe 'incrementing custom_attributes fields' do
|
119
121
|
before :each do
|
120
122
|
@now = Time.now
|
121
|
-
@user = Intercom::User.new(
|
123
|
+
@user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :custom_attributes => { 'mad' => 123, 'another' => 432, 'other' => @now.to_i, :thing => 'yay' })
|
122
124
|
end
|
123
125
|
|
124
|
-
it
|
125
|
-
@user.increment(
|
126
|
-
@user.to_hash[
|
126
|
+
it 'increments up by 1 with no args' do
|
127
|
+
@user.increment('mad')
|
128
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 124
|
127
129
|
end
|
128
130
|
|
129
|
-
it
|
130
|
-
@user.increment(
|
131
|
-
@user.to_hash[
|
131
|
+
it 'increments up by given value' do
|
132
|
+
@user.increment('mad', 4)
|
133
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 127
|
132
134
|
end
|
133
135
|
|
134
|
-
it
|
135
|
-
@user.increment(
|
136
|
-
@user.to_hash[
|
136
|
+
it 'increments down by given value' do
|
137
|
+
@user.increment('mad', -1)
|
138
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 122
|
137
139
|
end
|
138
140
|
|
139
|
-
it
|
140
|
-
@user.increment(
|
141
|
-
@user.to_hash[
|
141
|
+
it 'can increment new custom data fields' do
|
142
|
+
@user.increment('new_field', 3)
|
143
|
+
_(@user.to_hash['custom_attributes']['new_field']).must_equal 3
|
142
144
|
end
|
143
145
|
|
144
|
-
it
|
145
|
-
@user.increment(
|
146
|
-
@user.increment(
|
147
|
-
@user.to_hash[
|
146
|
+
it 'can call increment on the same key twice and increment by 2' do
|
147
|
+
@user.increment('mad')
|
148
|
+
@user.increment('mad')
|
149
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 125
|
148
150
|
end
|
149
151
|
end
|
150
152
|
|
151
|
-
describe
|
153
|
+
describe 'decrementing custom_attributes fields' do
|
152
154
|
before :each do
|
153
155
|
@now = Time.now
|
154
|
-
@user = Intercom::User.new(
|
156
|
+
@user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :custom_attributes => { 'mad' => 123, 'another' => 432, 'other' => @now.to_i, :thing => 'yay' })
|
155
157
|
end
|
156
158
|
|
157
|
-
it
|
158
|
-
@user.decrement(
|
159
|
-
@user.to_hash[
|
159
|
+
it 'decrements down by 1 with no args' do
|
160
|
+
@user.decrement('mad')
|
161
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 122
|
160
162
|
end
|
161
163
|
|
162
|
-
it
|
163
|
-
@user.decrement(
|
164
|
-
@user.to_hash[
|
164
|
+
it 'decrements down by given value' do
|
165
|
+
@user.decrement('mad', 3)
|
166
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 120
|
165
167
|
end
|
166
168
|
|
167
|
-
it
|
168
|
-
@user.decrement(
|
169
|
-
@user.to_hash[
|
169
|
+
it 'can decrement new custom data fields' do
|
170
|
+
@user.decrement('new_field', 5)
|
171
|
+
_(@user.to_hash['custom_attributes']['new_field']).must_equal(-5)
|
170
172
|
end
|
171
173
|
|
172
|
-
it
|
173
|
-
@user.decrement(
|
174
|
-
@user.decrement(
|
175
|
-
@user.to_hash[
|
174
|
+
it 'can call decrement on the same key twice and decrement by 2' do
|
175
|
+
@user.decrement('mad')
|
176
|
+
@user.decrement('mad')
|
177
|
+
_(@user.to_hash['custom_attributes']['mad']).must_equal 121
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
179
|
-
it
|
180
|
-
client.expects(:get).with(
|
181
|
-
user = client.
|
182
|
-
user.email.must_equal
|
183
|
-
user.name.must_equal
|
184
|
-
user.session_count.must_equal 123
|
181
|
+
it 'fetches a user' do
|
182
|
+
client.expects(:get).with('/users', 'email' => 'bo@example.com').returns(test_user)
|
183
|
+
user = client.deprecated__users.find('email' => 'bo@example.com')
|
184
|
+
_(user.email).must_equal 'bob@example.com'
|
185
|
+
_(user.name).must_equal 'Joe Schmoe'
|
186
|
+
_(user.session_count).must_equal 123
|
185
187
|
end
|
186
188
|
|
187
189
|
it 'gets users by tag' do
|
188
|
-
client.expects(:get).with(
|
189
|
-
client.
|
190
|
+
client.expects(:get).with('/users?tag_id=124', {}).returns(page_of_users(false))
|
191
|
+
client.deprecated__users.by_tag(124).each { |t| }
|
190
192
|
end
|
191
193
|
|
192
194
|
it 'gets users by segment' do
|
193
|
-
client.expects(:get).with(
|
194
|
-
client.
|
195
|
+
client.expects(:get).with('/users?segment_id=124', {}).returns(page_of_users(false))
|
196
|
+
client.deprecated__users.by_segment(124).each { |t| }
|
195
197
|
end
|
196
198
|
|
197
|
-
it
|
198
|
-
user = Intercom::User.new(
|
199
|
-
client.expects(:post).with(
|
200
|
-
client.
|
199
|
+
it 'saves a user (always sends custom_attributes)' do
|
200
|
+
user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242')
|
201
|
+
client.expects(:post).with('/users', 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'custom_attributes' => {}).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
|
202
|
+
client.deprecated__users.save(user)
|
201
203
|
end
|
202
204
|
|
203
|
-
it
|
204
|
-
user = Intercom::User.new(
|
205
|
-
client.expects(:post).with(
|
206
|
-
client.
|
205
|
+
it 'saves a user with a company' do
|
206
|
+
user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :company => { 'company_id' => 6, 'name' => 'Intercom' })
|
207
|
+
client.expects(:post).with('/users', 'custom_attributes' => {}, 'user_id' => 'i-1224242', 'email' => 'jo@example.com', 'company' => { 'company_id' => 6, 'name' => 'Intercom' }).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
|
208
|
+
client.deprecated__users.save(user)
|
207
209
|
end
|
208
210
|
|
209
|
-
it
|
210
|
-
user = Intercom::User.new(
|
211
|
-
client.expects(:post).with(
|
212
|
-
client.
|
211
|
+
it 'saves a user with a companies' do
|
212
|
+
user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :companies => [{ 'company_id' => 6, 'name' => 'Intercom' }])
|
213
|
+
client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'companies' => [{ 'company_id' => 6, 'name' => 'Intercom' }]).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
|
214
|
+
client.deprecated__users.save(user)
|
213
215
|
end
|
214
216
|
|
215
217
|
it 'can save a user with a nil email' do
|
216
|
-
user = Intercom::User.new(
|
217
|
-
client.expects(:post).with(
|
218
|
-
client.
|
218
|
+
user = Intercom::User.new('email' => nil, :user_id => 'i-1224242', :companies => [{ 'company_id' => 6, 'name' => 'Intercom' }])
|
219
|
+
client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => nil, 'user_id' => 'i-1224242', 'companies' => [{ 'company_id' => 6, 'name' => 'Intercom' }]).returns('email' => nil, 'user_id' => 'i-1224242')
|
220
|
+
client.deprecated__users.save(user)
|
219
221
|
end
|
220
222
|
|
221
|
-
it
|
222
|
-
user = Intercom::User.new(
|
223
|
-
client.expects(:delete).with(
|
224
|
-
client.
|
223
|
+
it 'archives a user' do
|
224
|
+
user = Intercom::User.new('id' => '1')
|
225
|
+
client.expects(:delete).with('/users/1', {}).returns(user)
|
226
|
+
client.deprecated__users.archive(user)
|
227
|
+
end
|
228
|
+
it 'has an alias to archive a user' do
|
229
|
+
user = Intercom::User.new('id' => '1')
|
230
|
+
client.expects(:delete).with('/users/1', {}).returns(user)
|
231
|
+
client.deprecated__users.delete(user)
|
225
232
|
end
|
226
|
-
it "has an alias to archive a user" do
|
227
|
-
user = Intercom::User.new("id" => "1")
|
228
|
-
client.expects(:delete).with("/users/1", {}).returns(user)
|
229
|
-
client.users.delete(user)
|
230
|
-
end
|
231
|
-
|
232
233
|
|
233
|
-
it
|
234
|
-
user = Intercom::User.new(
|
235
|
-
client.expects(:post).with(
|
236
|
-
client.
|
234
|
+
it 'sends a request for a hard deletion' do
|
235
|
+
user = Intercom::User.new('id' => '1')
|
236
|
+
client.expects(:post).with('/user_delete_requests', intercom_user_id: '1').returns(id: user.id)
|
237
|
+
client.deprecated__users.request_hard_delete(user)
|
237
238
|
end
|
238
239
|
|
239
|
-
it
|
240
|
-
client.expects(:post).with(
|
241
|
-
user = client.
|
242
|
-
user.email.must_equal
|
240
|
+
it 'can use client.users.create for convenience' do
|
241
|
+
client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => 'jo@example.com', 'user_id' => 'i-1224242').returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
|
242
|
+
user = client.deprecated__users.create('email' => 'jo@example.com', :user_id => 'i-1224242')
|
243
|
+
_(user.email).must_equal 'jo@example.com'
|
243
244
|
end
|
244
245
|
|
245
|
-
it
|
246
|
-
client.expects(:post).with(
|
247
|
-
user = client.
|
248
|
-
user.session_count.must_equal 4
|
246
|
+
it 'updates the user with attributes as set by the server' do
|
247
|
+
client.expects(:post).with('/users', 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'custom_attributes' => {}).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242', 'session_count' => 4)
|
248
|
+
user = client.deprecated__users.create('email' => 'jo@example.com', :user_id => 'i-1224242')
|
249
|
+
_(user.session_count).must_equal 4
|
249
250
|
end
|
250
251
|
|
251
|
-
it
|
252
|
-
client.expects(:post).with(
|
253
|
-
user = client.
|
252
|
+
it 'allows setting dates to nil without converting them to 0' do
|
253
|
+
client.expects(:post).with('/users', 'email' => 'jo@example.com', 'custom_attributes' => {}, 'remote_created_at' => nil).returns('email' => 'jo@example.com')
|
254
|
+
user = client.deprecated__users.create('email' => 'jo@example.com', 'remote_created_at' => nil)
|
254
255
|
assert_nil user.remote_created_at
|
255
256
|
end
|
256
257
|
|
257
|
-
it
|
258
|
-
params = {
|
258
|
+
it 'sets/gets rw keys' do
|
259
|
+
params = { 'email' => 'me@example.com', :user_id => 'abc123', 'name' => 'Bob Smith', 'last_seen_ip' => '1.2.3.4', 'last_seen_user_agent' => 'ie6', 'created_at' => Time.now }
|
259
260
|
user = Intercom::User.new(params)
|
260
261
|
custom_attributes = (params.keys + ['custom_attributes']).map(&:to_s).sort
|
261
|
-
user.to_hash.keys.sort.must_equal custom_attributes
|
262
|
+
_(user.to_hash.keys.sort).must_equal custom_attributes
|
262
263
|
params.keys.each do |key|
|
263
|
-
user.send(key).to_s.must_equal params[key].to_s
|
264
|
+
_(user.send(key).to_s).must_equal params[key].to_s
|
264
265
|
end
|
265
266
|
end
|
266
267
|
|
267
|
-
it
|
268
|
-
user = Intercom::User.send(:from_api,
|
269
|
-
user.new_param.must_equal
|
268
|
+
it 'will allow extra attributes in response from api' do
|
269
|
+
user = Intercom::User.send(:from_api, 'new_param' => 'some value')
|
270
|
+
_(user.new_param).must_equal 'some value'
|
270
271
|
end
|
271
272
|
|
272
|
-
it
|
273
|
+
it 'returns a ClientCollectionProxy for all without making any requests' do
|
273
274
|
client.expects(:execute_request).never
|
274
|
-
all = client.
|
275
|
-
all.must_be_instance_of(Intercom::ClientCollectionProxy)
|
275
|
+
all = client.deprecated__users.all
|
276
|
+
_(all).must_be_instance_of(Intercom::ClientCollectionProxy)
|
276
277
|
end
|
277
278
|
|
278
279
|
it 'can print users without crashing' do
|
279
|
-
client.expects(:get).with(
|
280
|
-
user = client.
|
280
|
+
client.expects(:get).with('/users', 'email' => 'bo@example.com').returns(test_user)
|
281
|
+
user = client.deprecated__users.find('email' => 'bo@example.com')
|
281
282
|
|
282
283
|
begin
|
283
284
|
orignal_stdout = $stdout
|
@@ -285,91 +286,88 @@ describe "Intercom::User" do
|
|
285
286
|
|
286
287
|
puts user
|
287
288
|
p user
|
288
|
-
|
289
289
|
ensure
|
290
290
|
$stdout = orignal_stdout
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
294
|
describe 'bulk operations' do
|
295
|
-
let (:job)
|
295
|
+
let (:job) do
|
296
296
|
{
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
297
|
+
'app_id' => 'app_id',
|
298
|
+
'id' => 'super_awesome_job',
|
299
|
+
'created_at' => 1_446_033_421,
|
300
|
+
'completed_at' => 1_446_048_736,
|
301
|
+
'closing_at' => 1_446_034_321,
|
302
|
+
'updated_at' => 1_446_048_736,
|
303
|
+
'name' => 'api_bulk_job',
|
304
|
+
'state' => 'completed',
|
305
|
+
'links' =>
|
306
306
|
{
|
307
|
-
|
308
|
-
|
307
|
+
'error' => 'https://api.intercom.io/jobs/super_awesome_job/error',
|
308
|
+
'self' => 'https://api.intercom.io/jobs/super_awesome_job'
|
309
309
|
},
|
310
|
-
|
310
|
+
'tasks' =>
|
311
311
|
[
|
312
312
|
{
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
313
|
+
'id' => 'super_awesome_task',
|
314
|
+
'item_count' => 2,
|
315
|
+
'created_at' => 1_446_033_421,
|
316
|
+
'started_at' => 1_446_033_709,
|
317
|
+
'completed_at' => 1_446_033_709,
|
318
|
+
'state' => 'completed'
|
319
319
|
}
|
320
320
|
]
|
321
|
-
|
322
|
-
|
323
|
-
let(:bulk_request)
|
324
|
-
|
321
|
+
}
|
322
|
+
end
|
323
|
+
let(:bulk_request) do
|
324
|
+
{
|
325
325
|
items: [
|
326
326
|
{
|
327
|
-
method:
|
328
|
-
data_type:
|
329
|
-
data:{
|
327
|
+
method: 'post',
|
328
|
+
data_type: 'user',
|
329
|
+
data: {
|
330
330
|
user_id: 25,
|
331
|
-
email:
|
331
|
+
email: 'alice@example.com'
|
332
332
|
}
|
333
333
|
},
|
334
334
|
{
|
335
|
-
method:
|
336
|
-
data_type:
|
337
|
-
data:{
|
335
|
+
method: 'delete',
|
336
|
+
data_type: 'user',
|
337
|
+
data: {
|
338
338
|
user_id: 26,
|
339
|
-
email:
|
339
|
+
email: 'bob@example.com'
|
340
340
|
}
|
341
341
|
}
|
342
342
|
]
|
343
343
|
}
|
344
|
-
|
345
|
-
let(:users_to_create)
|
344
|
+
end
|
345
|
+
let(:users_to_create) do
|
346
346
|
[
|
347
347
|
{
|
348
348
|
user_id: 25,
|
349
|
-
email:
|
349
|
+
email: 'alice@example.com'
|
350
350
|
}
|
351
351
|
]
|
352
|
-
|
353
|
-
let(:users_to_delete)
|
352
|
+
end
|
353
|
+
let(:users_to_delete) do
|
354
354
|
[
|
355
355
|
{
|
356
356
|
user_id: 26,
|
357
|
-
email:
|
357
|
+
email: 'bob@example.com'
|
358
358
|
}
|
359
359
|
]
|
360
|
-
}
|
361
|
-
|
362
|
-
it "submits a bulk job" do
|
363
|
-
client.expects(:post).with("/bulk/users", bulk_request).returns(job)
|
364
|
-
client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete)
|
365
360
|
end
|
366
361
|
|
367
|
-
it
|
368
|
-
|
369
|
-
client.
|
370
|
-
client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete, job_id: 'super_awesome_job')
|
362
|
+
it 'submits a bulk job' do
|
363
|
+
client.expects(:post).with('/bulk/users', bulk_request).returns(job)
|
364
|
+
client.deprecated__users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete)
|
371
365
|
end
|
372
366
|
|
367
|
+
it 'adds users to an existing bulk job' do
|
368
|
+
bulk_request[:job] = { id: 'super_awesome_job' }
|
369
|
+
client.expects(:post).with('/bulk/users', bulk_request).returns(job)
|
370
|
+
client.deprecated__users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete, job_id: 'super_awesome_job')
|
371
|
+
end
|
373
372
|
end
|
374
|
-
|
375
373
|
end
|