coinbase_commerce 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +38 -0
  3. data/.gitignore +51 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +21 -0
  6. data/README.md +268 -0
  7. data/Rakefile +6 -0
  8. data/coinbase_commerce.gemspec +28 -0
  9. data/examples/charge.rb +38 -0
  10. data/examples/checkout.rb +61 -0
  11. data/examples/event.rb +26 -0
  12. data/examples/webhook.rb +35 -0
  13. data/lib/coinbase_commerce.rb +42 -0
  14. data/lib/coinbase_commerce/api_errors.rb +157 -0
  15. data/lib/coinbase_commerce/api_resources/base/api_object.rb +206 -0
  16. data/lib/coinbase_commerce/api_resources/base/api_resource.rb +25 -0
  17. data/lib/coinbase_commerce/api_resources/base/create.rb +15 -0
  18. data/lib/coinbase_commerce/api_resources/base/delete.rb +16 -0
  19. data/lib/coinbase_commerce/api_resources/base/list.rb +25 -0
  20. data/lib/coinbase_commerce/api_resources/base/save.rb +18 -0
  21. data/lib/coinbase_commerce/api_resources/base/update.rb +15 -0
  22. data/lib/coinbase_commerce/api_resources/charge.rb +14 -0
  23. data/lib/coinbase_commerce/api_resources/checkout.rb +19 -0
  24. data/lib/coinbase_commerce/api_resources/event.rb +13 -0
  25. data/lib/coinbase_commerce/api_response.rb +48 -0
  26. data/lib/coinbase_commerce/client.rb +120 -0
  27. data/lib/coinbase_commerce/util.rb +59 -0
  28. data/lib/coinbase_commerce/version.rb +3 -0
  29. data/lib/coinbase_commerce/webhooks.rb +52 -0
  30. data/spec/api_resources/base/api_object_spec.rb +156 -0
  31. data/spec/api_resources/base/api_resource_spec.rb +32 -0
  32. data/spec/api_resources/charge_spec.rb +19 -0
  33. data/spec/api_resources/checkout_spec.rb +31 -0
  34. data/spec/api_resources/event_spec.rb +12 -0
  35. data/spec/endpont_spec.rb +103 -0
  36. data/spec/error_spec.rb +58 -0
  37. data/spec/response_spec.rb +43 -0
  38. data/spec/spec_helper.rb +15 -0
  39. data/spec/webhook_spec.rb +36 -0
  40. metadata +161 -0
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe CoinbaseCommerce::APIResources::Base::APIObject do
6
+ describe "#respond_to" do
7
+ it "should implement respond_to method" do
8
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(id: 1, foo: "bar")
9
+ expect(obj.respond_to?(:foo)).to be true
10
+ expect(obj.respond_to?(:baz)).to be false
11
+ end
12
+ end
13
+
14
+ describe "#serialize params" do
15
+ it "should serialize params on an empty object" do
16
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
17
+ expect({}).to eq obj.serialize_params
18
+ end
19
+
20
+ it "should serialize params on a new object with a sub object" do
21
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.new
22
+ obj.metadata = {foo: "bar"}
23
+ expect({metadata: {foo: "bar"}}).to eq obj.serialize_params
24
+ end
25
+
26
+ it "should serialize params on a basic object" do
27
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: nil)
28
+ obj.update_attributes(foo: "bar")
29
+ expect({foo: "bar"}).to eq obj.serialize_params
30
+ end
31
+
32
+ it "should serialize params on a complex object" do
33
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(
34
+ foo: CoinbaseCommerce::APIResources::Base::APIObject.create_from(bar: nil, baz: nil))
35
+ obj.foo.bar = "newbar"
36
+ expect({foo: {bar: "newbar"}}).to eq obj.serialize_params
37
+ end
38
+
39
+ it "should serialize params on an array" do
40
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: nil)
41
+ obj.foo = ["new-value"]
42
+ expect({foo: ["new-value"]}).to eq obj.serialize_params
43
+ end
44
+
45
+ it "should serialize params on an array that shortens" do
46
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: ["0-index", "1-index", "2-index"])
47
+ obj.foo = ["new-value"]
48
+ expect({foo: ["new-value"]}).to eq obj.serialize_params
49
+ end
50
+
51
+ it "should serialize params on an array of hashes" do
52
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: nil)
53
+ obj.foo = [
54
+ CoinbaseCommerce::APIResources::Base::APIObject.create_from(bar: nil),
55
+ ]
56
+ obj.foo[0].bar = "baz"
57
+ expect({foo: [{bar: "baz"}]}).to eq obj.serialize_params
58
+ end
59
+
60
+ it "should serialize params doesn't include unchanged values" do
61
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: nil)
62
+ expect({}).to eq obj.serialize_params
63
+ end
64
+
65
+ it "should serialize params with a APIObject" do
66
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
67
+ obj.metadata = CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: "bar")
68
+ serialized = obj.serialize_params
69
+ expect({foo: "bar"}).to eq serialized[:metadata]
70
+ end
71
+
72
+ it "should serialize params with APIObject that's been replaced" do
73
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(
74
+ source: CoinbaseCommerce::APIResources::Base::APIObject.create_from(bar: "foo"))
75
+
76
+ obj.source = CoinbaseCommerce::APIResources::Base::APIObject.create_from(baz: "foo")
77
+
78
+ serialized = obj.serialize_params
79
+ expect({baz: "foo"}).to eq serialized[:source]
80
+ end
81
+
82
+ it "should serialize params with an array of APIObjects" do
83
+ stub_request(:post, "#{@api_base}charges").to_return(body: {data: mock_item}.to_json)
84
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
85
+ obj.metadata = [
86
+ CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: "bar"),
87
+ ]
88
+
89
+ serialized = obj.serialize_params
90
+ expect([{foo: "bar"}]).to eq serialized[:metadata]
91
+ end
92
+
93
+ it "should serialize params with embed API resources" do
94
+ charge = CoinbaseCommerce::APIResources::Charge.create_from(id: "charge_id")
95
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
96
+ obj.charge = charge
97
+ expect(obj.charge).is_a? CoinbaseCommerce::APIResources::Charge
98
+ end
99
+
100
+ it "should serialize params and not include API resources that have not been set" do
101
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(id: "cus_123")
102
+ obj2 = CoinbaseCommerce::APIResources::Base::APIObject.create_from(obj: obj)
103
+ serialized = obj2.serialize_params
104
+ expect({}).to eq serialized
105
+ end
106
+
107
+ it "should serialize params takes a push option" do
108
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(
109
+ id: "id", metadata: CoinbaseCommerce::APIResources::Base::APIObject.create_from(foo: "bar"))
110
+ serialized = obj.serialize_params(push: true)
111
+ expect({id: "id", metadata: {foo: "bar"}}).to eq serialized
112
+ end
113
+ end
114
+
115
+ describe "update attributes" do
116
+ it "should update attributes with a hash" do
117
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
118
+ obj.update_attributes(metadata: {foo: "bar"})
119
+ expect(obj.metadata.class).to eq CoinbaseCommerce::APIResources::Base::APIObject
120
+ end
121
+
122
+ it "should assign question mark accessors for booleans added after initialization" do
123
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.new
124
+ obj.bool = true
125
+ expect(obj.respond_to?(:bool?)).to be true
126
+ expect(obj.bool?).to be true
127
+ end
128
+
129
+ it "should assign question mark accessors for booleans" do
130
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from(id: 1, bool: true, not_bool: "bar")
131
+ expect(obj.respond_to?(:bool?)).to be true
132
+ expect(obj.respond_to?(:not_bool)).to be true
133
+ expect(obj.bool?).to be true
134
+ end
135
+
136
+ it "should create accessors when update attributes is called" do
137
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
138
+ expect(obj.send(:metaclass).method_defined?(:foo)).to eq false
139
+ obj.update_attributes(foo: "bar")
140
+ expect(obj.send(:metaclass).method_defined?(:foo)).to eq true
141
+ end
142
+
143
+ it "should update attributes with a hash" do
144
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
145
+ obj.update_attributes(metadata: {foo: "bar"})
146
+ expect(CoinbaseCommerce::APIResources::Base::APIObject).to eq obj.metadata.class
147
+ end
148
+
149
+ it "should create accessors when update attributes is called" do
150
+ obj = CoinbaseCommerce::APIResources::Base::APIObject.create_from({})
151
+ expect(obj.send(:metaclass).method_defined?(:foo)).to be false
152
+ obj.update_attributes(foo: "bar")
153
+ expect(obj.send(:metaclass).method_defined?(:foo)).to be true
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe CoinbaseCommerce::APIResources::Base::APIResource do
4
+ before :all do
5
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
6
+ @api_base = @client.instance_variable_get :@api_uri
7
+ end
8
+
9
+ it "shout create a new APIResource without request" do
10
+ CoinbaseCommerce::APIResources::Base::APIResource.new("id")
11
+ assert_not_requested :get, %r{#{@api_base}/.*}
12
+ end
13
+
14
+ it "should create APIResource object form hash without request" do
15
+ CoinbaseCommerce::APIResources::Base::APIResource.create_from(id: "some_id",
16
+ param: {id: "param_id"})
17
+ assert_not_requested :get, %r{#{@api_base}/.*}
18
+ end
19
+
20
+ it "setting an attribute should not cause a network request" do
21
+ c = CoinbaseCommerce::APIResources::Base::APIResource.new("cus_123")
22
+ c.param = {id: "param_id"}
23
+ assert_not_requested :get, %r{#{@api_base}/.*}
24
+ assert_not_requested :post, %r{#{@api_base}/.*}
25
+ end
26
+
27
+ it "accessing id should not issue a fetch" do
28
+ c = CoinbaseCommerce::APIResources::Base::APIResource.new("cus_123")
29
+ c.id
30
+ assert_not_requested :get, %r{#{@api_base}/.*}
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ describe CoinbaseCommerce::APIResources::Charge do
2
+ before :all do
3
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
4
+ @api_base = @client.instance_variable_get :@api_uri
5
+ end
6
+
7
+ it "making a POST request with parameters should have a body and no query string" do
8
+ stub_request(:post, "#{@api_base}#{CoinbaseCommerce::APIResources::Charge::RESOURCE_PATH}")
9
+ .with(body: {:id => "id_value", :key => "key_value"})
10
+ .to_return(body: {data: {id: "id_value", key: "key_value"}}.to_json)
11
+ @client.charge.create(id: "id_value", key: "key_value")
12
+ end
13
+
14
+ it "making a GET request with parameters should have a query string and no body" do
15
+ stub_request(:get, "#{@api_base}#{CoinbaseCommerce::APIResources::Charge::RESOURCE_PATH}")
16
+ .with(query: {limit: 5}).to_return(body: JSON.generate(data: [mock_list]))
17
+ @client.charge.list(limit: 5)
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ describe CoinbaseCommerce::APIResources::Checkout do
2
+ before :all do
3
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
4
+ @api_base = @client.instance_variable_get :@api_uri
5
+ end
6
+
7
+ it "checkout should save nothing if nothing changes" do
8
+ stub_request(:post, "#{@api_base}#{CoinbaseCommerce::APIResources::Checkout::RESOURCE_PATH}")
9
+ .to_return(body: {data: {id: "id_value", key: "key_value"}}.to_json)
10
+ checkout = @client.checkout.create(id: "id_value", key: "key_value")
11
+
12
+ stub_request(:put, "#{@api_base}#{CoinbaseCommerce::APIResources::Checkout::RESOURCE_PATH}/id_value")
13
+ .with(body: {})
14
+ .to_return(body: JSON.generate("id" => "id_value", "key" => "key_value"))
15
+
16
+ checkout.save
17
+ end
18
+
19
+ it "making a POST request with parameters should have a body and no query string" do
20
+ stub_request(:post, "#{@api_base}#{CoinbaseCommerce::APIResources::Checkout::RESOURCE_PATH}")
21
+ .with(body: {:id => "id_value", :key => "key_value"})
22
+ .to_return(body: {data: {id: "id_value", key: "key_value"}}.to_json)
23
+ @client.checkout.create(id: "id_value", key: "key_value")
24
+ end
25
+
26
+ it "making a GET request with parameters should have a query string and no body" do
27
+ stub_request(:get, "#{@api_base}#{CoinbaseCommerce::APIResources::Checkout::RESOURCE_PATH}")
28
+ .with(query: {limit: 5}).to_return(body: JSON.generate(data: [mock_list]))
29
+ @client.checkout.list(limit: 5)
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ describe CoinbaseCommerce::APIResources::Event do
2
+ before :all do
3
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
4
+ @api_base = @client.instance_variable_get :@api_uri
5
+ end
6
+
7
+ it "making a GET request with parameters should have a query string and no body" do
8
+ stub_request(:get, "#{@api_base}#{CoinbaseCommerce::APIResources::Event::RESOURCE_PATH}")
9
+ .with(query: {limit: 5}).to_return(body: JSON.generate(data: [mock_list]))
10
+ @client.event.list(limit: 5)
11
+ end
12
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe CoinbaseCommerce do
5
+ before :all do
6
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
7
+ @api_base = @client.instance_variable_get :@api_uri
8
+ end
9
+
10
+ # test list resources
11
+ it "should get charges" do
12
+ stub_request(:get, "#{@api_base}charges").to_return(body: mock_list.to_json)
13
+ charge_list = @client.charge.list
14
+ expect(charge_list).is_a? @client.charge
15
+ expect(charge_list.data).is_a? Array
16
+ expect(charge_list.pagination).is_a? CoinbaseCommerce::APIResources::Base::APIObject
17
+ expect(charge_list.data[0].to_hash).to eq mock_item
18
+ end
19
+
20
+ it "should get checkouts" do
21
+ stub_request(:get, "#{@api_base}checkouts").to_return(body: mock_list.to_json)
22
+ checkout_list = @client.checkout.list
23
+ expect(checkout_list).is_a? @client.checkout
24
+ expect(checkout_list.data).is_a? Array
25
+ expect(checkout_list.pagination).is_a? CoinbaseCommerce::APIResources::Base::APIObject
26
+ expect(checkout_list.data[0].to_hash).to eq mock_item
27
+ end
28
+
29
+ it "should should get events" do
30
+ stub_request(:get, "#{@api_base}events").to_return(body: mock_list.to_json)
31
+ event_list = @client.event.list
32
+ expect(event_list).is_a? @client.checkout
33
+ expect(event_list.data).is_a? Array
34
+ expect(event_list.pagination).is_a? CoinbaseCommerce::APIResources::Base::APIObject
35
+ expect(event_list.data[0].to_hash).to eq mock_item
36
+ end
37
+
38
+
39
+ # test single resources
40
+ it "should get charge" do
41
+ stub_request(:get, "#{@api_base}charges/key").to_return(body: {data: mock_item}.to_json)
42
+ charge = @client.charge.retrieve :key
43
+ expect(charge).is_a? @client.charge
44
+ expect(charge).is_a? CoinbaseCommerce::APIResources::Base::APIObject
45
+ expect(charge.id).to eq mock_item[:id]
46
+ expect(charge.key).to eq mock_item[:key]
47
+ end
48
+
49
+ it "should get checkout" do
50
+ stub_request(:get, "#{@api_base}checkouts/key").to_return(body: {data: mock_item}.to_json)
51
+ checkout = @client.checkout.retrieve :key
52
+ expect(checkout).is_a? @client.checkout
53
+ expect(checkout).is_a? CoinbaseCommerce::APIResources::Base::APIObject
54
+ expect(checkout.id).to eq mock_item[:id]
55
+ expect(checkout.key).to eq mock_item[:key]
56
+ end
57
+
58
+ it "should get event" do
59
+ stub_request(:get, "#{@api_base}events/key").to_return(body: {data: mock_item}.to_json)
60
+ event = @client.event.retrieve :key
61
+ expect(event).is_a? @client.charge
62
+ expect(event).is_a? CoinbaseCommerce::APIResources::Base::APIObject
63
+ expect(event.id).to eq mock_item[:id]
64
+ expect(event.key).to eq mock_item[:key]
65
+ end
66
+
67
+ # test create resources
68
+ it "should create charge" do
69
+ stub_request(:post, "#{@api_base}charges").to_return(body: {data: mock_item}.to_json)
70
+ charge = @client.charge.create(mock_item)
71
+ expect(charge).is_a? @client.charge
72
+ expect(charge).is_a? CoinbaseCommerce::APIResources::Base::APIObject
73
+ expect(charge.id).to eq mock_item[:id]
74
+ expect(charge.key).to eq mock_item[:key]
75
+ end
76
+
77
+ it "should create checkout" do
78
+ stub_request(:post, "#{@api_base}checkouts").to_return(body: {data: mock_item}.to_json)
79
+ checkout = @client.checkout.create(mock_item)
80
+ expect(checkout).is_a? @client.checkout
81
+ expect(checkout).is_a? CoinbaseCommerce::APIResources::Base::APIObject
82
+ expect(checkout.id).to eq mock_item[:id]
83
+ expect(checkout.key).to eq mock_item[:key]
84
+ end
85
+
86
+ # test delete resources
87
+ it "should delete checkout" do
88
+ stub_request(:post, "#{@api_base}checkouts").to_return(body: {data: mock_item}.to_json)
89
+ stub_request(:delete, "#{@api_base}checkouts/val").to_return(body: {}.to_json)
90
+ checkout = @client.checkout.create(mock_item)
91
+ checkout.delete
92
+ end
93
+
94
+ # test save resources
95
+ it "should save checkout" do
96
+ stub_request(:post, "#{@api_base}checkouts").to_return(body: {data: mock_item}.to_json)
97
+ stub_request(:put, "#{@api_base}checkouts/val").to_return(body: {:edited => true}.to_json)
98
+ checkout = @client.checkout.create(mock_item)
99
+ checkout.key = "new value"
100
+ checkout.save
101
+ expect(checkout.edited).to eq true
102
+ end
103
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe CoinbaseCommerce do
5
+ before :all do
6
+ @client = CoinbaseCommerce::Client.new(api_key: 'api_key')
7
+ end
8
+
9
+ it "should get appropriate error when invalid response object" do
10
+ stub_request(:get, /.*/).to_return(body: {errors: [{id: "boo", message: "foo"}]}.to_json, status: 400)
11
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::APIError
12
+ end
13
+
14
+ it "should handle invalid request general" do
15
+ stub_request(:get, /.*/).to_return(body: {error: {type: "invalid_request", message: "test"}}.to_json, status: 400)
16
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::InvalidRequestError
17
+ end
18
+
19
+ it "should handle param required" do
20
+ stub_request(:get, /.*/).to_return(body: {error: {type: "param_required", message: "param_required"}}.to_json, status: 400)
21
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::ParamRequiredError
22
+ end
23
+
24
+ it "should handle validation error" do
25
+ stub_request(:get, /.*/).to_return(body: {error: {type: "validation_error", message: "validation_error"}}.to_json, status: 400)
26
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::ValidationError
27
+ end
28
+
29
+ it "should handle param_required" do
30
+ stub_request(:get, /.*/).to_return(body: {error: {type: "invalid_request", message: "invalid_request"}}.to_json, status: 400)
31
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::InvalidRequestError
32
+ end
33
+
34
+ it "should handle authentication error" do
35
+ stub_request(:get, /.*/).to_return(body: {error: {type: "auth_error", message: "auth_error"}}.to_json, status: 401)
36
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::AuthenticationError
37
+ end
38
+
39
+ it "should handle resource not found error" do
40
+ stub_request(:get, /.*/).to_return(body: {error: {type: "not_found", message: "not_found"}}.to_json, status: 404)
41
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::ResourceNotFoundError
42
+ end
43
+
44
+ it "should handle rate limit exceeded error" do
45
+ stub_request(:get, /.*/).to_return(body: {error: {type: "rate_limit_exceeded", message: "rate_limit_exceeded"}}.to_json, status: 429)
46
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::RateLimitExceededError
47
+ end
48
+
49
+ it "should handle internal server error" do
50
+ stub_request(:get, /.*/).to_return(body: {error: {type: "internal_error", message: "internal_error"}}.to_json, status: 500)
51
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::InternalServerError
52
+ end
53
+
54
+ it "should handle service unavailable error" do
55
+ stub_request(:get, /.*/).to_return(body: {error: {type: "service_unavailable", message: "service_unavailable"}}.to_json, status: 503)
56
+ expect {@client.checkout.list}.to raise_error CoinbaseCommerce::Errors::ServiceUnavailableError
57
+ end
58
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe CoinbaseCommerce::CoinbaseCommerceResponse do
5
+ describe "from_faraday_hash" do
6
+ it "should initialize a CoinbaseCommerceResponse object from a Hash like the kind" do
7
+ body = '{"foo": "bar"}'
8
+ headers = {"x-request-id" => "x-request-id"}
9
+ http_resp = {
10
+ body: body,
11
+ headers: headers,
12
+ status: 200,
13
+ }
14
+ resp = CoinbaseCommerce::CoinbaseCommerceResponse.from_faraday_hash(http_resp)
15
+
16
+ expect(JSON.parse(body, symbolize_names: true)).to eq resp.data
17
+ expect(body).to eq resp.http_body
18
+ expect(headers).to eq resp.http_headers
19
+ expect(200).to eq resp.http_status
20
+ expect("x-request-id").to eq resp.request_id
21
+ end
22
+ end
23
+
24
+ describe "from_faraday_response" do
25
+ it "should initialize a CoinbaseCommerceResponse object from a Faraday HTTP response object." do
26
+ body = '{"foo": "bar"}'
27
+ headers = {"x-request-id" => "x-request-id"}
28
+ env = Faraday::Env.from(
29
+ status: 200, body: body,
30
+ response_headers: headers
31
+ )
32
+ http_resp = Faraday::Response.new(env)
33
+
34
+ resp = CoinbaseCommerce::CoinbaseCommerceResponse.from_faraday_response(http_resp)
35
+
36
+ expect(JSON.parse(body, symbolize_names: true)).to eq resp.data
37
+ expect(body).to eq resp.http_body
38
+ expect(headers).to eq resp.http_headers
39
+ expect(200).to eq resp.http_status
40
+ expect("x-request-id").to eq resp.request_id
41
+ end
42
+ end
43
+ end