hubspot-api-ruby 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +18 -0
- data/README.md +295 -0
- data/RELEASING.md +6 -0
- data/Rakefile +32 -0
- data/hubspot-api-ruby.gemspec +42 -0
- data/lib/hubspot-api-ruby.rb +39 -0
- data/lib/hubspot/blog.rb +98 -0
- data/lib/hubspot/collection.rb +41 -0
- data/lib/hubspot/company.rb +160 -0
- data/lib/hubspot/company_properties.rb +59 -0
- data/lib/hubspot/config.rb +63 -0
- data/lib/hubspot/connection.rb +152 -0
- data/lib/hubspot/contact.rb +110 -0
- data/lib/hubspot/contact_list.rb +129 -0
- data/lib/hubspot/contact_properties.rb +59 -0
- data/lib/hubspot/deal.rb +173 -0
- data/lib/hubspot/deal_pipeline.rb +58 -0
- data/lib/hubspot/deal_properties.rb +59 -0
- data/lib/hubspot/deprecator.rb +7 -0
- data/lib/hubspot/engagement.rb +222 -0
- data/lib/hubspot/event.rb +21 -0
- data/lib/hubspot/exceptions.rb +18 -0
- data/lib/hubspot/file.rb +38 -0
- data/lib/hubspot/form.rb +95 -0
- data/lib/hubspot/oauth.rb +50 -0
- data/lib/hubspot/owner.rb +57 -0
- data/lib/hubspot/paged_collection.rb +35 -0
- data/lib/hubspot/properties.rb +123 -0
- data/lib/hubspot/railtie.rb +10 -0
- data/lib/hubspot/resource.rb +270 -0
- data/lib/hubspot/subscription.rb +37 -0
- data/lib/hubspot/topic.rb +37 -0
- data/lib/hubspot/utils.rb +127 -0
- data/lib/tasks/hubspot.rake +53 -0
- data/spec/factories/companies.rb +9 -0
- data/spec/factories/contacts.rb +10 -0
- data/spec/lib/hubspot-ruby_spec.rb +12 -0
- data/spec/lib/hubspot/blog_spec.rb +150 -0
- data/spec/lib/hubspot/company_properties_spec.rb +410 -0
- data/spec/lib/hubspot/company_spec.rb +340 -0
- data/spec/lib/hubspot/config_spec.rb +87 -0
- data/spec/lib/hubspot/connection_spec.rb +214 -0
- data/spec/lib/hubspot/contact_list_spec.rb +301 -0
- data/spec/lib/hubspot/contact_properties_spec.rb +245 -0
- data/spec/lib/hubspot/contact_spec.rb +223 -0
- data/spec/lib/hubspot/deal_pipeline_spec.rb +85 -0
- data/spec/lib/hubspot/deal_properties_spec.rb +262 -0
- data/spec/lib/hubspot/deal_spec.rb +185 -0
- data/spec/lib/hubspot/deprecator_spec.rb +15 -0
- data/spec/lib/hubspot/engagement_spec.rb +177 -0
- data/spec/lib/hubspot/event_spec.rb +33 -0
- data/spec/lib/hubspot/file_spec.rb +38 -0
- data/spec/lib/hubspot/form_spec.rb +189 -0
- data/spec/lib/hubspot/owner_spec.rb +56 -0
- data/spec/lib/hubspot/properties_spec.rb +45 -0
- data/spec/lib/hubspot/resource_spec.rb +54 -0
- data/spec/lib/hubspot/topic_spec.rb +23 -0
- data/spec/lib/hubspot/utils_spec.rb +164 -0
- data/spec/lib/tasks/hubspot_spec.rb +119 -0
- data/spec/shared_examples/saveable_resource.rb +45 -0
- data/spec/shared_examples/updateable_resource.rb +87 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/capture_output.rb +21 -0
- data/spec/support/cassette_helper.rb +19 -0
- data/spec/support/hubspot_api_helpers.rb +13 -0
- data/spec/support/rake.rb +46 -0
- data/spec/support/tests_helper.rb +17 -0
- data/spec/support/vcr.rb +16 -0
- metadata +369 -0
@@ -0,0 +1,301 @@
|
|
1
|
+
describe Hubspot::ContactList do
|
2
|
+
let(:example_contact_list_hash) do
|
3
|
+
VCR.use_cassette("contact_list_example") do
|
4
|
+
HTTParty.get("https://api.hubapi.com/contacts/v1/lists/1?hapikey=demo").parsed_response
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:static_list) { Hubspot::ContactList.all(static: true, count: 3).last }
|
9
|
+
let(:dynamic_list) { Hubspot::ContactList.all(dynamic: true, count: 1).first }
|
10
|
+
|
11
|
+
let(:example_contact_hash) do
|
12
|
+
VCR.use_cassette("contact_example") do
|
13
|
+
HTTParty.get("https://api.hubapi.com/contacts/v1/contact/email/testingapis@hubspot.com/profile?hapikey=demo").parsed_response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#initialize' do
|
18
|
+
subject { Hubspot::ContactList.new(example_contact_list_hash) }
|
19
|
+
|
20
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
21
|
+
its(:id) { should be_an(Integer) }
|
22
|
+
its(:portal_id) { should be_a(Integer) }
|
23
|
+
its(:name) { should_not be_empty }
|
24
|
+
its(:dynamic) { should be true }
|
25
|
+
its(:properties) { should be_a(Hash) }
|
26
|
+
end
|
27
|
+
|
28
|
+
before { Hubspot.configure(hapikey: "demo") }
|
29
|
+
|
30
|
+
describe '#contacts' do
|
31
|
+
cassette 'contacts_among_list'
|
32
|
+
|
33
|
+
let(:list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
34
|
+
|
35
|
+
it 'returns by default 20 contact lists' do
|
36
|
+
expect(list.contacts.count).to eql 20
|
37
|
+
contact = list.contacts.first
|
38
|
+
expect(contact).to be_a(Hubspot::Contact)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns by default 20 contact lists with paging data' do
|
42
|
+
contact_data = list.contacts({paged: true})
|
43
|
+
contacts = contact_data['contacts']
|
44
|
+
|
45
|
+
expect(contact_data).to have_key 'vid-offset'
|
46
|
+
expect(contact_data).to have_key 'has-more'
|
47
|
+
|
48
|
+
expect(contacts.count).to eql 20
|
49
|
+
contact = contacts.first
|
50
|
+
expect(contact).to be_a(Hubspot::Contact)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'add default properties to the contacts returned' do
|
54
|
+
contact = list.contacts.first
|
55
|
+
expect(contact.email).to_not be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
expect_count_and_offset do |params|
|
59
|
+
Hubspot::ContactList.find(1).contacts(params)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.create' do
|
64
|
+
subject{ Hubspot::ContactList.create!({ name: name }) }
|
65
|
+
|
66
|
+
context 'with all required parameters' do
|
67
|
+
cassette 'create_list'
|
68
|
+
|
69
|
+
let(:name) { 'testing list' }
|
70
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
71
|
+
its(:id) { should be_an(Integer) }
|
72
|
+
its(:portal_id) { should be_an(Integer) }
|
73
|
+
its(:dynamic) { should be false }
|
74
|
+
|
75
|
+
context 'adding filters parameters' do
|
76
|
+
cassette 'create_list_with_filters'
|
77
|
+
|
78
|
+
it 'returns a ContactList object with filters set' do
|
79
|
+
name = 'list with filters'
|
80
|
+
filters_param = [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]
|
81
|
+
list_with_filters = Hubspot::ContactList.create!({ name: name, filters: filters_param })
|
82
|
+
expect(list_with_filters).to be_a(Hubspot::ContactList)
|
83
|
+
expect(list_with_filters.properties['filters']).to_not be_empty
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'without all required parameters' do
|
89
|
+
cassette 'fail_to_create_list'
|
90
|
+
|
91
|
+
it 'raises an error' do
|
92
|
+
expect { Hubspot::ContactList.create!({ name: nil }) }.to raise_error(Hubspot::RequestError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '.all' do
|
98
|
+
context 'all list types' do
|
99
|
+
cassette 'find_all_lists'
|
100
|
+
|
101
|
+
it 'returns by default 20 contact lists' do
|
102
|
+
lists = Hubspot::ContactList.all
|
103
|
+
expect(lists.count).to eql 20
|
104
|
+
|
105
|
+
list = lists.first
|
106
|
+
expect(list).to be_a(Hubspot::ContactList)
|
107
|
+
expect(list.id).to be_an(Integer)
|
108
|
+
end
|
109
|
+
|
110
|
+
expect_count_and_offset { |params| Hubspot::ContactList.all(params) }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'static lists' do
|
114
|
+
cassette 'find_all_stastic_lists'
|
115
|
+
|
116
|
+
it 'returns by defaut all the static contact lists' do
|
117
|
+
lists = Hubspot::ContactList.all(static: true)
|
118
|
+
expect(lists.count).to be > 20
|
119
|
+
|
120
|
+
list = lists.first
|
121
|
+
expect(list).to be_a(Hubspot::ContactList)
|
122
|
+
expect(list.dynamic).to be false
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'dynamic lists' do
|
127
|
+
cassette 'find_all_dynamic_lists'
|
128
|
+
|
129
|
+
it 'returns by defaut all the static contact lists' do
|
130
|
+
lists = Hubspot::ContactList.all(dynamic: true)
|
131
|
+
expect(lists.count).to be > 20
|
132
|
+
|
133
|
+
list = lists.first
|
134
|
+
expect(list).to be_a(Hubspot::ContactList)
|
135
|
+
expect(list.dynamic).to be true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '.find' do
|
141
|
+
context 'given an id' do
|
142
|
+
cassette "contact_list_find"
|
143
|
+
subject { Hubspot::ContactList.find(id) }
|
144
|
+
|
145
|
+
context 'when the contact list is found' do
|
146
|
+
let(:id) { 1 }
|
147
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
148
|
+
its(:name) { should == 'twitterers' }
|
149
|
+
|
150
|
+
let(:id) { '1' }
|
151
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'Wrong parameter type given' do
|
155
|
+
it 'raises an error' do
|
156
|
+
expect { Hubspot::ContactList.find(static_list) }.to raise_error(Hubspot::InvalidParams)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when the contact list is not found' do
|
161
|
+
it 'raises an error' do
|
162
|
+
expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::RequestError)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'given a list of ids' do
|
168
|
+
cassette "contact_list_batch_find"
|
169
|
+
|
170
|
+
it 'find lists of contacts' do
|
171
|
+
lists = Hubspot::ContactList.find([2,3,4])
|
172
|
+
list = lists.first
|
173
|
+
expect(list).to be_a(Hubspot::ContactList)
|
174
|
+
expect(list.id).to be == 2
|
175
|
+
expect(lists.second.id).to be == 3
|
176
|
+
expect(lists.last.id).to be == 4
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#add" do
|
182
|
+
context "for a static list" do
|
183
|
+
it "adds the contact to the contact list" do
|
184
|
+
VCR.use_cassette("contact_lists/add_contact") do
|
185
|
+
contact = Hubspot::Contact.create("email@example.com")
|
186
|
+
contact_list_params = { name: "my-contacts-list" }
|
187
|
+
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
188
|
+
|
189
|
+
result = contact_list.add([contact])
|
190
|
+
|
191
|
+
expect(result).to be true
|
192
|
+
|
193
|
+
contact.delete
|
194
|
+
contact_list.destroy!
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when the contact already exists in the contact list" do
|
199
|
+
it "returns false" do
|
200
|
+
VCR.use_cassette("contact_lists/add_existing_contact") do
|
201
|
+
contact = Hubspot::Contact.create("email@example.com")
|
202
|
+
|
203
|
+
contact_list_params = { name: "my-contacts-list" }
|
204
|
+
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
205
|
+
contact_list.add([contact])
|
206
|
+
|
207
|
+
result = contact_list.add([contact])
|
208
|
+
|
209
|
+
expect(result).to be false
|
210
|
+
|
211
|
+
contact.delete
|
212
|
+
contact_list.destroy!
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context "for a dynamic list" do
|
219
|
+
it "raises an error as dynamic lists add contacts via on filters" do
|
220
|
+
VCR.use_cassette("contact_list/add_contact_to_dynamic_list") do
|
221
|
+
contact = Hubspot::Contact.create("email@example.com")
|
222
|
+
contact_list_params = {
|
223
|
+
name: "my-contacts-list",
|
224
|
+
dynamic: true,
|
225
|
+
"filters": [
|
226
|
+
[
|
227
|
+
{
|
228
|
+
"operator": "EQ",
|
229
|
+
"property": "email",
|
230
|
+
"type": "string",
|
231
|
+
"value": "@hubspot.com"
|
232
|
+
},
|
233
|
+
],
|
234
|
+
],
|
235
|
+
}
|
236
|
+
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
237
|
+
|
238
|
+
expect {
|
239
|
+
contact_list.add(contact)
|
240
|
+
}.to raise_error(Hubspot::RequestError)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#remove' do
|
247
|
+
cassette "remove_contacts_from_lists"
|
248
|
+
|
249
|
+
context 'static list' do
|
250
|
+
it 'returns true if removes all contacts in batch mode' do
|
251
|
+
contacts = static_list.contacts(count: 2)
|
252
|
+
expect(static_list.remove([contacts.first, contacts.last])).to be true
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'returns false if the contact cannot be removed' do
|
256
|
+
contact_not_present_in_list = Hubspot::Contact.new(example_contact_hash)
|
257
|
+
expect(static_list.remove(contact_not_present_in_list)).to be false
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'dynamic list' do
|
262
|
+
it 'raises error if try to remove a contact from a dynamic list' do
|
263
|
+
contact = dynamic_list.contacts(recent: true, count: 1).first
|
264
|
+
expect { dynamic_list.remove(contact) }.to raise_error(Hubspot::RequestError)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#update!' do
|
270
|
+
cassette "contact_list_update"
|
271
|
+
|
272
|
+
let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
273
|
+
let(:params) { { name: "update list name" } }
|
274
|
+
subject { contact_list.update!(params) }
|
275
|
+
|
276
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
277
|
+
its(:name){ should == "update list name" }
|
278
|
+
end
|
279
|
+
|
280
|
+
describe '#destroy!' do
|
281
|
+
cassette "contact_list_destroy"
|
282
|
+
|
283
|
+
let(:contact_list) { Hubspot::ContactList.create!({ name: "newcontactlist_#{Time.now.to_i}"}) }
|
284
|
+
subject{ contact_list.destroy! }
|
285
|
+
it { should be true }
|
286
|
+
|
287
|
+
it "should be destroyed" do
|
288
|
+
subject
|
289
|
+
expect(contact_list).to be_destroyed
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
describe '#refresh' do
|
294
|
+
cassette "contact_list_refresh"
|
295
|
+
|
296
|
+
let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
297
|
+
subject { contact_list.refresh }
|
298
|
+
|
299
|
+
it { should be true }
|
300
|
+
end
|
301
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
describe Hubspot::ContactProperties do
|
2
|
+
describe '.add_default_parameters' do
|
3
|
+
let(:opts) { {} }
|
4
|
+
subject { Hubspot::ContactProperties.add_default_parameters(opts) }
|
5
|
+
context 'default parameters' do
|
6
|
+
context 'without property parameter' do
|
7
|
+
its([:property]) { should == 'email' }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'with property parameter' do
|
11
|
+
let(:opts) { {property: 'firstname' } }
|
12
|
+
its([:property]) { should == 'firstname'}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:example_groups) do
|
18
|
+
VCR.use_cassette('contact_properties/groups_example') do
|
19
|
+
HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:example_properties) do
|
24
|
+
VCR.use_cassette('contact_properties/properties_example') do
|
25
|
+
HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before { Hubspot.configure(hapikey: 'demo') }
|
30
|
+
|
31
|
+
describe 'Properties' do
|
32
|
+
describe '.all' do
|
33
|
+
context 'with no filter' do
|
34
|
+
cassette 'contact_properties/all_properties'
|
35
|
+
|
36
|
+
it 'should return all properties' do
|
37
|
+
expect(Hubspot::ContactProperties.all).to eql(example_properties)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
42
|
+
|
43
|
+
context 'with included groups' do
|
44
|
+
cassette 'contact_properties/properties_in_groups'
|
45
|
+
|
46
|
+
it 'should return properties for the specified group[s]' do
|
47
|
+
response = Hubspot::ContactProperties.all({}, { include: groups })
|
48
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be true }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with excluded groups' do
|
53
|
+
cassette 'contact_properties/properties_not_in_groups'
|
54
|
+
|
55
|
+
it 'should return properties for the non-specified group[s]' do
|
56
|
+
response = Hubspot::ContactProperties.all({}, { exclude: groups })
|
57
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be false }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:params) { {
|
63
|
+
'name' => 'my_new_property',
|
64
|
+
'label' => 'This is my new property',
|
65
|
+
'description' => 'What kind of x would you like?',
|
66
|
+
'groupName' => 'contactinformation',
|
67
|
+
'type' => 'string',
|
68
|
+
'fieldType' => 'text',
|
69
|
+
'hidden' => false,
|
70
|
+
'options' => [],
|
71
|
+
'deleted' => false,
|
72
|
+
'displayOrder' => 0,
|
73
|
+
'formField' => true,
|
74
|
+
'readOnlyValue' => false,
|
75
|
+
'readOnlyDefinition' => false,
|
76
|
+
'mutableDefinitionNotDeletable' => false,
|
77
|
+
'calculated' => false,
|
78
|
+
'externalOptions' => false,
|
79
|
+
'displayMode' => 'current_value'
|
80
|
+
} }
|
81
|
+
let(:valid_params) { params.select { |k, _| Hubspot::ContactProperties::PROPERTY_SPECS[:field_names].include?(k) } }
|
82
|
+
|
83
|
+
describe '.create!' do
|
84
|
+
context 'with no valid parameters' do
|
85
|
+
it 'should return nil' do
|
86
|
+
expect(Hubspot::ContactProperties.create!({})).to be(nil)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with all valid parameters' do
|
91
|
+
cassette 'contact_properties/create_property'
|
92
|
+
|
93
|
+
it 'should return the valid parameters' do
|
94
|
+
response = Hubspot::ContactProperties.create!(params)
|
95
|
+
valid_params.each { |k, v| expect(response[k]).to eq(v) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '.update!' do
|
101
|
+
context 'with no valid parameters' do
|
102
|
+
|
103
|
+
it 'should return nil ' do
|
104
|
+
expect(Hubspot::ContactProperties.update!(params['name'], {})).to be(nil)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'with mixed parameters' do
|
109
|
+
cassette 'contact_properties/update_property'
|
110
|
+
|
111
|
+
it 'should return the valid parameters' do
|
112
|
+
params['description'] = 'What is their favorite flavor?'
|
113
|
+
valid_params['description'] = params['description']
|
114
|
+
|
115
|
+
response = Hubspot::ContactProperties.update!(params['name'], params)
|
116
|
+
valid_params.each { |k, v| expect(response[k]).to eq(v) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '.delete!' do
|
122
|
+
let(:name) { params['name'] }
|
123
|
+
|
124
|
+
context 'with existing property' do
|
125
|
+
cassette 'contact_properties/delete_property'
|
126
|
+
|
127
|
+
it 'should return nil' do
|
128
|
+
expect(Hubspot::ContactProperties.delete!(name)).to eq(nil)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with non-existent property' do
|
133
|
+
cassette 'contact_properties/delete_non_property'
|
134
|
+
|
135
|
+
it 'should raise an error' do
|
136
|
+
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::RequestError)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'Groups' do
|
143
|
+
describe '.groups' do
|
144
|
+
context 'with no filter' do
|
145
|
+
cassette 'contact_properties/all_groups'
|
146
|
+
|
147
|
+
it 'should return all groups' do
|
148
|
+
expect(Hubspot::ContactProperties.groups).to eql(example_groups)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
153
|
+
|
154
|
+
context 'with included groups' do
|
155
|
+
cassette 'contact_properties/groups_included'
|
156
|
+
|
157
|
+
it 'should return the specified groups' do
|
158
|
+
response = Hubspot::ContactProperties.groups({}, { include: groups })
|
159
|
+
response.each { |p| expect(groups.include?(p['name'])).to be true }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'with excluded groups' do
|
164
|
+
cassette 'contact_properties/groups_not_excluded'
|
165
|
+
|
166
|
+
it 'should return groups that were not excluded' do
|
167
|
+
response = Hubspot::ContactProperties.groups({}, { exclude: groups })
|
168
|
+
response.each { |p| expect(groups.include?(p['name'])).to be false }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
let(:params) { { 'name' => 'ff_group1', 'displayName' => 'Test Group One', 'displayOrder' => 100, 'badParam' => 99 } }
|
174
|
+
|
175
|
+
describe '.create_group!' do
|
176
|
+
context 'with no valid parameters' do
|
177
|
+
it 'should return nil' do
|
178
|
+
expect(Hubspot::ContactProperties.create_group!({})).to be(nil)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'with mixed parameters' do
|
183
|
+
cassette 'contact_properties/create_group'
|
184
|
+
|
185
|
+
it 'should return the valid parameters' do
|
186
|
+
response = Hubspot::ContactProperties.create_group!(params)
|
187
|
+
expect(Hubspot::ContactProperties.same?(response, params)).to be true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'with some valid parameters' do
|
192
|
+
cassette 'contact_properties/create_group_some_params'
|
193
|
+
|
194
|
+
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
195
|
+
|
196
|
+
it 'should return the valid parameters' do
|
197
|
+
params['name'] = 'ff_group234'
|
198
|
+
response = Hubspot::ContactProperties.create_group!(sub_params)
|
199
|
+
expect(Hubspot::ContactProperties.same?(response, sub_params)).to be true
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '.update_group!' do
|
205
|
+
context 'with no valid parameters' do
|
206
|
+
|
207
|
+
it 'should return nil ' do
|
208
|
+
expect(Hubspot::ContactProperties.update_group!(params['name'], {})).to be(nil)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'with mixed parameters' do
|
213
|
+
cassette 'contact_properties/update_group'
|
214
|
+
|
215
|
+
it 'should return the valid parameters' do
|
216
|
+
params['displayName'] = 'Test Group OneA'
|
217
|
+
|
218
|
+
response = Hubspot::ContactProperties.update_group!(params['name'], params)
|
219
|
+
expect(Hubspot::ContactProperties.same?(response, params)).to be true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
describe '.delete_group!' do
|
226
|
+
let(:name) { params['name'] }
|
227
|
+
|
228
|
+
context 'with existing group' do
|
229
|
+
cassette 'contact_properties/delete_group'
|
230
|
+
|
231
|
+
it 'should return nil' do
|
232
|
+
expect(Hubspot::ContactProperties.delete_group!(name)).to eq(nil)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'with non-existent group' do
|
237
|
+
cassette 'contact_properties/delete_non_group'
|
238
|
+
|
239
|
+
it 'should raise an error' do
|
240
|
+
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::RequestError)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|