hubspot-ruby 0.1.8 → 0.2.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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -22
  3. data/Gemfile.lock +14 -11
  4. data/LICENSE.txt +0 -2
  5. data/README.md +8 -6
  6. data/RELEASING.md +4 -5
  7. data/Rakefile +2 -17
  8. data/hubspot-ruby.gemspec +20 -157
  9. data/lib/hubspot-ruby.rb +10 -0
  10. data/lib/hubspot/blog.rb +1 -2
  11. data/lib/hubspot/company.rb +149 -0
  12. data/lib/hubspot/company_properties.rb +59 -0
  13. data/lib/hubspot/config.rb +10 -4
  14. data/lib/hubspot/connection.rb +12 -4
  15. data/lib/hubspot/contact.rb +52 -31
  16. data/lib/hubspot/contact_list.rb +16 -16
  17. data/lib/hubspot/contact_properties.rb +53 -6
  18. data/lib/hubspot/deal.rb +2 -2
  19. data/lib/hubspot/deal_pipeline.rb +43 -0
  20. data/lib/hubspot/deal_properties.rb +59 -0
  21. data/lib/hubspot/engagement.rb +133 -0
  22. data/lib/hubspot/exceptions.rb +1 -1
  23. data/lib/hubspot/form.rb +20 -20
  24. data/lib/hubspot/owner.rb +49 -0
  25. data/lib/hubspot/properties.rb +119 -0
  26. data/lib/hubspot/railtie.rb +10 -0
  27. data/lib/hubspot/topic.rb +2 -2
  28. data/lib/hubspot/utils.rb +106 -3
  29. data/spec/lib/hubspot/blog_spec.rb +2 -0
  30. data/spec/lib/hubspot/company_properties_spec.rb +239 -0
  31. data/spec/lib/hubspot/company_spec.rb +190 -0
  32. data/spec/lib/hubspot/config_spec.rb +1 -1
  33. data/spec/lib/hubspot/connection_spec.rb +33 -27
  34. data/spec/lib/hubspot/contact_list_spec.rb +61 -61
  35. data/spec/lib/hubspot/contact_properties_spec.rb +234 -3
  36. data/spec/lib/hubspot/contact_spec.rb +140 -71
  37. data/spec/lib/hubspot/deal_properties_spec.rb +254 -0
  38. data/spec/lib/hubspot/engagement_spec.rb +87 -0
  39. data/spec/lib/hubspot/form_spec.rb +72 -60
  40. data/spec/lib/hubspot/owner_spec.rb +56 -0
  41. data/spec/lib/hubspot/properties_spec.rb +45 -0
  42. data/spec/lib/hubspot/topic_spec.rb +0 -1
  43. data/spec/lib/hubspot/utils_spec.rb +113 -15
  44. data/spec/lib/tasks/properties_spec.rb +90 -0
  45. data/spec/live/companies_integration_spec.rb +23 -0
  46. data/spec/live/companies_properties_integration_spec.rb +120 -0
  47. data/spec/live/contacts_integration_spec.rb +1 -1
  48. data/spec/live/contacts_properties_integration_spec.rb +120 -0
  49. data/spec/live/deal_properties_integration_spec.rb +123 -0
  50. data/spec/live/deals_integration_spec.rb +1 -1
  51. data/spec/support/cassette_helper.rb +1 -1
  52. data/spec/support/tests_helper.rb +3 -3
  53. metadata +39 -78
  54. data/.document +0 -5
  55. data/lib/hubspot/version.rb +0 -9
  56. data/spec/fixtures/vcr_cassettes/add_contacts_to_lists.yml +0 -281
  57. data/spec/fixtures/vcr_cassettes/blog_list.yml +0 -180
  58. data/spec/fixtures/vcr_cassettes/blog_posts.yml +0 -107
  59. data/spec/fixtures/vcr_cassettes/blog_posts_list.yml +0 -6463
  60. data/spec/fixtures/vcr_cassettes/contact_create.yml +0 -64
  61. data/spec/fixtures/vcr_cassettes/contact_create_existing_email.yml +0 -62
  62. data/spec/fixtures/vcr_cassettes/contact_create_invalid_email.yml +0 -63
  63. data/spec/fixtures/vcr_cassettes/contact_create_with_params.yml +0 -64
  64. data/spec/fixtures/vcr_cassettes/contact_destroy.yml +0 -131
  65. data/spec/fixtures/vcr_cassettes/contact_example.yml +0 -32
  66. data/spec/fixtures/vcr_cassettes/contact_find_by_email.yml +0 -59
  67. data/spec/fixtures/vcr_cassettes/contact_find_by_email_batch_mode.yml +0 -509
  68. data/spec/fixtures/vcr_cassettes/contact_find_by_id.yml +0 -59
  69. data/spec/fixtures/vcr_cassettes/contact_find_by_id_batch_mode.yml +0 -33
  70. data/spec/fixtures/vcr_cassettes/contact_find_by_utk.yml +0 -83
  71. data/spec/fixtures/vcr_cassettes/contact_find_by_utk_batch_mode.yml +0 -33
  72. data/spec/fixtures/vcr_cassettes/contact_list_batch_find.yml +0 -65
  73. data/spec/fixtures/vcr_cassettes/contact_list_destroy.yml +0 -63
  74. data/spec/fixtures/vcr_cassettes/contact_list_example.yml +0 -33
  75. data/spec/fixtures/vcr_cassettes/contact_list_find.yml +0 -96
  76. data/spec/fixtures/vcr_cassettes/contact_list_refresh.yml +0 -33
  77. data/spec/fixtures/vcr_cassettes/contact_list_update.yml +0 -36
  78. data/spec/fixtures/vcr_cassettes/contact_update.yml +0 -66
  79. data/spec/fixtures/vcr_cassettes/contacts_among_list.yml +0 -189
  80. data/spec/fixtures/vcr_cassettes/create_form.yml +0 -39
  81. data/spec/fixtures/vcr_cassettes/create_list.yml +0 -36
  82. data/spec/fixtures/vcr_cassettes/create_list_with_filters.yml +0 -36
  83. data/spec/fixtures/vcr_cassettes/deal_create.yml +0 -61
  84. data/spec/fixtures/vcr_cassettes/deal_example.yml +0 -166
  85. data/spec/fixtures/vcr_cassettes/deal_find.yml +0 -115
  86. data/spec/fixtures/vcr_cassettes/destroy_deal.yml +0 -221
  87. data/spec/fixtures/vcr_cassettes/fail_to_create_form.yml +0 -35
  88. data/spec/fixtures/vcr_cassettes/fail_to_create_list.yml +0 -35
  89. data/spec/fixtures/vcr_cassettes/field_among_form.yml +0 -34
  90. data/spec/fixtures/vcr_cassettes/fields_among_form.yml +0 -35
  91. data/spec/fixtures/vcr_cassettes/find_all_contacts.yml +0 -297
  92. data/spec/fixtures/vcr_cassettes/find_all_dynamic_lists.yml +0 -104
  93. data/spec/fixtures/vcr_cassettes/find_all_forms.yml +0 -15378
  94. data/spec/fixtures/vcr_cassettes/find_all_lists.yml +0 -138
  95. data/spec/fixtures/vcr_cassettes/find_all_recent_contacts.yml +0 -33
  96. data/spec/fixtures/vcr_cassettes/find_all_recent_updated_deals.yml +0 -130
  97. data/spec/fixtures/vcr_cassettes/find_all_stastic_lists.yml +0 -21876
  98. data/spec/fixtures/vcr_cassettes/form_destroy.yml +0 -64
  99. data/spec/fixtures/vcr_cassettes/form_example.yml +0 -39
  100. data/spec/fixtures/vcr_cassettes/form_find.yml +0 -69
  101. data/spec/fixtures/vcr_cassettes/form_post.yml +0 -31
  102. data/spec/fixtures/vcr_cassettes/form_submit_data.yml +0 -130
  103. data/spec/fixtures/vcr_cassettes/form_update.yml +0 -77
  104. data/spec/fixtures/vcr_cassettes/one_month_blog_posts_filter_state.yml +0 -19127
  105. data/spec/fixtures/vcr_cassettes/one_month_blog_posts_list.yml +0 -34963
  106. data/spec/fixtures/vcr_cassettes/remove_contacts_from_lists.yml +0 -315
  107. data/spec/fixtures/vcr_cassettes/topic_list.yml +0 -48
  108. data/spec/fixtures/vcr_cassettes/topics_list.yml +0 -86
@@ -0,0 +1,87 @@
1
+ describe Hubspot::Engagement do
2
+ let(:example_engagement_hash) do
3
+ VCR.use_cassette("engagement_example") do
4
+ HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/51484873?hapikey=demo").parsed_response
5
+ end
6
+ end
7
+ let(:example_associated_engagement_hash) do
8
+ VCR.use_cassette("engagement_associated_example") do
9
+ HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/58699206?hapikey=demo").parsed_response
10
+ end
11
+ end
12
+
13
+ # http://developers.hubspot.com/docs/methods/contacts/get_contact
14
+ before{ Hubspot.configure(hapikey: "demo") }
15
+
16
+ describe "#initialize" do
17
+ subject{ Hubspot::Engagement.new(example_engagement_hash) }
18
+ it { should be_an_instance_of Hubspot::Engagement }
19
+ its (:id) { should == 51484873 }
20
+ end
21
+
22
+ describe ".create!" do
23
+ cassette "engagement_create"
24
+ body = "Test note"
25
+ subject { Hubspot::EngagementNote.create!(nil, body) }
26
+ its(:id) { should_not be_nil }
27
+ its(:body) { should eql body }
28
+ end
29
+
30
+ describe ".find" do
31
+ cassette "engagement_find"
32
+ let(:engagement) {Hubspot::EngagementNote.new(example_engagement_hash)}
33
+
34
+ it 'must find by the engagement id' do
35
+ find_engagement = Hubspot::EngagementNote.find(engagement.id)
36
+ find_engagement.id.should eql engagement.id
37
+ find_engagement.body.should eql engagement.body
38
+ end
39
+ end
40
+
41
+ describe ".find_by_company" do
42
+ cassette "engagement_find_by_country"
43
+ let(:engagement) {Hubspot::EngagementNote.new(example_associated_engagement_hash)}
44
+
45
+ it 'must find by company id' do
46
+ find_engagements = Hubspot::EngagementNote.find_by_company(engagement.associations["companyIds"].first)
47
+ find_engagements.should_not be_nil
48
+ find_engagements.any?{|engagement| engagement.id == engagement.id and engagement.body == engagement.body}.should be_true
49
+ end
50
+ end
51
+
52
+ describe ".find_by_contact" do
53
+ cassette "engagement_find_by_contact"
54
+ let(:engagement) {Hubspot::EngagementNote.new(example_associated_engagement_hash)}
55
+
56
+ it 'must find by contact id' do
57
+ find_engagements = Hubspot::EngagementNote.find_by_contact(engagement.associations["contactIds"].first)
58
+ find_engagements.should_not be_nil
59
+ find_engagements.any?{|engagement| engagement.id == engagement.id and engagement.body == engagement.body}.should be_true
60
+ end
61
+ end
62
+
63
+ describe ".find_by_association" do
64
+ cassette "engagement_find_by_association"
65
+
66
+ it 'must raise for fake association type' do
67
+ expect {
68
+ Hubspot::EngagementNote.find_by_association(1, 'FAKE_TYPE')
69
+ }.to raise_error
70
+ end
71
+ end
72
+
73
+ describe '#destroy!' do
74
+ cassette 'engagement_destroy'
75
+
76
+ let(:engagement) {Hubspot::EngagementNote.create!(nil, 'test note') }
77
+
78
+ it 'should remove from hubspot' do
79
+ expect(Hubspot::Engagement.find(engagement.id)).to_not be_nil
80
+
81
+ expect(engagement.destroy!).to be_true
82
+ expect(engagement.destroyed?).to be_true
83
+
84
+ expect(Hubspot::Engagement.find(engagement.id)).to be_nil
85
+ end
86
+ end
87
+ end
@@ -1,77 +1,77 @@
1
1
  describe Hubspot::Form do
2
+ let(:guid) { '78c2891f-ebdd-44c0-bd94-15c012bbbfbf' } # '561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0'
2
3
  let(:example_form_hash) do
3
- VCR.use_cassette("form_example", record: :none) do
4
- HTTParty.get("https://api.hubapi.com/contacts/v1/forms/561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0/?hapikey=demo").parsed_response
4
+ VCR.use_cassette('form_example', record: :none) do
5
+ HTTParty.get("https://api.hubapi.com#{Hubspot::Form::FORMS_PATH}/#{guid}/?hapikey=demo").parsed_response
5
6
  end
6
7
  end
7
8
 
8
9
  describe '#initialize' do
9
10
  subject { Hubspot::Form.new(example_form_hash) }
10
-
11
+
11
12
  it { should be_an_instance_of Hubspot::Form }
12
13
  its(:guid) { should be_a(String) }
13
14
  its(:properties) { should be_a(Hash) }
14
- end
15
+ end
15
16
 
16
- before { Hubspot.configure(hapikey: "demo", portal_id: '62515') }
17
+ before { Hubspot.configure(hapikey: 'demo', portal_id: '62515') }
17
18
 
18
19
  describe '.all' do
19
20
  cassette 'find_all_forms'
20
21
 
21
22
  it 'returns all forms' do
22
23
  forms = Hubspot::Form.all
23
- expect(forms.count).to be > 20
24
+ expect(forms.count).to be > 20
24
25
 
25
- form = forms.first
26
- expect(form).to be_a(Hubspot::Form)
26
+ form = forms.first
27
+ expect(form).to be_a(Hubspot::Form)
27
28
  end
28
29
  end
29
30
 
30
31
  describe '.find' do
31
- cassette "form_find"
32
+ cassette 'form_find'
32
33
  subject { Hubspot::Form.find(guid) }
33
34
 
34
35
  context 'when the form is found' do
35
- let(:guid) { '561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0' }
36
36
  it { should be_an_instance_of Hubspot::Form }
37
37
  its(:fields) { should_not be_empty }
38
38
  end
39
39
 
40
40
  context 'when the form is not found' do
41
- it 'raises an error' do
42
- expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::RequestError)
41
+ it 'raises an error' do
42
+ expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::RequestError)
43
43
  end
44
- end
44
+ end
45
45
  end
46
46
 
47
47
  describe '.create' do
48
- subject{ Hubspot::Form.create!(params) }
49
-
50
- context 'with all required parameters' do
48
+ subject { Hubspot::Form.create!(params) }
49
+
50
+ context 'with all required parameters' do
51
51
  cassette 'create_form'
52
52
 
53
- let(:params) do
54
- {
53
+ let(:params) do
54
+ {
55
55
  name: "Demo Form #{Time.now.to_i}",
56
- action: "",
57
- method: "POST",
58
- cssClass: "hs-form stacked",
59
- redirect: "",
60
- submitText: "Sign Up",
61
- followUpId: "",
62
- leadNurturingCampaignId: "",
63
- notifyRecipients: "",
64
- embeddedCode: ""
56
+ action: '',
57
+ method: 'POST',
58
+ cssClass: 'hs-form stacked',
59
+ redirect: '',
60
+ submitText: 'Sign Up',
61
+ followUpId: '',
62
+ leadNurturingCampaignId: '',
63
+ notifyRecipients: '',
64
+ embeddedCode: ''
65
65
  }
66
66
  end
67
67
  it { should be_an_instance_of Hubspot::Form }
68
68
  its(:guid) { should be_a(String) }
69
- end
70
-
69
+ end
70
+
71
71
  context 'without all required parameters' do
72
72
  cassette 'fail_to_create_form'
73
73
 
74
- it 'raises an error' do
74
+ it 'raises an error' do
75
75
  expect { Hubspot::Form.create!({}) }.to raise_error(Hubspot::RequestError)
76
76
  end
77
77
  end
@@ -88,54 +88,66 @@ describe Hubspot::Form do
88
88
  fields.should_not be_empty
89
89
  end
90
90
 
91
- it 'updates the fields property and returns it' do
91
+ it 'updates the fields property and returns it' do
92
92
  fields = form.fields(bypass_cache: true)
93
93
  fields.should_not be_empty
94
94
  end
95
95
  end
96
96
 
97
- context 'returning an uniq field' do
97
+ context 'returning an uniq field' do
98
98
  cassette 'field_among_form'
99
99
 
100
100
  let(:form) { Hubspot::Form.new(example_form_hash) }
101
-
101
+ let(:field_name) { form.fields.first['name'] }
102
+
102
103
  it 'returns by default the field if present as a property' do
103
- field = form.fields(only: :email)
104
+ field = form.fields(only: field_name)
104
105
  expect(field).to be_a(Hash)
105
- expect(field['name']).to be == 'email'
106
+ expect(field['name']).to be == field_name
106
107
  end
107
108
 
108
- it 'makes an API request if specified' do
109
- field = form.fields(only: :email, bypass_cache: true)
109
+ it 'makes an API request if specified' do
110
+ field = form.fields(only: field_name, bypass_cache: true)
110
111
  expect(field).to be_a(Hash)
111
- expect(field['name']).to be == 'email'
112
+ expect(field['name']).to be == field_name
112
113
  end
113
114
  end
114
115
  end
115
116
 
116
- describe '#submit' do
117
+ describe '#submit' do
117
118
  cassette 'form_submit_data'
118
119
 
119
120
  let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
120
121
 
121
- it 'returns true if the form submission is successfull' do
122
- params = { }
123
- result = form.submit(params)
124
- result.should be true
122
+ context 'with a valid portal id' do
123
+ before do
124
+ Hubspot.configure(hapikey: 'demo', portal_id: '62515')
125
+ end
126
+
127
+ it 'returns true if the form submission is successful' do
128
+ params = {}
129
+ result = form.submit(params)
130
+ result.should be true
131
+ end
125
132
  end
126
133
 
127
- it 'returns false in case of errors' do
128
- Hubspot.configure(hapikey: "demo", portal_id: '62514')
129
- params = { }
130
- result = form.submit(params)
131
- result.should be false
134
+ context 'with an invalid portal id' do
135
+ before do
136
+ Hubspot.configure(hapikey: 'demo', portal_id: 'xxxx')
137
+ end
138
+
139
+ it 'returns false in case of errors' do
140
+ params = { unknown_field: :bogus_value }
141
+ result = form.submit(params)
142
+ result.should be false
143
+ end
132
144
  end
133
145
  end
134
146
 
135
- describe '#update!' do
136
- cassette "form_update"
137
-
138
- new_name = "updated form name 1424709912"
147
+ describe '#update!' do
148
+ cassette 'form_update'
149
+
150
+ new_name = 'updated form name 1424709912'
139
151
  redirect = 'http://hubspot.com'
140
152
 
141
153
  let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
@@ -143,23 +155,23 @@ describe Hubspot::Form do
143
155
  subject { form.update!(params) }
144
156
 
145
157
  it { should be_an_instance_of Hubspot::Form }
146
- it 'updates properties' do
158
+ it 'updates properties' do
147
159
  subject.properties['name'].should be == new_name
148
160
  subject.properties['redirect'].should be == redirect
149
161
  end
150
162
  end
151
163
 
152
- describe '#destroy!' do
153
- cassette "form_destroy"
164
+ describe '#destroy!' do
165
+ cassette 'form_destroy'
154
166
 
155
167
  # NOTE: form previous created via the create! method
156
- let(:form) { Hubspot::Form.find('8291bdd1-0681-4d99-b5f7-76ffffb4f98d') }
157
- subject{ form.destroy! }
168
+ let(:form) { Hubspot::Form.find('beb92950-ca65-4daf-87ae-a42c054e429f') }
169
+ subject { form.destroy! }
158
170
  it { should be_true }
159
-
160
- it "should be destroyed" do
171
+
172
+ it 'should be destroyed' do
161
173
  subject
162
174
  form.destroyed?.should be_true
163
175
  end
164
176
  end
165
- end
177
+ end
@@ -0,0 +1,56 @@
1
+ describe Hubspot::Owner do
2
+ let(:example_owners) do
3
+ VCR.use_cassette('owner_example') do
4
+ HTTParty.get('https://api.hubapi.com/owners/v2/owners?hapikey=demo&portalId=62515').parsed_response
5
+ end
6
+ end
7
+
8
+ before { Hubspot.configure(hapikey: 'demo') }
9
+
10
+ describe '.all' do
11
+ cassette 'owner_all'
12
+
13
+ it 'should find all owners' do
14
+ owners = Hubspot::Owner.all
15
+
16
+ expect(owners.blank?).to be_false
17
+ compare_owners(owners, example_owners)
18
+ end
19
+ end
20
+
21
+ describe '.find_by_email' do
22
+ cassette 'owner_find_by_email'
23
+
24
+ let(:sample) { example_owners.first }
25
+ let(:email) { sample['email'] }
26
+
27
+ it 'should find a user via their email address' do
28
+ owner = Hubspot::Owner.find_by_email(email)
29
+ sample.map do |key, val|
30
+ expect(owner[key]).to eq(val)
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '.find_by_emails' do
36
+ cassette 'owner_find_by_emails'
37
+
38
+ let(:samples) { example_owners[0..[example_owners.count, 3].min] }
39
+ let(:emails) { samples.map { |s| s['email'] } }
40
+
41
+ it 'should find users via their email address' do
42
+ owners = Hubspot::Owner.find_by_emails(emails)
43
+ compare_owners(owners, samples)
44
+ end
45
+ end
46
+ end
47
+
48
+ def compare_owners(owners, examples)
49
+ owners.each do |owner|
50
+ example = examples.detect { |o| o['email'] == owner.email }
51
+ expect(example.blank?).to be_false
52
+ example.each do |key, val|
53
+ expect(owner[key]).to eq(val)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,45 @@
1
+ module Hubspot
2
+ describe Properties do
3
+ let(:params) { { 'name' => 'amount_of_new_money_lined_up',
4
+ 'label' => 'New Money Lined Up (Over $50K or Under $50K)',
5
+ 'description' => '',
6
+ 'groupName' => 'onboarding_questionnaire',
7
+ 'type' => 'enumeration',
8
+ 'fieldType' => 'select',
9
+ 'options' => [{ 'description' => '', 'value' => 'option0', 'readOnly' => false, 'label' => 'Under $50K', 'displayOrder' => 0, 'hidden' => false, 'doubleData' => 0.0 },
10
+ { 'description' => '', 'value' => 'option1', 'readOnly' => false, 'label' => '$50K and above', 'displayOrder' => 1, 'hidden' => false, 'doubleData' => 0.0 },
11
+ { 'description' => nil, 'value' => 'option2', 'readOnly' => nil, 'label' => 'Not applicable', 'displayOrder' => 2, 'hidden' => false, 'doubleData' => nil }],
12
+ 'formField' => true,
13
+ 'displayOrder' => 0,
14
+ 'readOnlyDefinition' => false,
15
+ 'hidden' => false,
16
+ 'mutableDefinitionNotDeletable' => false,
17
+ 'displayMode' => 'current_value',
18
+ 'deleted' => false,
19
+ 'createdUserId' => 2334900,
20
+ 'calculated' => false,
21
+ 'readOnlyValue' => false,
22
+ 'externalOptions' => false,
23
+ 'updatedUserId' => 2225340 } }
24
+ let(:valid_params) { { 'name' => 'amount_of_new_money_lined_up',
25
+ 'groupName' => 'onboarding_questionnaire',
26
+ 'description' => '',
27
+ 'fieldType' => 'select',
28
+ 'formField' => true,
29
+ 'type' => 'enumeration',
30
+ 'displayOrder' => 0,
31
+ 'label' => 'New Money Lined Up (Over $50K or Under $50K)',
32
+ 'options' => [{ 'description' => '', 'value' => 'option0', 'label' => 'Under $50K', 'hidden' => false, 'displayOrder' => 0 },
33
+ { 'description' => '', 'value' => 'option1', 'label' => '$50K and above', 'hidden' => false, 'displayOrder' => 1 },
34
+ { 'description' => nil, 'value' => 'option2', 'label' => 'Not applicable', 'hidden' => false, 'displayOrder' => 2 }]
35
+ } }
36
+
37
+ context '.valid_params' do
38
+ it 'should strip out extra keys and their values' do
39
+ result = Hubspot::Properties.valid_params(params)
40
+ expect(Properties.same?(result, valid_params))
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -21,4 +21,3 @@ describe Hubspot::Topic do
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -2,30 +2,128 @@ describe Hubspot::Utils do
2
2
  describe ".properties_to_hash" do
3
3
  let(:properties) do
4
4
  {
5
- "email" => {"value" => "email@address.com"},
6
- "firstname" => {"value" => "Bob"},
7
- "lastname" => {"value" => "Smith"}
5
+ "email" => { "value" => "email@address.com" },
6
+ "firstname" => { "value" => "Bob" },
7
+ "lastname" => { "value" => "Smith" }
8
8
  }
9
9
  end
10
- subject{ Hubspot::Utils.properties_to_hash(properties) }
11
- its(["email"]){ should == "email@address.com" }
12
- its(["firstname"]){ should == "Bob" }
13
- its(["lastname"]){ should == "Smith" }
10
+ subject { Hubspot::Utils.properties_to_hash(properties) }
11
+ its(["email"]) { should == "email@address.com" }
12
+ its(["firstname"]) { should == "Bob" }
13
+ its(["lastname"]) { should == "Smith" }
14
14
  end
15
15
 
16
16
  describe ".hash_to_properties" do
17
17
  let(:hash) do
18
18
  {
19
- "email" => "email@address.com",
19
+ "email" => "email@address.com",
20
20
  "firstname" => "Bob",
21
- "lastname" => "Smith"
21
+ "lastname" => "Smith"
22
22
  }
23
23
  end
24
- subject{ Hubspot::Utils.hash_to_properties(hash) }
25
- it{ should be_an_instance_of Array }
26
- its(:length){ should == 3 }
27
- it{ should include({"property" => "email", "value" => "email@address.com"}) }
28
- it{ should include({"property" => "firstname", "value" => "Bob"}) }
29
- it{ should include({"property" => "lastname", "value" => "Smith"}) }
24
+ subject { Hubspot::Utils.hash_to_properties(hash) }
25
+ it { should be_an_instance_of Array }
26
+ its(:length) { should == 3 }
27
+ it { should include({ "property" => "email", "value" => "email@address.com" }) }
28
+ it { should include({ "property" => "firstname", "value" => "Bob" }) }
29
+ it { should include({ "property" => "lastname", "value" => "Smith" }) }
30
+ end
31
+
32
+ describe '.compare_property_lists for ContactProperties' do
33
+ let(:example_groups) do
34
+ VCR.use_cassette('groups_example', record: :once) do
35
+ HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
36
+ end
37
+ end
38
+
39
+ let(:example_properties) do
40
+ VCR.use_cassette('properties_example', record: :once) do
41
+ HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
42
+ end
43
+ end
44
+
45
+ let(:source) { { 'groups' => example_groups, 'properties' => example_properties } }
46
+ let!(:target) { Marshal.load(Marshal.dump(source)) }
47
+
48
+ context 'with no changes' do
49
+ it 'should report no changes' do
50
+ skip, new_groups, new_props, update_props = Hubspot::Utils.compare_property_lists(Hubspot::ContactProperties, source, target)
51
+ expect(skip.count).to be > 0
52
+ expect(new_groups.count).to be(0)
53
+ expect(new_props.count).to be(0)
54
+ expect(update_props.count).to be(0)
55
+ end
56
+ end
57
+
58
+ context 'with changes' do
59
+ let(:description) { "#{source['properties'][0]['description']}_XXX" }
60
+
61
+ count = 0
62
+
63
+ it 'should report the changes' do
64
+ 10.times do |i|
65
+ if !source['properties'][i]['readOnlyDefinition']
66
+ source['properties'][i]['description'] = description
67
+ source['properties'][i]['createdUserId'] = 2500
68
+ count += 1
69
+ end
70
+ end
71
+
72
+ skip, new_groups, new_props, update_props = Hubspot::Utils.compare_property_lists(Hubspot::ContactProperties, source, target)
73
+ expect(skip.count).to be > 0
74
+ expect(new_groups.count).to be(0)
75
+ expect(new_props.count).to be(0)
76
+ expect(update_props.count).to be(count)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '.compare_property_lists for DealProperties' do
82
+ let(:example_groups) do
83
+ VCR.use_cassette('deal_groups_example', record: :once) do
84
+ HTTParty.get('https://api.hubapi.com/deals/v1/groups?hapikey=demo').parsed_response
85
+ end
86
+ end
87
+
88
+ let(:example_properties) do
89
+ VCR.use_cassette('deal_properties_example', record: :once) do
90
+ HTTParty.get('https://api.hubapi.com/deals/v1/properties?hapikey=demo').parsed_response
91
+ end
92
+ end
93
+
94
+ let(:source) { { 'groups' => example_groups, 'properties' => example_properties } }
95
+ let!(:target) { Marshal.load(Marshal.dump(source)) }
96
+
97
+ context 'with no changes' do
98
+ it 'should report no changes' do
99
+ skip, new_groups, new_props, update_props = Hubspot::Utils.compare_property_lists(Hubspot::DealProperties, source, target)
100
+ expect(skip.count).to be > 0
101
+ expect(new_groups.count).to be(0)
102
+ expect(new_props.count).to be(0)
103
+ expect(update_props.count).to be(0)
104
+ end
105
+ end
106
+
107
+ context 'with changes' do
108
+ let(:description) { "#{source['properties'][0]['description']}_XXX" }
109
+
110
+ count = 0
111
+
112
+ it 'should report the changes' do
113
+ 10.times do |i|
114
+ if !source['properties'][i]['readOnlyDefinition']
115
+ source['properties'][i]['description'] = description
116
+ source['properties'][i]['createdUserId'] = 2500
117
+ count += 1
118
+ end
119
+ end
120
+
121
+ skip, new_groups, new_props, update_props = Hubspot::Utils.compare_property_lists(Hubspot::DealProperties, source, target)
122
+ expect(skip.count).to be > 0
123
+ expect(new_groups.count).to be(0)
124
+ expect(new_props.count).to be(0)
125
+ expect(update_props.count).to be(count)
126
+ end
127
+ end
30
128
  end
31
129
  end