diff --git a/lib/hubspot/deal.rb b/lib/hubspot/deal.rb index 445b2f70..989920bc 100644 --- a/lib/hubspot/deal.rb +++ b/lib/hubspot/deal.rb @@ -39,6 +39,28 @@ def create!(portal_id, company_ids, vids, params={}) new(response) end + # Updates the properties of a deal + # {http://developers.hubspot.com/docs/methods/deals/update_deal} + # @param deal_id [Integer] hubspot deal_id + # @param params [Hash] hash of properties to update + # @return [boolean] success + def update(id, properties = {}) + update!(id, properties) + rescue Hubspot::RequestError => e + false + end + + # Updates the properties of a deal + # {http://developers.hubspot.com/docs/methods/deals/update_deal} + # @param deal_id [Integer] hubspot deal_id + # @param params [Hash] hash of properties to update + # @return [Hubspot::Deal] Deal record + def update!(id, properties = {}) + request = { properties: Hubspot::Utils.hash_to_properties(properties.stringify_keys, key_name: 'name') } + response = Hubspot::Connection.put_json(UPDATE_DEAL_PATH, params: { deal_id: id, no_parse: true }, body: request) + response.success? + end + # Associate a deal with a contact or company # {http://developers.hubspot.com/docs/methods/deals/associate_deal} # Usage @@ -132,10 +154,11 @@ def [](property) # @param params [Hash] hash of properties to update # @return [Hubspot::Deal] self def update!(params) - query = {"properties" => Hubspot::Utils.hash_to_properties(params.stringify_keys!, key_name: 'name')} + query = { 'properties' => Hubspot::Utils.hash_to_properties(params.stringify_keys!, key_name: 'name') } Hubspot::Connection.put_json(UPDATE_DEAL_PATH, params: { deal_id: deal_id }, body: query) @properties.merge!(params) self end + alias_method :update, :update! end end diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_existing_resource_updates.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_existing_resource_updates.yml new file mode 100644 index 00000000..785c612e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_existing_resource_updates.yml @@ -0,0 +1,187 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo + body: + encoding: UTF-8 + string: '{"portalId":62515,"associations":{"associatedCompanyIds":[8954037],"associatedVids":[27136]},"properties":[{"name":"amount","value":"30"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:18:58 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:18:58 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249607' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '99' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885c7b84eb7db-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152775540,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"associationCreateFailures":[{"association":{"fromObjectId":1152775540,"toObjectId":8954037,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":5,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"COMPANY=8954037 + is not valid"},{"association":{"fromObjectId":1152775540,"toObjectId":27136,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":3,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"CONTACT=27136 + is not valid"}],"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226338621","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226338621","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226338621","timestamp":1573226338621,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152775540","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152775540","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226338621","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:18:58 GMT +- request: + method: put + uri: https://api.hubapi.com/deals/v1/deal/1152775540?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"dealname","value":"super deal"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:18:59 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:18:58 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249606' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '98' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885caac2f68f4-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152775540,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"dealname":{"value":"super + deal","timestamp":1573226339087,"source":"API","sourceId":null,"versions":[{"name":"dealname","value":"super + deal","timestamp":1573226339087,"source":"API","sourceVid":[]}]},"amount":{"value":"30","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226338621","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"amount_in_home_currency":{"value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_closed_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226339087","timestamp":1573226339087,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226339087","timestamp":1573226339087,"source":"CALCULATED","sourceVid":[]},{"name":"hs_lastmodifieddate","value":"1573226338621","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226338621","timestamp":1573226338621,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152775540","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152775540","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:18:59 GMT +- request: + method: get + uri: https://api.hubapi.com/deals/v1/deal/1152775540?hapikey=demo + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:22:45 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:22:45 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249587' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '99' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 53288b542dccb7ab-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152775540,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"dealname":{"value":"super + deal","timestamp":1573226339087,"source":"API","sourceId":null,"versions":[{"name":"dealname","value":"super + deal","timestamp":1573226339087,"source":"API","sourceVid":[]}]},"amount":{"value":"30","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"num_associated_contacts":{"value":"0","timestamp":1573226339407,"source":"CALCULATED","sourceId":"RollupProperties","versions":[{"name":"num_associated_contacts","value":"0","timestamp":1573226339407,"sourceId":"RollupProperties","source":"CALCULATED","sourceVid":[]}]},"createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226338621","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"amount_in_home_currency":{"value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_closed_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226339552","timestamp":1573226339552,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226339552","timestamp":1573226339552,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226338621","timestamp":1573226338621,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226338621","timestamp":1573226338621,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152775540","timestamp":1573226338621,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152775540","timestamp":1573226338621,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226338621,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:22:46 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_.yml new file mode 100644 index 00000000..aab9f27b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_.yml @@ -0,0 +1,66 @@ +--- +http_interactions: +- request: + method: put + uri: https://api.hubapi.com/deals/v1/deal/0?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"dealname","value":"super deal"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 08 Nov 2019 15:18:59 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '263' + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:18:59 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Notfound: + - 'true' + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249605' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '97' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885cd1c83b7cf-CDG + body: + encoding: UTF-8 + string: '{"status":"error","message":"No deal found for dealId=0 portalId=62515","correlationId":"f8a1c167-ffc4-4c7d-a868-82a7ee43b347","errors":[{"message":"This + deal 0 does not exist."}],"category":"OBJECT_NOT_FOUND","requestId":"d8e67bd2-e41d-4e08-b6f7-91747c037ab8"}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:18:59 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_fails_with_an_error.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_fails_with_an_error.yml new file mode 100644 index 00000000..3af9e637 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_an_invalid_resource_fails_with_an_error.yml @@ -0,0 +1,66 @@ +--- +http_interactions: +- request: + method: put + uri: https://api.hubapi.com/deals/v1/deal/0?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"dealname","value":"super deal"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 08 Nov 2019 15:18:59 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '263' + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:18:59 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Notfound: + - 'true' + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249604' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '96' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885ce4f7fcdd7-CDG + body: + encoding: UTF-8 + string: '{"status":"error","message":"No deal found for dealId=0 portalId=62515","correlationId":"ea967775-f24d-4c01-9a17-4e5b8709c90b","errors":[{"message":"This + deal 0 does not exist."}],"category":"OBJECT_NOT_FOUND","requestId":"6a572d20-8314-4aa5-8496-49e7594bd1d1"}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:18:59 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_overlapping_changes_merges_and_updates_the_properties.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_overlapping_changes_merges_and_updates_the_properties.yml new file mode 100644 index 00000000..d4378eba --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_with_overlapping_changes_merges_and_updates_the_properties.yml @@ -0,0 +1,127 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo + body: + encoding: UTF-8 + string: '{"portalId":62515,"associations":{"associatedCompanyIds":[8954037],"associatedVids":[27136]},"properties":[{"name":"amount","value":"30"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:19:02 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:19:01 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249599' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '91' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885dc7e5ab78d-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152692179,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"associationCreateFailures":[{"association":{"fromObjectId":1152692179,"toObjectId":8954037,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":5,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"COMPANY=8954037 + is not valid"},{"association":{"fromObjectId":1152692179,"toObjectId":27136,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":3,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"CONTACT=27136 + is not valid"}],"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226341920","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226341920","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226341920","timestamp":1573226341920,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226341920","timestamp":1573226341920,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152692179","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152692179","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"createdate":{"value":"1573226341920","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226341920","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:19:02 GMT +- request: + method: put + uri: https://api.hubapi.com/deals/v1/deal/1152692179?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"dealname","value":"super deal"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:19:02 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:19:02 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249598' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '90' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885df0f04692a-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152692179,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"dealname":{"value":"super + deal","timestamp":1573226342377,"source":"API","sourceId":null,"versions":[{"name":"dealname","value":"super + deal","timestamp":1573226342377,"source":"API","sourceVid":[]}]},"amount":{"value":"30","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"createdate":{"value":"1573226341920","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226341920","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"amount_in_home_currency":{"value":"30","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_closed_amount":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226342377","timestamp":1573226342377,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226342377","timestamp":1573226342377,"source":"CALCULATED","sourceVid":[]},{"name":"hs_lastmodifieddate","value":"1573226341920","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226341920","timestamp":1573226341920,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226341920","timestamp":1573226341920,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152692179","timestamp":1573226341920,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152692179","timestamp":1573226341920,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226341920,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:19:02 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_without_overlapping_changes_updates_the_properties.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_without_overlapping_changes_updates_the_properties.yml new file mode 100644 index 00000000..4f697bf6 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_update_without_overlapping_changes_updates_the_properties.yml @@ -0,0 +1,127 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo + body: + encoding: UTF-8 + string: '{"portalId":62515,"associations":{"associatedCompanyIds":[8954037],"associatedVids":[27136]},"properties":[{"name":"amount","value":"30"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:19:00 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:18:59 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249603' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '95' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885d009416924-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152692173,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"associationCreateFailures":[{"association":{"fromObjectId":1152692173,"toObjectId":27136,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":3,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"CONTACT=27136 + is not valid"},{"association":{"fromObjectId":1152692173,"toObjectId":8954037,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":5,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"COMPANY=8954037 + is not valid"}],"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226339932","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226339932","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226339932","timestamp":1573226339932,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226339932","timestamp":1573226339932,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152692173","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152692173","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"createdate":{"value":"1573226339932","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226339932","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:19:00 GMT +- request: + method: put + uri: https://api.hubapi.com/deals/v1/deal/1152692173?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"dealname","value":"super deal"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 08 Nov 2019 15:19:01 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 07-Nov-20 + 15:19:00 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249602' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '94' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 532885d33934b7b1-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1152692173,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"dealname":{"value":"super + deal","timestamp":1573226340886,"source":"API","sourceId":null,"versions":[{"name":"dealname","value":"super + deal","timestamp":1573226340886,"source":"API","sourceVid":[]}]},"amount":{"value":"30","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"num_associated_contacts":{"value":"0","timestamp":1573226340383,"source":"CALCULATED","sourceId":"RollupProperties","versions":[{"name":"num_associated_contacts","value":"0","timestamp":1573226340383,"sourceId":"RollupProperties","source":"CALCULATED","sourceVid":[]}]},"createdate":{"value":"1573226339932","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1573226339932","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"amount_in_home_currency":{"value":"30","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_closed_amount":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1573226340886","timestamp":1573226340886,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1573226340886","timestamp":1573226340886,"source":"CALCULATED","sourceVid":[]},{"name":"hs_lastmodifieddate","value":"1573226340556","timestamp":1573226340556,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1573226339932","timestamp":1573226339932,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1573226339932","timestamp":1573226339932,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1152692173","timestamp":1573226339932,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1152692173","timestamp":1573226339932,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1573226339932,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Fri, 08 Nov 2019 15:19:01 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/lib/hubspot/deal_spec.rb b/spec/lib/hubspot/deal_spec.rb index eb0ff86a..22045c93 100644 --- a/spec/lib/hubspot/deal_spec.rb +++ b/spec/lib/hubspot/deal_spec.rb @@ -3,6 +3,7 @@ let(:company_id) { 8954037 } let(:vid) { 27136 } let(:amount) { '30' } + let(:deal) { Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount}) } let(:example_deal_hash) do VCR.use_cassette("deal_example") do @@ -28,9 +29,87 @@ its(:vids) { should eql [vid]} end + describe '.update' do + let(:changed_properties) { { dealname: 'super deal' } } + + context 'with an existing resource' do + cassette + subject { described_class.update(deal.deal_id, changed_properties) } + + it 'updates' do + expect(subject).to be_truthy + find_deal = Hubspot::Deal.find(deal.deal_id) + expect(find_deal['dealname']).to eq 'super deal' + end + end + + context 'with an invalid resource' do + cassette + subject { described_class.update(0, changed_properties) } + + it { is_expected.to be false } + end + end + + describe '.update!' do + let(:changed_properties) { { dealname: 'super deal' } } + + context 'with an existing resource' do + cassette + subject { described_class.update!(deal.deal_id, changed_properties) } + + it 'updates' do + expect(subject).to be_truthy + find_deal = Hubspot::Deal.find(deal.deal_id) + expect(find_deal['dealname']).to eq 'super deal' + end + end + + context 'with an invalid resource' do + cassette + subject { described_class.update!(0, changed_properties) } + + it 'fails with an error' do + expect { subject }.to raise_error Hubspot::RequestError + end + end + end + + describe '#update' do + let(:changed_properties) { { dealname: 'super deal' }.stringify_keys } + + context 'without overlapping changes' do + cassette + subject { deal.update(changed_properties) } + + it 'updates the properties' do + expect(subject).to be_truthy + changed_properties.each do |property, value| + expect(deal[property]).to eq value + end + end + end + + context 'with overlapping changes' do + cassette + subject { deal.update(changed_properties) } + let(:overlapping_properties) { { dealname: 'old deal', amount: 6 }.stringify_keys } + + before(:each) do + overlapping_properties.each { |property, value| deal.properties[property] = value } + end + + it 'merges and updates the properties' do + expect(subject).to be_truthy + overlapping_properties.merge(changed_properties).each do |property, value| + expect(deal[property]).to eq value + end + end + end + end + describe ".find" do cassette "deal_find" - let(:deal) {Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount})} it 'must find by the deal id' do find_deal = Hubspot::Deal.find(deal.deal_id) @@ -42,7 +121,7 @@ describe '.find_by_company' do cassette 'deal_find_by_company' let(:company) { Hubspot::Company.create(name: 'Test Company') } - let(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [vid], { amount: amount }) } + let(:company_id) { company.id } it 'returns company deals' do deals = Hubspot::Deal.find_by_company(company) @@ -85,8 +164,6 @@ describe "#destroy!" do it "should remove from hubspot" do VCR.use_cassette("destroy_deal") do - deal = Hubspot::Deal.create!(portal_id, [company_id], [vid], {amount: amount}) - result = deal.destroy! assert_requested :delete, hubspot_api_url("/deals/v1/deal/#{deal.deal_id}?hapikey=demo") diff --git a/spec/shared_examples/updateable_resource.rb b/spec/shared_examples/updateable_resource.rb index 5bd1a006..cf1bea8f 100644 --- a/spec/shared_examples/updateable_resource.rb +++ b/spec/shared_examples/updateable_resource.rb @@ -84,4 +84,4 @@ end end end -end \ No newline at end of file +end