gecko-ruby 0.9.1 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/config/rubocop_linter_action.yml +7 -0
- data/.github/workflows/testing.yml +26 -0
- data/.rubocop.yml +23 -16
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/gecko-ruby.gemspec +11 -10
- data/generate.thor +4 -1
- data/lib/gecko-ruby.rb +2 -0
- data/lib/gecko.rb +3 -0
- data/lib/gecko/client.rb +17 -14
- data/lib/gecko/ext/liquid_compat.rb +10 -10
- data/lib/gecko/ext/log_subscriber.rb +6 -6
- data/lib/gecko/helpers/association_helper.rb +14 -12
- data/lib/gecko/helpers/inspection_helper.rb +4 -2
- data/lib/gecko/helpers/record_helper.rb +2 -0
- data/lib/gecko/helpers/serialization_helper.rb +5 -1
- data/lib/gecko/helpers/validation_helper.rb +3 -1
- data/lib/gecko/record/account.rb +4 -1
- data/lib/gecko/record/address.rb +2 -0
- data/lib/gecko/record/base.rb +5 -3
- data/lib/gecko/record/base_adapter.rb +33 -22
- data/lib/gecko/record/company.rb +3 -0
- data/lib/gecko/record/contact.rb +2 -0
- data/lib/gecko/record/currency.rb +2 -0
- data/lib/gecko/record/exceptions.rb +2 -0
- data/lib/gecko/record/fulfillment.rb +2 -0
- data/lib/gecko/record/fulfillment_line_item.rb +2 -1
- data/lib/gecko/record/image.rb +13 -8
- data/lib/gecko/record/invoice.rb +7 -3
- data/lib/gecko/record/invoice_line_item.rb +2 -1
- data/lib/gecko/record/location.rb +2 -0
- data/lib/gecko/record/note.rb +2 -0
- data/lib/gecko/record/order.rb +2 -0
- data/lib/gecko/record/order_line_item.rb +3 -0
- data/lib/gecko/record/payment_method.rb +15 -0
- data/lib/gecko/record/payment_term.rb +2 -1
- data/lib/gecko/record/product.rb +4 -0
- data/lib/gecko/record/purchase_order.rb +2 -1
- data/lib/gecko/record/purchase_order_line_item.rb +2 -1
- data/lib/gecko/record/tax_type.rb +2 -1
- data/lib/gecko/record/user.rb +3 -1
- data/lib/gecko/record/variant.rb +9 -7
- data/lib/gecko/record/webhook.rb +3 -1
- data/lib/gecko/version.rb +3 -1
- data/test/client_test.rb +4 -2
- data/test/fixtures/vcr_cassettes/images.yml +1 -1
- data/test/fixtures/vcr_cassettes/payment_methods.yml +69 -0
- data/test/fixtures/vcr_cassettes/payment_methods_count.yml +66 -0
- data/test/gecko_test.rb +2 -0
- data/test/helpers/association_helper_test.rb +7 -5
- data/test/helpers/inspection_helper_test.rb +6 -4
- data/test/helpers/serialization_helper_test.rb +16 -14
- data/test/helpers/validation_helper_test.rb +3 -1
- data/test/record/account_adapter_test.rb +2 -0
- data/test/record/address_adapter_test.rb +2 -0
- data/test/record/address_test.rb +2 -0
- data/test/record/company_adapter_test.rb +2 -0
- data/test/record/company_test.rb +2 -0
- data/test/record/contact_adapter_test.rb +2 -0
- data/test/record/contact_test.rb +3 -1
- data/test/record/currency_adapter_test.rb +2 -0
- data/test/record/currency_test.rb +2 -0
- data/test/record/fulfillment_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_test.rb +2 -0
- data/test/record/fulfillment_test.rb +4 -2
- data/test/record/image_adapter_test.rb +2 -0
- data/test/record/image_test.rb +18 -0
- data/test/record/invoice_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_test.rb +2 -0
- data/test/record/invoice_test.rb +2 -0
- data/test/record/location_adapter_test.rb +2 -0
- data/test/record/location_test.rb +2 -0
- data/test/record/note_test.rb +2 -0
- data/test/record/order_adapter_test.rb +2 -0
- data/test/record/order_line_item_adapter_test.rb +2 -0
- data/test/record/order_line_item_test.rb +2 -0
- data/test/record/order_test.rb +2 -0
- data/test/record/payment_method_adapter_test.rb +16 -0
- data/test/record/payment_method_test.rb +20 -0
- data/test/record/payment_term_adapter_test.rb +2 -0
- data/test/record/payment_term_test.rb +2 -0
- data/test/record/product_adapter_test.rb +2 -0
- data/test/record/product_test.rb +2 -0
- data/test/record/purchase_order_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_test.rb +2 -0
- data/test/record/purchase_order_test.rb +2 -0
- data/test/record/tax_type_adapter_test.rb +2 -0
- data/test/record/tax_type_test.rb +2 -0
- data/test/record/user_adapter_test.rb +2 -0
- data/test/record/user_test.rb +2 -0
- data/test/record/variant_adapter_test.rb +2 -0
- data/test/record/variant_test.rb +6 -4
- data/test/record/webhook_test.rb +2 -0
- data/test/support/let.rb +2 -0
- data/test/support/shared_adapter_examples.rb +35 -31
- data/test/support/shared_record_examples.rb +3 -1
- data/test/support/shared_sideloaded_data_parsing_examples.rb +2 -1
- data/test/support/testing_adapter.rb +2 -0
- data/test/support/vcr_support.rb +2 -0
- data/test/test_helper.rb +12 -0
- metadata +33 -23
- data/.travis.yml +0 -8
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gecko'
|
2
4
|
|
3
5
|
class Gecko::Helpers::ValidationHelperTest < Minitest::Test
|
@@ -17,7 +19,7 @@ class Gecko::Helpers::ValidationHelperTest < Minitest::Test
|
|
17
19
|
|
18
20
|
def test_from_response
|
19
21
|
record = @klass.new(@client, name: "Gecko")
|
20
|
-
record.errors.from_response({name: ["is not shiny"]})
|
22
|
+
record.errors.from_response({ name: ["is not shiny"] })
|
21
23
|
assert(!record.valid?)
|
22
24
|
assert_equal(record.errors[:name], ["is not shiny"])
|
23
25
|
end
|
data/test/record/address_test.rb
CHANGED
data/test/record/company_test.rb
CHANGED
data/test/record/contact_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::ContactTest < Minitest::Test
|
@@ -15,4 +17,4 @@ class Gecko::ContactTest < Minitest::Test
|
|
15
17
|
def test_initializes_record
|
16
18
|
assert_instance_of(Gecko::Record::Contact, @record)
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::FulfillmentTest < Minitest::Test
|
@@ -17,11 +19,11 @@ class Gecko::FulfillmentTest < Minitest::Test
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_serialization
|
20
|
-
json_keys = %w
|
22
|
+
json_keys = %w[
|
21
23
|
order_id shipping_address_id billing_address_id status stock_location_id exchange_rate
|
22
24
|
delivery_type tracking_number notes tracking_url tracking_company packed_at
|
23
25
|
service shipped_at received_at receipt
|
24
|
-
|
26
|
+
].map(&:to_sym)
|
25
27
|
assert_equal json_keys.sort, @record.as_json[:fulfillment].keys.sort
|
26
28
|
end
|
27
29
|
end
|
data/test/record/image_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::ImageTest < Minitest::Test
|
@@ -22,4 +24,20 @@ class Gecko::ImageTest < Minitest::Test
|
|
22
24
|
assert_equal("https://example.com/Gecko.jpg", @record.url(:full))
|
23
25
|
assert_equal("https://example.com/thumbnail_Gecko.jpg", @record.url(:thumbnail))
|
24
26
|
end
|
27
|
+
|
28
|
+
def test_building_record # rubocop:disable Metrics/MethodLength
|
29
|
+
record = @client.adapter_for(record_class.demodulized_name).build({
|
30
|
+
variant_ids: 1,
|
31
|
+
product_id: 1,
|
32
|
+
url: "https://example.com/Gecko.jpg"
|
33
|
+
})
|
34
|
+
assert_equal(record.product_id, 1)
|
35
|
+
assert_equal(record.variant_ids, [1])
|
36
|
+
assert_equal(record.serializable_hash, {
|
37
|
+
product_id: 1,
|
38
|
+
variant_ids: [1],
|
39
|
+
name: nil,
|
40
|
+
url: "https://example.com/Gecko.jpg"
|
41
|
+
})
|
42
|
+
end
|
25
43
|
end
|
data/test/record/invoice_test.rb
CHANGED
data/test/record/note_test.rb
CHANGED
data/test/record/order_test.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class Gecko::Record::PaymentMethodAdapterTest < Minitest::Test
|
6
|
+
include TestingAdapter
|
7
|
+
include SharedAdapterExamples
|
8
|
+
|
9
|
+
let(:adapter) { @client.PaymentMethod }
|
10
|
+
let(:plural_name) { "payment_methods" }
|
11
|
+
let(:record_class) { Gecko::Record::PaymentMethod }
|
12
|
+
|
13
|
+
def test_initializes_adapter
|
14
|
+
assert_instance_of(Gecko::Record::PaymentMethodAdapter, @client.PaymentMethod)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class Gecko::PaymentMethodTest < Minitest::Test
|
6
|
+
include VCRHelper
|
7
|
+
include SharedRecordExamples
|
8
|
+
|
9
|
+
let(:plural_name) { "payment_methods" }
|
10
|
+
let(:record_class) { Gecko::Record::PaymentMethod }
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@json = load_vcr_hash("payment_methods", "payment_methods").first
|
14
|
+
@record = record_class.new(client, @json)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initializes_record
|
18
|
+
assert_instance_of(Gecko::Record::PaymentMethod, @record)
|
19
|
+
end
|
20
|
+
end
|
data/test/record/product_test.rb
CHANGED
data/test/record/user_test.rb
CHANGED
data/test/record/variant_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class Gecko::VariantTest < Minitest::Test
|
@@ -22,7 +24,7 @@ class Gecko::VariantTest < Minitest::Test
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_variant_prices
|
25
|
-
json = {variant_prices: [{price_list_id: "buy", value: "12.50"}, {price_list_id: 123, value: "14.00"}]}
|
27
|
+
json = { variant_prices: [{ price_list_id: "buy", value: "12.50" }, { price_list_id: 123, value: "14.00" }] }
|
26
28
|
variant_prices = record_class.new(client, json).variant_prices
|
27
29
|
assert_instance_of(Gecko::Record::Variant::VariantPrice, variant_prices.first)
|
28
30
|
assert_equal(variant_prices[0].price_list_id, "buy")
|
@@ -31,10 +33,10 @@ class Gecko::VariantTest < Minitest::Test
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_variant_locations
|
34
|
-
json = {locations: [
|
36
|
+
json = { locations: [
|
35
37
|
{ location_id: 1, stock_on_hand: "12.50",
|
36
|
-
committed: "0", bin_location: "AB-123" }
|
37
|
-
]}
|
38
|
+
committed: "0", bin_location: "AB-123" }
|
39
|
+
] }
|
38
40
|
|
39
41
|
locations = record_class.new(client, json).locations
|
40
42
|
assert_instance_of(Gecko::Record::Variant::VariantLocation, locations.first)
|
data/test/record/webhook_test.rb
CHANGED
data/test/support/let.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Shared tests for Gecko::Record Adapters
|
2
4
|
# requires definition of several variables
|
3
5
|
# - adapter
|
@@ -5,7 +7,8 @@
|
|
5
7
|
# - record_class
|
6
8
|
|
7
9
|
require 'json'
|
8
|
-
|
10
|
+
|
11
|
+
module SharedAdapterExamples # rubocop:disable Metrics/ModuleLength
|
9
12
|
def test_adapter_all
|
10
13
|
VCR.use_cassette(plural_name) do
|
11
14
|
collection = adapter.where(limit: 5)
|
@@ -49,29 +52,29 @@ module SharedAdapterExamples
|
|
49
52
|
|
50
53
|
def test_has_record_for_id
|
51
54
|
mock_record = Object.new
|
52
|
-
adapter.instance_variable_set(:@identity_map, {12 => mock_record})
|
55
|
+
adapter.instance_variable_set(:@identity_map, { 12 => mock_record })
|
53
56
|
assert adapter.has_record_for_id?(12)
|
54
57
|
assert !adapter.has_record_for_id?(12345)
|
55
58
|
end
|
56
59
|
|
57
60
|
def test_fetch
|
58
|
-
request_stub = stub_request(:get,
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
request_stub = stub_request(:get, %r{#{plural_name}/\d+})
|
62
|
+
.to_return({
|
63
|
+
headers: { "Content-Type" => "application/json" },
|
64
|
+
body: JSON.dump({ plural_name.singularize => { id: 12345 } })
|
65
|
+
})
|
63
66
|
record = adapter.fetch(12345)
|
64
67
|
assert_equal(12345, record.id)
|
65
68
|
assert_requested(request_stub)
|
66
69
|
end
|
67
70
|
|
68
|
-
def test_fetch_miss
|
69
|
-
stub_request(:get,
|
71
|
+
def test_fetch_miss # rubocop:disable Metrics/MethodLength
|
72
|
+
stub_request(:get, %r{#{plural_name}/\d+})
|
70
73
|
.to_return({
|
71
74
|
status: 404,
|
72
|
-
headers: {"Content-Type" => "application/json"},
|
73
|
-
body:
|
74
|
-
type:
|
75
|
+
headers: { "Content-Type" => "application/json" },
|
76
|
+
body: JSON.dump({
|
77
|
+
type: "Not Found",
|
75
78
|
message: "Couldn't find #{plural_name.singularize} with id 12345"
|
76
79
|
})
|
77
80
|
})
|
@@ -105,9 +108,8 @@ module SharedAdapterExamples
|
|
105
108
|
def test_saving_new_record
|
106
109
|
record = adapter.build
|
107
110
|
mock_api_request(record,
|
108
|
-
|
109
|
-
|
110
|
-
)
|
111
|
+
[:post, plural_name],
|
112
|
+
[200, { plural_name.singularize => { id: 123 } }])
|
111
113
|
adapter.save(record)
|
112
114
|
assert_equal(record.id, 123)
|
113
115
|
assert(record.valid?)
|
@@ -116,9 +118,8 @@ module SharedAdapterExamples
|
|
116
118
|
def test_saving_new_invalid_record
|
117
119
|
record = adapter.build
|
118
120
|
mock_api_request(record,
|
119
|
-
|
120
|
-
|
121
|
-
)
|
121
|
+
[:post, plural_name],
|
122
|
+
[422, { "errors" => { title: ["can not be bounced"] } }])
|
122
123
|
adapter.save(record)
|
123
124
|
assert_nil(record.id)
|
124
125
|
assert(!record.valid?)
|
@@ -127,9 +128,8 @@ module SharedAdapterExamples
|
|
127
128
|
def test_saving_existing_record
|
128
129
|
record = existing_record
|
129
130
|
mock_api_request(record,
|
130
|
-
|
131
|
-
|
132
|
-
)
|
131
|
+
[:put, "#{plural_name}/#{record.id}"],
|
132
|
+
[204, ''])
|
133
133
|
adapter.save(record)
|
134
134
|
assert(record.valid?)
|
135
135
|
end
|
@@ -137,23 +137,22 @@ module SharedAdapterExamples
|
|
137
137
|
def test_saving_existing_invalid_record
|
138
138
|
record = existing_record
|
139
139
|
mock_api_request(record,
|
140
|
-
|
141
|
-
|
142
|
-
)
|
140
|
+
[:put, "#{plural_name}/#{record.id}"],
|
141
|
+
[422, { "errors" => { title: ["can not be bounced"] } }])
|
143
142
|
adapter.save(record)
|
144
143
|
assert(!record.valid?)
|
145
144
|
assert(record.errors[:title].any?)
|
146
145
|
end
|
147
146
|
|
148
|
-
def test_saving_record_with_idempotency_key
|
147
|
+
def test_saving_record_with_idempotency_key # rubocop:disable Metrics/MethodLength
|
149
148
|
record = adapter.build
|
150
149
|
mock_token = mock
|
151
|
-
mock_response = mock(status: 200, parsed: {plural_name.singularize => {id: 123}})
|
150
|
+
mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } }, error: nil)
|
152
151
|
mock_token.expects(:request)
|
153
152
|
.with(:post, plural_name, {
|
154
|
-
body:
|
153
|
+
body: record.as_json.to_json,
|
155
154
|
raise_errors: false,
|
156
|
-
headers:
|
155
|
+
headers: {
|
157
156
|
'Content-Type' => 'application/json',
|
158
157
|
'Idempotency-Key' => 'abcdefghijkl'
|
159
158
|
}
|
@@ -163,11 +162,16 @@ module SharedAdapterExamples
|
|
163
162
|
end
|
164
163
|
|
165
164
|
private
|
165
|
+
|
166
166
|
def mock_api_request(record, request, response)
|
167
167
|
mock_token = mock
|
168
|
-
mock_response = mock(status: response[0], parsed: response[1])
|
168
|
+
mock_response = mock(status: response[0], parsed: response[1], error: nil)
|
169
169
|
mock_token.expects(:request)
|
170
|
-
.with(request[0], request[1],
|
170
|
+
.with(request[0], request[1], {
|
171
|
+
body: record.as_json.to_json,
|
172
|
+
raise_errors: false,
|
173
|
+
headers: { 'Content-Type' => 'application/json' }
|
174
|
+
})
|
171
175
|
.returns(mock_response)
|
172
176
|
adapter.client.access_token = mock_token
|
173
177
|
end
|
@@ -177,6 +181,6 @@ private
|
|
177
181
|
end
|
178
182
|
|
179
183
|
def random_attribute
|
180
|
-
@
|
184
|
+
@random_attribute ||= record_class.attribute_set.find { |att| att.type == Axiom::Types::String }.name
|
181
185
|
end
|
182
186
|
end
|