diff --git a/.env.test.example b/.env.test.example new file mode 100644 index 0000000..3670495 --- /dev/null +++ b/.env.test.example @@ -0,0 +1,3 @@ +# Used by VCR-based tests +BC_ACCESS_TOKEN= +BC_STORE_HASH= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0f37aea..5a1e5b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ /tmp/ # Used by dotenv library to load environment variables. -# .env +.env* +!.env*.example # Ignore Byebug command history file. .byebug_history diff --git a/README.md b/README.md index ff75258..9e5ff59 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,18 @@ p attribute.meta.total # 1 - Call the appropriate HTTP verb method passing the endpoint's path (the portion **after** the API's `v3` URL) and parameters 1. If the method's return value should not be an `Array` call `unwrap(result)` before returning +## Testing + +Tests use [VCR](https://github.com/vcr/vcr). If you need to re-record cassettes or create new ones a BigCommerce +account is with API access is required. See `.env.test.example`. + +To re-record certain tests you must import fixture data into your store. See `etc/customers.csv`. These records can be deleted once +the VCR cassettes are recorded and you are done with development. The IDs they create are assumed by the tests which may present +a problem. Open an issue if so. + +Any records that are created by the tests are deleted. Well, a delete is attempted in an `after` block, if something goes wrong with the test +the record(s) may remain in your store. + ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/big_commerce-management_api.gemspec b/big_commerce-management_api.gemspec index 19787ab..5a5d48e 100644 --- a/big_commerce-management_api.gemspec +++ b/big_commerce-management_api.gemspec @@ -27,4 +27,6 @@ Gem::Specification.new do |spec| spec.add_dependency "class2", ">= 0.6.0" spec.add_development_dependency "vcr" + spec.add_development_dependency "webmock" + spec.add_development_dependency "dotenv" end diff --git a/lib/big_commerce/management_api/classes.json b/lib/big_commerce/management_api/classes.json index 41de4be..d1ecd78 100644 --- a/lib/big_commerce/management_api/classes.json +++ b/lib/big_commerce/management_api/classes.json @@ -28,6 +28,7 @@ { "first_name": "string", "last_name": "string", + "company": "string", "address1": "Addr1", "address2": "", "city": "string", diff --git a/lib/big_commerce/management_api/customers.rb b/lib/big_commerce/management_api/customers.rb index 877a250..edb53f4 100644 --- a/lib/big_commerce/management_api/customers.rb +++ b/lib/big_commerce/management_api/customers.rb @@ -80,7 +80,7 @@ def get(options = {}) def upsert(*attributes) attributes.flatten! - PUT(PATH, attributes.map(&:to_h)) + PUT(PATH, attributes) end end @@ -147,6 +147,21 @@ def initialize(*argz) @metafields = Metafields.new(*argz) end + def create(*customers) + customers.flatten! + + POST(PATH, customers.map(&:to_h)) + end + + def delete(*ids) + ids.flatten! + + DELETE( + PATH, + with_in_param({:id => ids}, :id) + ) + end + def get(options = {}) GET( PATH, diff --git a/lib/big_commerce/management_api/endpoint.rb b/lib/big_commerce/management_api/endpoint.rb index acd6cdc..cd02df8 100644 --- a/lib/big_commerce/management_api/endpoint.rb +++ b/lib/big_commerce/management_api/endpoint.rb @@ -30,7 +30,7 @@ def request_id method.tr!("-", "_") define_method(method) do - value = headers[header] + value = @headers[header] # Net::HTTP returns as an array value.is_a?(Array) ? value[0] : value end @@ -51,21 +51,31 @@ def initialize(data, headers) def error_message(data) # - # Looks for a structure like this and picks best message: + # Looks for a structure like one of these and picks best message: # - # {"data"=>[], - # "errors"=> + # A: + # + # {"errors"=> # [{"status"=>409, # "title"=>"Cannot have multiple segments with the same name", # "type"=> # "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes", # "errors"=>{}}] # + # + # B: + # + # {"status"=>422, + # "title"=>"Set customer attribute values failed.", + # "type"=> + # "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes", + # "errors"=>{"0.data"=>"missing attribute value"}} + # + return data unless data.is_a?(Hash) - return data unless data.is_a?(Hash) && data["errors"] + data = data["errors"][0] if data["errors"].is_a?(Array) - data = data["errors"][0] - if data["errors"] && data["errors"].any? + if data["errors"].any? errors = data["errors"].map { |property, message| "#{property}: #{message.chomp(".")}" } errors.join(", ") else @@ -147,14 +157,14 @@ def DELETE(path, data = {}) path = endpoint(path) path << query_string(data) if data && data.any? - request(Net::HTTP::Delete.new(path)) + request(Net::HTTP::Delete.new(path), data) end def GET(path, data = {}) path = endpoint(path) path << query_string(data) if data && data.any? - request(Net::HTTP::Get.new(path)) + request(Net::HTTP::Get.new(path), data) end def POST(path, data = {}) @@ -206,15 +216,12 @@ def query_string(params) value = params[name] if value.is_a?(Array) - value = value.join(",") + params[name] = value.join(",") elsif value.respond_to?(:strftime) - value = value.strftime("%Y-%m-%dT%H:%M:%S%z") + params[name] = value.strftime("%Y-%m-%dT%H:%M:%S%z") end - - params[name] = value end - # TODO: do they want form or URL encoding? sprintf("?%s", URI.encode_www_form(params)) end diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Attribute/_create/_create/creating_a_single_attribute/returns_the_new_attribute.yml b/spec/cassettes/BigCommerce_ManagementAPI_Attribute/_create/_create/creating_a_single_attribute/returns_the_new_attribute.yml new file mode 100644 index 0000000..bdde987 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Attribute/_create/_create/creating_a_single_attribute/returns_the_new_attribute.yml @@ -0,0 +1,87 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.bigcommerce.com/stores//v3/customers/attributes + body: + encoding: UTF-8 + string: '[{"name":"test.attribute.create","type":"string"}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3748' + X-Rate-Limit-Time-Reset-Ms: + - '29999' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - adfe0ca9196b5b3a1eeef4b3a714b7f6 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":9,"name":"test.attribute.create","type":"string","date_created":"2024-10-24T07:19:18Z","date_modified":"2024-10-24T07:19:18Z"}],"meta":{}}' + recorded_at: Thu, 24 Oct 2024 07:19:17 GMT +- request: + method: delete + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=9 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 204 + message: No Content + headers: + Connection: + - keep-alive + X-Rate-Limit-Requests-Left: + - '3747' + X-Rate-Limit-Time-Reset-Ms: + - '29663' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 83945b56fae6f287da0e750111b29a51 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: UTF-8 + string: '' + recorded_at: Thu, 24 Oct 2024 07:19:18 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_AttributeValue/_create/_upsert/creating_a_single_attribute_value/returns_the_new_attribute_value.yml b/spec/cassettes/BigCommerce_ManagementAPI_AttributeValue/_create/_upsert/creating_a_single_attribute_value/returns_the_new_attribute_value.yml new file mode 100644 index 0000000..37d2a2d --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_AttributeValue/_create/_upsert/creating_a_single_attribute_value/returns_the_new_attribute_value.yml @@ -0,0 +1,218 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.bigcommerce.com/stores//v3/customers/attributes + body: + encoding: UTF-8 + string: '[{"name":"test.attribute_values.upsert","type":"string"}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3748' + X-Rate-Limit-Time-Reset-Ms: + - '29999' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - a77668757fe1fafbd7b2a6a4f56cdc52 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":7,"name":"test.attribute_values.upsert","type":"string","date_created":"2024-10-24T04:32:20Z","date_modified":"2024-10-24T04:32:20Z"}],"meta":{}}' + recorded_at: Thu, 24 Oct 2024 04:32:19 GMT +- request: + method: post + uri: https://api.bigcommerce.com/stores//v3/customers + body: + encoding: UTF-8 + string: '[{"email":"test.attributevalues.create@example.com","first_name":"Test","last_name":"User"}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3747' + X-Rate-Limit-Time-Reset-Ms: + - '29765' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - '095016d230b13b8892cc069d2ec0255c' + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":13,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"test.attributevalues.create@example.com","first_name":"Test","last_name":"User","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-24T04:32:20Z","date_modified":"2024-10-24T04:32:20Z","accepts_product_review_abandoned_cart_emails":false,"store_credit_amounts":[{"amount":0}],"origin_channel_id":1,"channel_ids":null}],"meta":{}}' + recorded_at: Thu, 24 Oct 2024 04:32:20 GMT +- request: + method: put + uri: https://api.bigcommerce.com/stores//v3/customers/attribute-values + body: + encoding: UTF-8 + string: '[{"attribute_id":7,"value":"some value","customer_id":13}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3746' + X-Rate-Limit-Time-Reset-Ms: + - '29406' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 434fb8d5f91cc5309d3259aa6ee6eeb3 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":2,"customer_id":13,"attribute_id":7,"attribute_value":"some + value","date_created":"2024-10-24T04:32:20Z","date_modified":"2024-10-24T04:32:20Z"}],"meta":{}}' + recorded_at: Thu, 24 Oct 2024 04:32:20 GMT +- request: + method: delete + uri: https://api.bigcommerce.com/stores//v3/customers/attributes?id:in=7 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 204 + message: No Content + headers: + Connection: + - keep-alive + X-Rate-Limit-Requests-Left: + - '3745' + X-Rate-Limit-Time-Reset-Ms: + - '29157' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 2340a3ea99c495840af3e123af0ba961 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: UTF-8 + string: '' + recorded_at: Thu, 24 Oct 2024 04:32:20 GMT +- request: + method: delete + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=13 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 204 + message: No Content + headers: + Connection: + - keep-alive + X-Rate-Limit-Requests-Left: + - '3744' + X-Rate-Limit-Time-Reset-Ms: + - '28819' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - '097705c6c96088113e48db79156a64d0' + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: UTF-8 + string: '' + recorded_at: Thu, 24 Oct 2024 04:32:21 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/raises_an_error_when_the_customer_is_invalid.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/raises_an_error_when_the_customer_is_invalid.yml new file mode 100644 index 0000000..fdd8bb3 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/raises_an_error_when_the_customer_is_invalid.yml @@ -0,0 +1,50 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.bigcommerce.com/stores//v3/customers + body: + encoding: UTF-8 + string: '[{"email":"not-an-email","first_name":"Jay","last_name":"Cat"}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 422 + message: Unprocessable Entity + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3748' + X-Rate-Limit-Time-Reset-Ms: + - '30000' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 6359dbf153da3fd76ad1c69ef1ef0d37 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"status":422,"title":"Create customers failed.","type":"https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes","errors":{"0.email":"invalid + email"}}' + recorded_at: Thu, 24 Oct 2024 07:13:33 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/returns_the_new_customer.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/returns_the_new_customer.yml new file mode 100644 index 0000000..122ecda --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_create/creating_a_single_customer/returns_the_new_customer.yml @@ -0,0 +1,90 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.bigcommerce.com/stores//v3/customers + body: + encoding: UTF-8 + string: '[{"email":"test.customers.get@example.com","first_name":"Bill","last_name":"Bellamy","company":"Thangz + Inc.","phone":"510-555-1212","notes":"Duly noted!"}]' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3746' + X-Rate-Limit-Time-Reset-Ms: + - '18652' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - e39c0ef84ab6b1f5fc76b850ce17172c + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":18,"authentication":{"force_password_reset":false},"company":"Thangz + Inc.","customer_group_id":0,"email":"test.customers.get@example.com","first_name":"Bill","last_name":"Bellamy","notes":"Duly + noted!","phone":"510-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-24T07:19:29Z","date_modified":"2024-10-24T07:19:29Z","accepts_product_review_abandoned_cart_emails":false,"store_credit_amounts":[{"amount":0}],"origin_channel_id":1,"channel_ids":null}],"meta":{}}' + recorded_at: Thu, 24 Oct 2024 07:19:29 GMT +- request: + method: delete + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=18 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 204 + message: No Content + headers: + Connection: + - keep-alive + X-Rate-Limit-Requests-Left: + - '3745' + X-Rate-Limit-Time-Reset-Ms: + - '18294' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 205fabc8ef1d7a04b7e4e2d8f8390436 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: UTF-8 + string: '' + recorded_at: Thu, 24 Oct 2024 07:19:29 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_an_empty_result_when_customer_with_the_given_ID_does_not_exist.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_an_empty_result_when_customer_with_the_given_ID_does_not_exist.yml new file mode 100644 index 0000000..9e11578 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_an_empty_result_when_customer_with_the_given_ID_does_not_exist.yml @@ -0,0 +1,47 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=999999 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3746' + X-Rate-Limit-Time-Reset-Ms: + - '29449' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 63468144a5d7155b8c274b4caf822063 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[],"meta":{"pagination":{"total":0,"count":0,"per_page":50,"current_page":1,"total_pages":0}}}' + recorded_at: Thu, 24 Oct 2024 07:15:42 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_the_customer_with_the_given_ID.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_the_customer_with_the_given_ID.yml new file mode 100644 index 0000000..3bf5fca --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_a_single_ID/returns_the_customer_with_the_given_ID.yml @@ -0,0 +1,49 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3747' + X-Rate-Limit-Time-Reset-Ms: + - '29709' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 91f2ae3e79a1538d18115ed18fc08122 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":1,"authentication":{"force_password_reset":false},"company":"Acme + Inc.","customer_group_id":0,"email":"user1@example.com","first_name":"John","last_name":"Doe","notes":"Note + 1","phone":"555-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T18:16:29Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":1,"count":1,"per_page":50,"current_page":1,"total_pages":1}}}' + recorded_at: Thu, 24 Oct 2024 07:15:41 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_an_Array_containing_multiple_IDs/returns_the_customers_with_the_given_IDs.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_an_Array_containing_multiple_IDs/returns_the_customers_with_the_given_IDs.yml new file mode 100644 index 0000000..18dfea6 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_id/given_an_Array_containing_multiple_IDs/returns_the_customers_with_the_given_IDs.yml @@ -0,0 +1,49 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?id:in=1,5 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3745' + X-Rate-Limit-Time-Reset-Ms: + - '29169' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 7f1f8b643354e06667455e74f3d67200 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":1,"authentication":{"force_password_reset":false},"company":"Acme + Inc.","customer_group_id":0,"email":"user1@example.com","first_name":"John","last_name":"Doe","notes":"Note + 1","phone":"555-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T18:16:29Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":5,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user5@example.com","first_name":"Caio","last_name":"Oliver","notes":"","phone":"510-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":2,"count":2,"per_page":50,"current_page":1,"total_pages":1}}}' + recorded_at: Thu, 24 Oct 2024 07:15:42 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_a_single_relation_s_name/returns_customers_including_the_relation.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_a_single_relation_s_name/returns_customers_including_the_relation.yml new file mode 100644 index 0000000..c876d20 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_a_single_relation_s_name/returns_customers_including_the_relation.yml @@ -0,0 +1,64 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?include=addresses + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3744' + X-Rate-Limit-Time-Reset-Ms: + - '28722' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 5439cf74846804c760740380f664f13d + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":1,"address_count":1,"addresses":[{"id":1,"address1":"59 + West 46th Street","address2":"","address_type":"residential","city":"New York","company":"Fofiha","country":"United + States","country_code":"US","customer_id":1,"first_name":"","last_name":"","phone":"555-555-1212","postal_code":"10005","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"Acme Inc.","customer_group_id":0,"email":"user1@example.com","first_name":"John","last_name":"Doe","notes":"Note + 1","phone":"555-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T18:16:29Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":2,"address_count":1,"addresses":[{"id":2,"address1":"123 + 55th St.","address2":"#1","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":2,"first_name":"","last_name":"","phone":"212-555-1212","postal_code":"10038","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"Acme Inc.","customer_group_id":0,"email":"user2@example.com","first_name":"Bob","last_name":"John","notes":"","phone":"212-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T06:11:27Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":3,"address_count":1,"addresses":[{"id":3,"address1":"21 + W. 21st St.","address2":"","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":3,"first_name":"Abe","last_name":"Simpson","phone":"310-555-1212","postal_code":"10015","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"FooBar + LLC","customer_group_id":0,"email":"user3@example.com","first_name":"Richard","last_name":"Smith","notes":"","phone":"310-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T18:50:21Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null},{"id":4,"address_count":1,"addresses":[{"id":4,"address1":"666 + 6th Ave.","address2":"","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":4,"first_name":"","last_name":"","phone":"","postal_code":"10005","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user4@example.com","first_name":"Paulo","last_name":"Costa","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":5,"address_count":1,"addresses":[{"id":5,"address1":"125 + 55th St.","address2":"Apt 3Q","address_type":"residential","city":"New York","company":"Fofiha","country":"United + States","country_code":"US","customer_id":5,"first_name":"","last_name":"","phone":"510-555-1212","postal_code":"10001","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user5@example.com","first_name":"Caio","last_name":"Oliver","notes":"","phone":"510-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":5,"count":5,"per_page":50,"current_page":1,"total_pages":1}}}' + recorded_at: Thu, 24 Oct 2024 07:15:42 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_an_Array_containing_multiple_relations/returns_customers_including_both_relations.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_an_Array_containing_multiple_relations/returns_customers_including_both_relations.yml new file mode 100644 index 0000000..b962997 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/_include/given_an_Array_containing_multiple_relations/returns_customers_including_both_relations.yml @@ -0,0 +1,64 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?include=addresses,storecredit + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3743' + X-Rate-Limit-Time-Reset-Ms: + - '28351' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 5aad7dc52f51682680746f851cfda486 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":1,"address_count":1,"addresses":[{"id":1,"address1":"59 + West 46th Street","address2":"","address_type":"residential","city":"New York","company":"Fofiha","country":"United + States","country_code":"US","customer_id":1,"first_name":"","last_name":"","phone":"555-555-1212","postal_code":"10005","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"Acme Inc.","customer_group_id":0,"email":"user1@example.com","first_name":"John","last_name":"Doe","notes":"Note + 1","phone":"555-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T18:16:29Z","accepts_product_review_abandoned_cart_emails":false,"store_credit_amounts":[{"amount":59.99}],"origin_channel_id":1,"channel_ids":null},{"id":2,"address_count":1,"addresses":[{"id":2,"address1":"123 + 55th St.","address2":"#1","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":2,"first_name":"","last_name":"","phone":"212-555-1212","postal_code":"10038","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"Acme Inc.","customer_group_id":0,"email":"user2@example.com","first_name":"Bob","last_name":"John","notes":"","phone":"212-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T06:11:27Z","accepts_product_review_abandoned_cart_emails":false,"store_credit_amounts":[{"amount":0}],"origin_channel_id":1,"channel_ids":null},{"id":3,"address_count":1,"addresses":[{"id":3,"address1":"21 + W. 21st St.","address2":"","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":3,"first_name":"Abe","last_name":"Simpson","phone":"310-555-1212","postal_code":"10015","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"FooBar + LLC","customer_group_id":0,"email":"user3@example.com","first_name":"Richard","last_name":"Smith","notes":"","phone":"310-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T18:50:21Z","accepts_product_review_abandoned_cart_emails":true,"store_credit_amounts":[{"amount":101}],"origin_channel_id":1,"channel_ids":null},{"id":4,"address_count":1,"addresses":[{"id":4,"address1":"666 + 6th Ave.","address2":"","address_type":"residential","city":"New York","company":"","country":"United + States","country_code":"US","customer_id":4,"first_name":"","last_name":"","phone":"","postal_code":"10005","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user4@example.com","first_name":"Paulo","last_name":"Costa","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":false,"store_credit_amounts":[{"amount":0}],"origin_channel_id":1,"channel_ids":null},{"id":5,"address_count":1,"addresses":[{"id":5,"address1":"125 + 55th St.","address2":"Apt 3Q","address_type":"residential","city":"New York","company":"Fofiha","country":"United + States","country_code":"US","customer_id":5,"first_name":"","last_name":"","phone":"510-555-1212","postal_code":"10001","state_or_province":"New + York"}],"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user5@example.com","first_name":"Caio","last_name":"Oliver","notes":"","phone":"510-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":true,"store_credit_amounts":[{"amount":0}],"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":5,"count":5,"per_page":50,"current_page":1,"total_pages":1}}}' + recorded_at: Thu, 24 Oct 2024 07:15:43 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/makes_the_pagination_values_available_on_the_result.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/makes_the_pagination_values_available_on_the_result.yml new file mode 100644 index 0000000..c38d977 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/makes_the_pagination_values_available_on_the_result.yml @@ -0,0 +1,48 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?limit=2&page=2 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3741' + X-Rate-Limit-Time-Reset-Ms: + - '27493' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - d48b0c8b173b138c707a79d54994569d + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":3,"authentication":{"force_password_reset":false},"company":"FooBar + LLC","customer_group_id":0,"email":"user3@example.com","first_name":"Richard","last_name":"Smith","notes":"","phone":"310-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T18:50:21Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null},{"id":4,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user4@example.com","first_name":"Paulo","last_name":"Costa","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":5,"count":2,"per_page":2,"current_page":2,"total_pages":3}}}' + recorded_at: Thu, 24 Oct 2024 07:15:43 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/returns_the_customers_at_the_specified_page_and_limit.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/returns_the_customers_at_the_specified_page_and_limit.yml new file mode 100644 index 0000000..b9804b2 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/pagination/returns_the_customers_at_the_specified_page_and_limit.yml @@ -0,0 +1,48 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers?limit=2&page=2 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3742' + X-Rate-Limit-Time-Reset-Ms: + - '27842' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - d779ff158b641a2133b8e0df680d62fb + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":3,"authentication":{"force_password_reset":false},"company":"FooBar + LLC","customer_group_id":0,"email":"user3@example.com","first_name":"Richard","last_name":"Smith","notes":"","phone":"310-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T18:50:21Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null},{"id":4,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user4@example.com","first_name":"Paulo","last_name":"Costa","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":5,"count":2,"per_page":2,"current_page":2,"total_pages":3}}}' + recorded_at: Thu, 24 Oct 2024 07:15:43 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/returns_a_list_of_customers.yml b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/returns_a_list_of_customers.yml new file mode 100644 index 0000000..6768970 --- /dev/null +++ b/spec/cassettes/BigCommerce_ManagementAPI_Customers/_customers/_get/returns_a_list_of_customers.yml @@ -0,0 +1,51 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.bigcommerce.com/stores//v3/customers + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - BigCommerce Management API Client v0.0.1.pre1 (Ruby v2.7.8) + X-Auth-Token: + - "" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Vary: + - Accept-Encoding + X-Rate-Limit-Requests-Left: + - '3748' + X-Rate-Limit-Time-Reset-Ms: + - '29999' + X-Rate-Limit-Requests-Quota: + - '3749' + X-Rate-Limit-Time-Window-Ms: + - '30000' + X-Request-Id: + - 26807b4aad2d38ec2237132799ac141c + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: ASCII-8BIT + string: '{"data":[{"id":1,"authentication":{"force_password_reset":false},"company":"Acme + Inc.","customer_group_id":0,"email":"user1@example.com","first_name":"John","last_name":"Doe","notes":"Note + 1","phone":"555-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T18:16:29Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":2,"authentication":{"force_password_reset":false},"company":"Acme + Inc.","customer_group_id":0,"email":"user2@example.com","first_name":"Bob","last_name":"John","notes":"","phone":"212-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:27Z","date_modified":"2024-10-21T06:11:27Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":3,"authentication":{"force_password_reset":false},"company":"FooBar + LLC","customer_group_id":0,"email":"user3@example.com","first_name":"Richard","last_name":"Smith","notes":"","phone":"310-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T18:50:21Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null},{"id":4,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user4@example.com","first_name":"Paulo","last_name":"Costa","notes":"","phone":"","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":false,"origin_channel_id":1,"channel_ids":null},{"id":5,"authentication":{"force_password_reset":false},"company":"","customer_group_id":0,"email":"user5@example.com","first_name":"Caio","last_name":"Oliver","notes":"","phone":"510-555-1212","registration_ip_address":"","tax_exempt_category":"","date_created":"2024-10-21T06:11:28Z","date_modified":"2024-10-21T06:11:28Z","accepts_product_review_abandoned_cart_emails":true,"origin_channel_id":1,"channel_ids":null}],"meta":{"pagination":{"total":5,"count":5,"per_page":50,"current_page":1,"total_pages":1}}}' + recorded_at: Thu, 24 Oct 2024 07:15:41 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/customers/attribute_values_spec.rb b/spec/customers/attribute_values_spec.rb new file mode 100644 index 0000000..b951175 --- /dev/null +++ b/spec/customers/attribute_values_spec.rb @@ -0,0 +1,50 @@ +RSpec.describe BigCommerce::ManagementAPI::AttributeValue, :vcr do + describe "#create" do + before do + @created = [] + @attribute = client.customers.attributes.create( + :name => "test.attribute_values.upsert", + :type => "string" + ).first + + @customer = client.customers.create( + :email => "test.attributevalues.create@example.com", + :first_name => "Test", + :last_name => "User" + ).first + + @created << @customer.id + end + + after do + client.customers.attributes.delete(@attribute.id) if @attribute + client.customers.delete(*@created) if @created.any? + end + + describe "#upsert" do + describe "creating a single attribute value" do + it "returns the new attribute value" do + # Can check if created vs updated? + result = client.customers.attribute_values.upsert( + :attribute_id => @attribute.id, + :value => "some value", + :customer_id => @customer.id + ) + + expect(result.count).to eq 1 + + value = result.first + expect(value).to be_a(BigCommerce::ManagementAPI::AttributeValue) + expect(value).to have_attributes( + :id => match(Numeric), + :attribute_value => "some value", + :attribute_id => @attribute.id, + :customer_id => @customer.id, + :date_created => match(Time), + :date_modified => match(Time) + ) + end + end + end + end +end diff --git a/spec/customers/attributes_spec.rb b/spec/customers/attributes_spec.rb new file mode 100644 index 0000000..b277a29 --- /dev/null +++ b/spec/customers/attributes_spec.rb @@ -0,0 +1,31 @@ +RSpec.describe BigCommerce::ManagementAPI::Attribute, :vcr do + describe "#create" do + before { @created = [] } + after { client.customers.delete(*@created) if @created.any? } + + describe "#create" do + describe "creating a single attribute" do + it "returns the new attribute" do + result = client.customers.attributes.create( + :name => "test.attribute.create", + :type => "string" + ) + + expect(result.count).to eq 1 + + attribute = result.first + @created << attribute.id + + expect(attribute).to be_a(BigCommerce::ManagementAPI::Attribute) + expect(attribute).to have_attributes( + :id => match(Numeric), + :name => "test.attribute.create", + :type => "string", + :date_created => match(Time), + :date_modified => match(Time) + ) + end + end + end + end +end diff --git a/spec/customers_spec.rb b/spec/customers_spec.rb new file mode 100644 index 0000000..4702f8d --- /dev/null +++ b/spec/customers_spec.rb @@ -0,0 +1,241 @@ +RSpec.describe BigCommerce::ManagementAPI::Customers, :vcr do + describe "#customers" do + describe "#create" do + before { @created = [] } + + after do + client.customers.delete(*@created) if @created.any? + end + + describe "creating a single customer" do + it "returns the new customer" do + result = client.customers.create( + :email => "test.customers.get@example.com", + :first_name => "Bill", + :last_name => "Bellamy", + :company => "Thangz Inc.", + :phone => "510-555-1212", + :notes => "Duly noted!", + # :tax_exempt_category => nil, + # :customer_group_id => 0 + ) + + expect(result.count).to eq 1 + + customer = result.first + @created << customer.id + + expect(customer).to be_a(BigCommerce::ManagementAPI::Customer) + expect(customer).to have_attributes( + :email => "test.customers.get@example.com", + :first_name => "Bill", + :last_name => "Bellamy", + :company => "Thangz Inc.", + :phone => "510-555-1212", + :notes => "Duly noted!", + :tax_exempt_category => "", + # BC default + :customer_group_id => 0 + ) + end + + it "raises an error when the customer is invalid" do + expect { + client.customers.create( + :email => "not-an-email", + :first_name => "Jay", + :last_name => "Cat" + ) + }.to raise_error(BigCommerce::ManagementAPI::ResponseError, /invalid email/) + end + end + end + + describe "#get" do + it "returns a list of customers" do + result = client.customers.get + expect(result.count).to eq 5 + + customers = result.sort_by(&:email) + expect(customers[0]).to be_a BigCommerce::ManagementAPI::Customer + expect(customers[0]).to have_attributes( + :first_name => "John", + :last_name => "Doe", + :email => "user1@example.com" + ) + + expect(customers[1]).to be_a BigCommerce::ManagementAPI::Customer + expect(customers[1]).to have_attributes( + :first_name => "Bob", + :last_name => "John", + :email => "user2@example.com" + ) + end + + describe ":id" do + context "given a single ID" do + it "returns the customer with the given ID" do + result = client.customers.get(:id => 1) + expect(result.count).to eq 1 + + customer = result.first + expect(customer).to be_a(BigCommerce::ManagementAPI::Customer) + expect(customer).to have_attributes( + :id => 1, + :first_name => "John", + :last_name => "Doe" + ) + end + + it "returns an empty result when customer with the given ID does not exist" do + result = client.customers.get(:id => 999999) + expect(result.count).to eq 0 + end + end + + context "given an Array containing multiple IDs" do + it "returns the customers with the given IDs" do + result = client.customers.get(:id => [1, 5]) + expect(result.count).to eq 2 + + customers = result.to_a + expect(customers[0]).to have_attributes( + :id => 1, + :first_name => "John", + :last_name => "Doe" + ) + expect(customers[1]).to have_attributes( + :id => 5, + :first_name => "Caio", + :last_name => "Oliver" + ) + end + end + end + + describe ":include" do + context "given a single relation's name" do + it "returns customers including the relation" do + result = client.customers.get(:include => "addresses") + expect(result.count).to eq 5 + + customers = result.sort_by(&:email) + expect(customers[0]).to be_a(BigCommerce::ManagementAPI::Customer) + + # Just check a few to ensure we're getting what we expect via include + addresses = customers[0].addresses + expect(addresses.size).to eq 1 + expect(addresses[0]).to be_a(BigCommerce::ManagementAPI::Address) + expect(addresses[0]).to have_attributes( + "id"=> be_a(Integer), + "address1" => "59 West 46th Street", + "address2" => "", + "address_type" => "residential", + "city" => "New York", + "company" => "Fofiha", + "country" => "United States", + "country_code" => "US", + "customer_id" => be_a(Integer), + "first_name" => "", + "last_name" => "", + "phone" => "555-555-1212", + "postal_code" => "10005", + "state_or_province" => "New York" + ) + + addresses = customers[1].addresses + expect(addresses.size).to eq 1 + expect(addresses[0]).to be_a(BigCommerce::ManagementAPI::Address) + expect(addresses[0]).to have_attributes( + "id"=> be_a(Integer), + "address1" => "123 55th St.", + "address2" => "#1", + "address_type" => "residential", + "city" => "New York", + "company" => "", + "country" => "United States", + "country_code" => "US", + "customer_id" => be_a(Integer), + "first_name" => "", + "last_name" => "", + "phone" => "212-555-1212", + "postal_code" => "10038", + "state_or_province" => "New York" + ) + + end + end + + context "given an Array containing multiple relations" do + it "returns customers including both relations" do + result = client.customers.get(:include => %w[addresses storecredit]) + expect(result.count).to eq 5 + + # Just check a few to ensure we're getting what we expect via include + customers = result.sort_by(&:email) + expect(customers[0]).to be_a(BigCommerce::ManagementAPI::Customer) + expect(customers[0].email).to eq "user1@example.com" + + addresses = customers[0].addresses + expect(addresses.size).to eq 1 + expect(addresses[0]).to be_a(BigCommerce::ManagementAPI::Address) + expect(addresses[0].address1).to eq "59 West 46th Street" + + credits = customers[0].store_credit_amounts + expect(credits.size).to eq 1 + expect(credits[0]).to be_a(BigCommerce::ManagementAPI::StoreCreditAmount) + expect(credits[0].amount).to eq 59.99 + + expect(customers[1]).to be_a(BigCommerce::ManagementAPI::Customer) + expect(customers[1].email).to eq "user2@example.com" + + addresses = customers[1].addresses + expect(addresses.size).to eq 1 + expect(addresses[0]).to be_a(BigCommerce::ManagementAPI::Address) + expect(addresses[0].address1).to eq "123 55th St." + + credits = customers[1].store_credit_amounts + expect(credits.size).to eq 1 + expect(credits[0]).to be_a(BigCommerce::ManagementAPI::StoreCreditAmount) + expect(credits[0].amount).to eq 0.0 + + expect(customers[2]).to be_a(BigCommerce::ManagementAPI::Customer) + expect(customers[2].email).to eq "user3@example.com" + + addresses = customers[2].addresses + expect(addresses.size).to eq 1 + expect(addresses[0]).to be_a(BigCommerce::ManagementAPI::Address) + expect(addresses[0].address1).to eq "21 W. 21st St." + + credits = customers[2].store_credit_amounts + expect(credits.size).to eq 1 + expect(credits[0]).to be_a(BigCommerce::ManagementAPI::StoreCreditAmount) + expect(credits[0].amount).to eq 101.0 + end + end + end + + describe "pagination" do + before { @result = client.customers.get(:page => 2, :limit => 2) } + + it "returns the customers at the specified :page and :limit" do + expect(@result.count).to eq 2 + + emails = @result.map(&:email) + expect(emails).to contain_exactly("user3@example.com", "user4@example.com") + end + + it "makes the pagination values available on the result" do + pages = @result.meta.pagination + expect(pages).to have_attributes( + :count => 2, + :current_page => 2, + :per_page => 2, + :total => 5, + :total_pages => 3 + ) + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 997246a..e961413 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ require "bundler/setup" -require "big_commerce_rest" +require "vcr" +require "dotenv/load" +require "big_commerce/management_api" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure @@ -11,11 +13,21 @@ config.expect_with :rspec do |c| c.syntax = :expect end + + config.before do + def client + @client ||= BigCommerce::ManagementAPI.new( + ENV.fetch("BC_STORE_HASH"), + ENV.fetch("BC_ACCESS_TOKEN"), + ) + end + end end VCR.configure do |c| c.cassette_library_dir = "spec/cassettes" c.hook_into :webmock c.configure_rspec_metadata! - c.filter_sensitive_data("") { ENV.fetch("BC_AUTH_TOKEN") } + c.filter_sensitive_data("") { ENV.fetch("BC_ACCESS_TOKEN") } + c.filter_sensitive_data("") { ENV.fetch("BC_STORE_HASH") } end