shopify_api 9.0.4 → 9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -1
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/workflows/build.yml +44 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +23 -3
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +41 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +153 -0
- data/Gemfile_ar51 +1 -1
- data/README.md +42 -32
- data/RELEASING +10 -6
- data/Rakefile +16 -5
- data/SECURITY.md +59 -0
- data/dev.yml +11 -0
- data/docs/_config.yml +1 -0
- data/docs/_includes/footer.html +28 -0
- data/docs/_includes/head.html +28 -0
- data/docs/_layouts/index.html +57 -0
- data/docs/graphql.md +47 -2
- data/docs/index.md +639 -0
- data/lib/active_resource/connection_ext.rb +1 -0
- data/lib/active_resource/detailed_log_subscriber.rb +10 -7
- data/lib/active_resource/json_errors.rb +8 -2
- data/lib/shopify_api/api_access.rb +57 -0
- data/lib/shopify_api/api_version.rb +6 -5
- data/lib/shopify_api/connection.rb +1 -0
- data/lib/shopify_api/countable.rb +3 -2
- data/lib/shopify_api/disable_prefix_check.rb +2 -2
- data/lib/shopify_api/events.rb +2 -1
- data/lib/shopify_api/graphql.rb +28 -8
- data/lib/shopify_api/hmac_params.rb +23 -0
- data/lib/shopify_api/limits.rb +3 -2
- data/lib/shopify_api/message_enricher.rb +11 -9
- data/lib/shopify_api/meta.rb +0 -1
- data/lib/shopify_api/metafields.rb +5 -4
- data/lib/shopify_api/pagination_link_headers.rb +5 -4
- data/lib/shopify_api/resources/access_scope.rb +1 -1
- data/lib/shopify_api/resources/access_token.rb +1 -0
- data/lib/shopify_api/resources/address.rb +1 -0
- data/lib/shopify_api/resources/announcement.rb +2 -1
- data/lib/shopify_api/resources/application_charge.rb +1 -0
- data/lib/shopify_api/resources/application_credit.rb +1 -0
- data/lib/shopify_api/resources/article.rb +3 -2
- data/lib/shopify_api/resources/asset.rb +6 -5
- data/lib/shopify_api/resources/assigned_fulfillment_order.rb +1 -1
- data/lib/shopify_api/resources/base.rb +12 -8
- data/lib/shopify_api/resources/billing_address.rb +1 -0
- data/lib/shopify_api/resources/blog.rb +2 -1
- data/lib/shopify_api/resources/carrier_service.rb +1 -0
- data/lib/shopify_api/resources/cart.rb +2 -1
- data/lib/shopify_api/resources/collect.rb +1 -0
- data/lib/shopify_api/resources/collection_listing.rb +1 -0
- data/lib/shopify_api/resources/comment.rb +20 -5
- data/lib/shopify_api/resources/country.rb +1 -0
- data/lib/shopify_api/resources/custom_collection.rb +4 -3
- data/lib/shopify_api/resources/customer.rb +2 -1
- data/lib/shopify_api/resources/customer_group.rb +1 -0
- data/lib/shopify_api/resources/customer_invite.rb +1 -0
- data/lib/shopify_api/resources/customer_saved_search.rb +2 -1
- data/lib/shopify_api/resources/discount_code.rb +1 -0
- data/lib/shopify_api/resources/discount_code_batch.rb +4 -2
- data/lib/shopify_api/resources/draft_order.rb +1 -0
- data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
- data/lib/shopify_api/resources/event.rb +1 -0
- data/lib/shopify_api/resources/fulfillment.rb +12 -3
- data/lib/shopify_api/resources/fulfillment_event.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_order.rb +30 -16
- data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_v2.rb +3 -2
- data/lib/shopify_api/resources/gift_card.rb +1 -0
- data/lib/shopify_api/resources/image.rb +2 -1
- data/lib/shopify_api/resources/inventory_level.rb +3 -4
- data/lib/shopify_api/resources/line_item.rb +4 -3
- data/lib/shopify_api/resources/location.rb +1 -1
- data/lib/shopify_api/resources/marketing_event.rb +1 -0
- data/lib/shopify_api/resources/metafield.rb +1 -0
- data/lib/shopify_api/resources/note_attribute.rb +1 -0
- data/lib/shopify_api/resources/option.rb +1 -0
- data/lib/shopify_api/resources/order.rb +2 -1
- data/lib/shopify_api/resources/order_risk.rb +1 -0
- data/lib/shopify_api/resources/page.rb +1 -0
- data/lib/shopify_api/resources/payment_details.rb +1 -0
- data/lib/shopify_api/resources/policy.rb +1 -0
- data/lib/shopify_api/resources/price_rule.rb +1 -1
- data/lib/shopify_api/resources/product.rb +27 -3
- data/lib/shopify_api/resources/product_listing.rb +1 -0
- data/lib/shopify_api/resources/province.rb +1 -0
- data/lib/shopify_api/resources/receipt.rb +1 -0
- data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
- data/lib/shopify_api/resources/redirect.rb +1 -0
- data/lib/shopify_api/resources/refund.rb +2 -1
- data/lib/shopify_api/resources/report.rb +1 -0
- data/lib/shopify_api/resources/resource_feedback.rb +1 -1
- data/lib/shopify_api/resources/rule.rb +1 -0
- data/lib/shopify_api/resources/script_tag.rb +1 -0
- data/lib/shopify_api/resources/shipping_address.rb +1 -0
- data/lib/shopify_api/resources/shipping_line.rb +1 -0
- data/lib/shopify_api/resources/shipping_zone.rb +1 -0
- data/lib/shopify_api/resources/shop.rb +2 -1
- data/lib/shopify_api/resources/smart_collection.rb +4 -8
- data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
- data/lib/shopify_api/resources/tax_line.rb +1 -0
- data/lib/shopify_api/resources/tax_service.rb +1 -0
- data/lib/shopify_api/resources/theme.rb +1 -0
- data/lib/shopify_api/resources/transaction.rb +1 -0
- data/lib/shopify_api/resources/usage_charge.rb +1 -0
- data/lib/shopify_api/resources/user.rb +1 -0
- data/lib/shopify_api/resources/variant.rb +35 -0
- data/lib/shopify_api/resources/webhook.rb +1 -0
- data/lib/shopify_api/resources.rb +1 -0
- data/lib/shopify_api/session.rb +51 -20
- data/lib/shopify_api/version.rb +2 -1
- data/lib/shopify_api.rb +9 -1
- data/lib/verify_docs.rb +8 -0
- data/service.yml +2 -5
- data/shopify_api.gemspec +13 -7
- data/test/access_token_test.rb +6 -5
- data/test/active_resource/json_errors_test.rb +6 -6
- data/test/api_access_test.rb +153 -0
- data/test/api_version_test.rb +3 -3
- data/test/application_charge_test.rb +30 -27
- data/test/application_credit_test.rb +10 -9
- data/test/article_test.rb +34 -35
- data/test/asset_test.rb +14 -6
- data/test/assigned_fulfillment_order_test.rb +5 -4
- data/test/base_test.rb +64 -49
- data/test/blog_test.rb +4 -3
- data/test/carrier_service_test.rb +7 -6
- data/test/cart_test.rb +2 -1
- data/test/collect_test.rb +4 -3
- data/test/collection_listing_test.rb +21 -16
- data/test/collection_publication_test.rb +8 -8
- data/test/collection_test.rb +20 -19
- data/test/countable_test.rb +3 -2
- data/test/currency_test.rb +5 -5
- data/test/custom_collection_test.rb +4 -3
- data/test/customer_saved_search_test.rb +18 -8
- data/test/customer_test.rb +22 -14
- data/test/detailed_log_subscriber_test.rb +16 -12
- data/test/discount_code_batch_test.rb +11 -10
- data/test/discount_code_test.rb +21 -15
- data/test/draft_order_test.rb +68 -52
- data/test/fixtures/assigned_fulfillment_orders.json +2 -0
- data/test/fixtures/fulfillment_order.json +1 -0
- data/test/fixtures/fulfillment_orders.json +2 -0
- data/test/fulfillment_event_test.rb +31 -26
- data/test/fulfillment_order_test.rb +217 -149
- data/test/fulfillment_order_test_helper.rb +1 -0
- data/test/fulfillment_request_test.rb +10 -8
- data/test/fulfillment_service_test.rb +13 -12
- data/test/fulfillment_test.rb +81 -66
- data/test/fulfillment_v2_test.rb +16 -12
- data/test/gift_card_test.rb +6 -4
- data/test/graphql_test.rb +55 -23
- data/test/hmac_params_test.rb +25 -0
- data/test/image_test.rb +19 -17
- data/test/inventory_level_test.rb +24 -15
- data/test/lib/webmock_extensions/last_request.rb +1 -1
- data/test/limits_test.rb +2 -1
- data/test/location_test.rb +2 -1
- data/test/marketing_event_test.rb +20 -20
- data/test/message_enricher_test.rb +6 -6
- data/test/meta_test.rb +9 -11
- data/test/metafield_test.rb +30 -20
- data/test/order_risk_test.rb +17 -16
- data/test/order_test.rb +43 -28
- data/test/pagination_test.rb +89 -56
- data/test/policy_test.rb +6 -5
- data/test/price_rule_test.rb +20 -15
- data/test/product_listing_test.rb +20 -20
- data/test/product_publication_test.rb +8 -8
- data/test/product_test.rb +71 -20
- data/test/publication_test.rb +3 -3
- data/test/recurring_application_charge_test.rb +104 -42
- data/test/redirect_test.rb +4 -3
- data/test/refund_test.rb +22 -17
- data/test/report_test.rb +12 -10
- data/test/resource_feedback_test.rb +14 -13
- data/test/script_tag_test.rb +10 -9
- data/test/session_test.rb +319 -45
- data/test/shipping_zone_test.rb +4 -3
- data/test/shop_test.rb +47 -33
- data/test/smart_collection_test.rb +5 -29
- data/test/storefront_access_token_test.rb +13 -15
- data/test/tax_service_test.rb +7 -4
- data/test/tender_transaction_test.rb +3 -3
- data/test/test_helper.rb +14 -12
- data/test/transaction_test.rb +4 -3
- data/test/usage_charge_test.rb +12 -8
- data/test/user_test.rb +4 -3
- data/test/variant_test.rb +50 -23
- data/test/webhook_test.rb +10 -7
- metadata +44 -17
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/.travis.yml +0 -23
- data/bin/shopify +0 -3
data/test/product_test.rb
CHANGED
@@ -1,47 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ProductTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
7
|
|
7
|
-
|
8
|
-
@product = ShopifyAPI::Product.find(632910392)
|
8
|
+
refresh_product
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_add_metafields_to_product
|
12
|
-
fake
|
13
|
-
|
14
|
-
field = @product.add_metafield(
|
15
|
-
|
16
|
-
|
17
|
-
assert_equal
|
18
|
-
|
19
|
-
|
12
|
+
fake("products/632910392/metafields", method: :post, status: 201, body: load_fixture('metafield'))
|
13
|
+
|
14
|
+
field = @product.add_metafield(
|
15
|
+
ShopifyAPI::Metafield.new(namespace: "contact", key: "email", value: "123@example.com", value_type: "string")
|
16
|
+
)
|
17
|
+
assert_equal(
|
18
|
+
ActiveSupport::JSON.decode(
|
19
|
+
'{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'
|
20
|
+
),
|
21
|
+
ActiveSupport::JSON.decode(WebMock.last_request.body)
|
22
|
+
)
|
23
|
+
assert(!field.new_record?)
|
24
|
+
assert_equal("contact", field.namespace)
|
25
|
+
assert_equal("email", field.key)
|
26
|
+
assert_equal("123@example.com", field.value)
|
20
27
|
end
|
21
28
|
|
22
29
|
def test_get_all_metafields_for_product
|
23
|
-
fake
|
30
|
+
fake("products/632910392/metafields", body: load_fixture('metafields'))
|
24
31
|
|
25
32
|
metafields = @product.metafields
|
26
33
|
|
27
|
-
assert_equal
|
28
|
-
assert
|
34
|
+
assert_equal(3, metafields.length)
|
35
|
+
assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
|
29
36
|
end
|
30
37
|
|
31
38
|
def test_get_2_metafields_for_product
|
32
|
-
body = ActiveSupport::JSON.decode
|
33
|
-
body['metafields'].slice!
|
39
|
+
body = ActiveSupport::JSON.decode(load_fixture('metafields'))
|
40
|
+
body['metafields'].slice!(2, 1)
|
34
41
|
|
35
|
-
fake
|
42
|
+
fake('products/632910392/metafields.json?limit=2', body: body.to_json, extension: false)
|
36
43
|
|
37
|
-
metafields = @product.metafields
|
44
|
+
metafields = @product.metafields(limit: 2)
|
38
45
|
|
39
|
-
assert_equal
|
40
|
-
assert
|
46
|
+
assert_equal(2, metafields.length)
|
47
|
+
assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
|
41
48
|
end
|
42
49
|
|
43
50
|
def test_update_loaded_variant
|
44
|
-
fake
|
51
|
+
fake("products/632910392/variants/808950810", method: :put, status: 200, body: load_fixture('variant'))
|
45
52
|
|
46
53
|
variant = @product.variants.first
|
47
54
|
variant.price = "0.50"
|
@@ -57,4 +64,48 @@ class ProductTest < Test::Unit::TestCase
|
|
57
64
|
|
58
65
|
assert_equal('100.00 - 199.00', @product.price_range)
|
59
66
|
end
|
67
|
+
|
68
|
+
def test_read_only_variant_inventory_fields_not_removed_in_2020_01
|
69
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
70
|
+
refresh_product(api_version: ShopifyAPI::Base.api_version)
|
71
|
+
|
72
|
+
variant = @product.variants.first
|
73
|
+
assert_equal(10, variant.inventory_quantity)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_deprecated_inventory_fields_are_removed_in_2020_01
|
77
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
78
|
+
refresh_product(api_version: ShopifyAPI::Base.api_version)
|
79
|
+
|
80
|
+
refute(@product.as_json.include?('total_inventory'))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_setting_product_total_inventory_passes_in_api_before_2019_10
|
84
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
85
|
+
refresh_product(api_version: ShopifyAPI::Base.api_version)
|
86
|
+
@product.total_inventory = 8
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_setting_product_total_inventory_fails_in_2019_10_api
|
90
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
91
|
+
refresh_product(api_version: ShopifyAPI::Base.api_version)
|
92
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
93
|
+
@product.total_inventory = 8
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_setting_product_total_inventory_fails_in_the_unstable_api
|
98
|
+
ShopifyAPI::Base.api_version = :unstable
|
99
|
+
refresh_product(api_version: ShopifyAPI::Base.api_version)
|
100
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
101
|
+
@product.total_inventory = 8
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def refresh_product(api_version: nil)
|
108
|
+
fake("products/632910392", body: load_fixture('product'), api_version: api_version)
|
109
|
+
@product = ShopifyAPI::Product.find(632910392)
|
110
|
+
end
|
60
111
|
end
|
data/test/publication_test.rb
CHANGED
@@ -3,10 +3,10 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class PublicationTest < Test::Unit::TestCase
|
5
5
|
def test_find_all_publications
|
6
|
-
fake
|
6
|
+
fake('publications')
|
7
7
|
publications = ShopifyAPI::Publication.find(:all)
|
8
8
|
|
9
|
-
assert_equal
|
10
|
-
assert_equal
|
9
|
+
assert_equal(55650051, publications.first.id)
|
10
|
+
assert_equal("Buy Button", publications.first.name)
|
11
11
|
end
|
12
12
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class RecurringApplicationChargeTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_recurring_application_charges_create
|
6
|
-
fake
|
6
|
+
fake(
|
7
|
+
"recurring_application_charges", method: :post, status: 201, body: load_fixture('recurring_application_charge')
|
8
|
+
)
|
7
9
|
|
8
10
|
charge = ShopifyAPI::RecurringApplicationCharge.create(
|
9
11
|
name: "Default Plan",
|
@@ -11,132 +13,192 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
|
|
11
13
|
return_url: "http://test.com/confirm"
|
12
14
|
)
|
13
15
|
|
14
|
-
assert_equal
|
16
|
+
assert_equal(
|
17
|
+
'http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?' \
|
18
|
+
'signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164',
|
19
|
+
charge.confirmation_url
|
20
|
+
)
|
15
21
|
end
|
16
22
|
|
17
23
|
def test_get_recurring_application_charges
|
18
|
-
fake
|
24
|
+
fake(
|
25
|
+
"recurring_application_charges/654381177",
|
26
|
+
method: :get,
|
27
|
+
status: 201,
|
28
|
+
body: load_fixture('recurring_application_charge')
|
29
|
+
)
|
19
30
|
|
20
31
|
charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
|
21
32
|
|
22
|
-
assert_equal
|
33
|
+
assert_equal("Super Duper Plan", charge.name)
|
23
34
|
end
|
24
35
|
|
25
36
|
def test_list_recurring_application_charges
|
26
|
-
fake
|
37
|
+
fake(
|
38
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
39
|
+
)
|
27
40
|
|
28
41
|
charge = ShopifyAPI::RecurringApplicationCharge.find(:all)
|
29
42
|
|
30
|
-
assert_equal
|
43
|
+
assert_equal("Super Mega Plan", charge.last.name)
|
31
44
|
end
|
32
45
|
|
33
46
|
def test_list_since_recurring_application_charges
|
34
|
-
fake
|
47
|
+
fake(
|
48
|
+
"recurring_application_charges.json?since_id=64512345",
|
49
|
+
extension: false,
|
50
|
+
method: :get,
|
51
|
+
status: 201,
|
52
|
+
body: load_fixture('recurring_application_charges')
|
53
|
+
)
|
35
54
|
|
36
55
|
charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { since_id: '64512345' })
|
37
56
|
|
38
|
-
assert_equal
|
57
|
+
assert_equal("Super Mega Plan", charge.last.name)
|
39
58
|
end
|
40
59
|
|
41
60
|
def test_list_fields_recurring_application_charges
|
42
|
-
fake
|
61
|
+
fake(
|
62
|
+
"recurring_application_charges.json?fields=name",
|
63
|
+
extension: false,
|
64
|
+
method: :get,
|
65
|
+
status: 201,
|
66
|
+
body: load_fixture('recurring_application_charges')
|
67
|
+
)
|
43
68
|
|
44
69
|
charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { fields: 'name' })
|
45
70
|
|
46
|
-
assert_equal
|
71
|
+
assert_equal("Super Mega Plan", charge.last.name)
|
47
72
|
end
|
48
73
|
|
49
74
|
def test_pending_recurring_application_charge
|
50
|
-
fake
|
75
|
+
fake(
|
76
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
77
|
+
)
|
51
78
|
|
52
79
|
charge = ShopifyAPI::RecurringApplicationCharge.pending
|
53
80
|
|
54
|
-
assert_equal
|
81
|
+
assert_equal("Super Mega Plan2", charge.last.name)
|
55
82
|
end
|
56
83
|
|
57
84
|
def test_cancelled_recurring_application_charge
|
58
|
-
fake
|
85
|
+
fake(
|
86
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
87
|
+
)
|
59
88
|
|
60
89
|
charge = ShopifyAPI::RecurringApplicationCharge.cancelled
|
61
90
|
|
62
|
-
assert_equal
|
91
|
+
assert_equal("Super Mega Plan3", charge.last.name)
|
63
92
|
end
|
64
93
|
|
65
94
|
def test_accepted_recurring_application_charge
|
66
|
-
fake
|
95
|
+
fake(
|
96
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
97
|
+
)
|
67
98
|
|
68
99
|
charge = ShopifyAPI::RecurringApplicationCharge.accepted
|
69
100
|
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
101
|
+
assert_equal("Super Mega Plan4", charge.first.name)
|
102
|
+
assert_equal("Super Mega Plan", charge.last.name)
|
72
103
|
end
|
73
104
|
|
74
105
|
def test_declined_recurring_application_charge
|
75
|
-
fake
|
106
|
+
fake(
|
107
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
108
|
+
)
|
76
109
|
|
77
110
|
charge = ShopifyAPI::RecurringApplicationCharge.declined
|
78
111
|
|
79
|
-
assert_equal
|
112
|
+
assert_equal("Super Mega Plan5", charge.last.name)
|
80
113
|
end
|
81
114
|
|
82
115
|
def test_activate_recurring_application_charge
|
83
|
-
fake
|
84
|
-
|
116
|
+
fake(
|
117
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
118
|
+
)
|
119
|
+
fake("recurring_application_charges/455696199/activate", method: :post, status: 200, body: "{}")
|
85
120
|
|
86
121
|
charge = ShopifyAPI::RecurringApplicationCharge.accepted
|
87
122
|
|
88
|
-
assert
|
123
|
+
assert(charge.last.activate)
|
89
124
|
end
|
90
125
|
|
91
126
|
def test_adjust_recurring_application_charge
|
92
|
-
fake
|
93
|
-
|
127
|
+
fake(
|
128
|
+
"recurring_application_charges/654381177",
|
129
|
+
method: :get,
|
130
|
+
status: 201,
|
131
|
+
body: load_fixture('recurring_application_charge')
|
132
|
+
)
|
133
|
+
fake(
|
134
|
+
"recurring_application_charges/654381177/customize.json?recurring_application_charge%5Bcapped_amount%5D=200",
|
135
|
+
method: :put,
|
136
|
+
body: load_fixture('recurring_application_charge_adjustment'),
|
137
|
+
extension: false
|
138
|
+
)
|
94
139
|
|
95
140
|
charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
|
96
141
|
|
97
|
-
assert
|
142
|
+
assert(charge.customize(capped_amount: 200))
|
98
143
|
end
|
99
144
|
|
100
145
|
def test_cancel_recurring_application_charge
|
101
|
-
fake
|
102
|
-
|
146
|
+
fake(
|
147
|
+
"recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
|
148
|
+
)
|
149
|
+
fake("recurring_application_charges/455696194", method: :delete, status: 200, body: "{}")
|
103
150
|
|
104
151
|
charge = ShopifyAPI::RecurringApplicationCharge.current
|
105
|
-
assert
|
152
|
+
assert(charge.cancel)
|
106
153
|
end
|
107
154
|
|
108
155
|
def test_usage_charges_recurring_application_charge_found
|
109
|
-
fake
|
110
|
-
|
156
|
+
fake(
|
157
|
+
"recurring_application_charges/654381177",
|
158
|
+
method: :get,
|
159
|
+
status: 201,
|
160
|
+
body: load_fixture('recurring_application_charge')
|
161
|
+
)
|
162
|
+
fake(
|
163
|
+
"recurring_application_charges/654381177/usage_charges",
|
164
|
+
method: :get,
|
165
|
+
status: 201,
|
166
|
+
body: load_fixture('usage_charges')
|
167
|
+
)
|
111
168
|
|
112
169
|
charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
|
113
170
|
usage_charges = charge.usage_charges
|
114
171
|
|
115
|
-
assert_equal
|
172
|
+
assert_equal(2, usage_charges.length)
|
116
173
|
end
|
117
174
|
|
118
175
|
def test_usage_charges_recurring_application_charge_not_found
|
119
|
-
fake
|
120
|
-
|
176
|
+
fake(
|
177
|
+
"recurring_application_charges/654381177",
|
178
|
+
method: :get,
|
179
|
+
status: 201,
|
180
|
+
body: load_fixture('recurring_application_charge')
|
181
|
+
)
|
182
|
+
fake("recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: "[]")
|
121
183
|
|
122
184
|
charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
|
123
185
|
usage_charges = charge.usage_charges
|
124
186
|
|
125
|
-
assert_equal
|
187
|
+
assert_equal(0, usage_charges.length)
|
126
188
|
end
|
127
189
|
|
128
190
|
def test_no_recurring_application_charge_found
|
129
|
-
fake
|
191
|
+
fake("recurring_application_charges", body: { recurring_application_charges: [] }.to_json)
|
130
192
|
|
131
|
-
assert_equal
|
132
|
-
assert_nil
|
133
|
-
assert_equal
|
193
|
+
assert_equal(0, ShopifyAPI::RecurringApplicationCharge.all.count)
|
194
|
+
assert_nil(ShopifyAPI::RecurringApplicationCharge.current)
|
195
|
+
assert_equal([], ShopifyAPI::RecurringApplicationCharge.pending)
|
134
196
|
end
|
135
197
|
|
136
198
|
def test_recurring_application_charge_not_found_error
|
137
|
-
fake
|
138
|
-
assert_nil
|
139
|
-
assert_nil
|
199
|
+
fake("recurring_application_charges", body: '{"errors":"Not Found"}', status: 404)
|
200
|
+
assert_nil(ShopifyAPI::RecurringApplicationCharge.all)
|
201
|
+
assert_nil(ShopifyAPI::RecurringApplicationCharge.current)
|
140
202
|
assert_equal([], ShopifyAPI::RecurringApplicationCharge.pending)
|
141
203
|
end
|
142
204
|
end
|
data/test/redirect_test.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class RedirectTest < Test::Unit::TestCase
|
4
5
|
test "#create should create a redirect" do
|
5
|
-
fake
|
6
|
-
redirect = ShopifyAPI::Redirect.create(:
|
7
|
-
assert_equal
|
6
|
+
fake("redirects", method: :post, status: 201, body: load_fixture('redirect'))
|
7
|
+
redirect = ShopifyAPI::Redirect.create(path: "/ipod", target: "/pages/itunes")
|
8
|
+
assert_equal(979034150, redirect.id)
|
8
9
|
end
|
9
10
|
end
|
data/test/refund_test.rb
CHANGED
@@ -1,32 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class RefundTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
test '#create should create a refund' do
|
6
|
-
fake
|
6
|
+
fake("orders/450789469/refunds", method: :post, status: 201, body: load_fixture('refund'))
|
7
7
|
refund = ShopifyAPI::Refund.create(
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
8
|
+
order_id: 450789469,
|
9
|
+
restock: true,
|
10
|
+
note: "wrong size",
|
11
|
+
shipping: { full_refund: true },
|
12
|
+
refund_line_items: [{ line_item_id: 518995019, quantity: 1 }]
|
13
13
|
)
|
14
|
-
assert_equal
|
14
|
+
assert_equal(703073504, refund.refund_line_items.first.line_item_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
test '#find should return a refund' do
|
18
|
-
fake
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
fake(
|
19
|
+
"orders/450789469/refunds/509562969.json?order_id=450789469",
|
20
|
+
extension: false,
|
21
|
+
method: :get,
|
22
|
+
body: load_fixture('refund')
|
23
|
+
)
|
24
|
+
fake("orders/450789469/refunds/509562969", method: :get, body: load_fixture('refund'))
|
25
|
+
refund = ShopifyAPI::Refund.find(509562969, params: { order_id: 450789469 })
|
26
|
+
assert_equal(509562969, refund.id)
|
22
27
|
end
|
23
28
|
|
24
29
|
test '#calculate a refund' do
|
25
|
-
fake
|
26
|
-
data = { :
|
30
|
+
fake("orders/450789469/refunds/calculate", method: :post, body: load_fixture('refund'))
|
31
|
+
data = { shipping: { amount: 0 } }
|
27
32
|
|
28
|
-
refund = ShopifyAPI::Refund.calculate(data, :
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
33
|
+
refund = ShopifyAPI::Refund.calculate(data, params: { order_id: 450789469 })
|
34
|
+
assert_equal(2, refund.refund_line_items.count)
|
35
|
+
assert_equal(703073504, refund.refund_line_items.first.line_item_id)
|
31
36
|
end
|
32
37
|
end
|
data/test/report_test.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ReportTest < Test::Unit::TestCase
|
4
5
|
test 'get should get a report' do
|
5
|
-
fake
|
6
|
+
fake('reports/987', method: :get, status: 200, body: load_fixture('report'))
|
6
7
|
|
7
8
|
report = ShopifyAPI::Report.find(987)
|
8
|
-
assert_equal
|
9
|
+
assert_equal(987, report.id)
|
9
10
|
end
|
10
11
|
|
11
12
|
test 'get all should get all reports' do
|
12
|
-
fake
|
13
|
+
fake('reports', method: :get, status: 200, body: load_fixture('reports'))
|
13
14
|
|
14
15
|
reports = ShopifyAPI::Report.all
|
15
|
-
assert_equal
|
16
|
+
assert_equal('custom_app_reports', reports.first.category)
|
16
17
|
end
|
17
18
|
|
18
19
|
test 'create should create a report' do
|
19
|
-
fake
|
20
|
+
fake('reports', method: :post, status: 201, body: load_fixture('report'))
|
20
21
|
|
21
22
|
report = ShopifyAPI::Report.create(
|
22
23
|
name: 'Custom App Report',
|
23
|
-
shopify_ql: 'SHOW quantity_count, total_sales BY product_type, vendor, product_title
|
24
|
+
shopify_ql: 'SHOW quantity_count, total_sales BY product_type, vendor, product_title ' \
|
25
|
+
'FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC'
|
24
26
|
)
|
25
|
-
assert_equal
|
27
|
+
assert_equal('custom_app_reports', report.category)
|
26
28
|
end
|
27
29
|
|
28
30
|
test 'delete should delete report' do
|
29
|
-
fake
|
30
|
-
fake
|
31
|
+
fake('reports/987', method: :get, status: 200, body: load_fixture('report'))
|
32
|
+
fake('reports/987', method: :delete, status: 200, body: '[]')
|
31
33
|
|
32
34
|
report = ShopifyAPI::Report.find(987)
|
33
|
-
assert
|
35
|
+
assert(report.destroy)
|
34
36
|
end
|
35
37
|
end
|
@@ -1,41 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class ResourceFeedbackTest < Test::Unit::TestCase
|
2
3
|
def test_get_resource_feedback
|
3
|
-
body = { resource_feedback: [
|
4
|
-
fake
|
4
|
+
body = { resource_feedback: [{ resource_type: 'Shop' }] }.to_json
|
5
|
+
fake('resource_feedback', method: :get, body: body)
|
5
6
|
resource_feedback = ShopifyAPI::ResourceFeedback.find(:all)
|
6
|
-
assert_equal
|
7
|
+
assert_equal('Shop', resource_feedback.first.resource_type)
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_save_with_resource_feedback_endpoint
|
10
11
|
body = { resource_feedback: {} }.to_json
|
11
|
-
fake
|
12
|
+
fake('resource_feedback', method: :post, body: body)
|
12
13
|
ShopifyAPI::ResourceFeedback.new.save
|
13
|
-
assert_request_body
|
14
|
+
assert_request_body(body)
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_get_resource_feedback_with_product_id
|
17
|
-
body = { resource_feedback: [
|
18
|
-
fake
|
18
|
+
body = { resource_feedback: [{ resource_type: 'Product' }] }.to_json
|
19
|
+
fake('products/42/resource_feedback', method: :get, body: body)
|
19
20
|
resource_feedback = ShopifyAPI::ResourceFeedback.find(:all, params: { product_id: 42 })
|
20
|
-
assert_equal
|
21
|
+
assert_equal('Product', resource_feedback.first.resource_type)
|
21
22
|
end
|
22
23
|
|
23
24
|
def test_save_with_product_id_resource_feedback_endpoint
|
24
25
|
body = { resource_feedback: {} }.to_json
|
25
|
-
fake
|
26
|
+
fake('products/42/resource_feedback', method: :post, body: body)
|
26
27
|
ShopifyAPI::ResourceFeedback.new(product_id: 42).save
|
27
|
-
assert_request_body
|
28
|
+
assert_request_body(body)
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_save_raises_exception_when_already_persisted
|
31
32
|
body = { resource_feedback: {} }.to_json
|
32
|
-
fake
|
33
|
+
fake('resource_feedback', method: :post, body: body)
|
33
34
|
resource_feedback = ShopifyAPI::ResourceFeedback.new
|
34
35
|
resource_feedback.save
|
35
|
-
assert_request_body
|
36
|
+
assert_request_body(body)
|
36
37
|
|
37
38
|
ShopifyAPI::ResourceFeedback.any_instance.expects(:persisted?).returns(true)
|
38
|
-
assert_raises
|
39
|
+
assert_raises(ShopifyAPI::ResourceFeedback::ExistingFeedbackSaved) do
|
39
40
|
resource_feedback.save
|
40
41
|
end
|
41
42
|
end
|
data/test/script_tag_test.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ScriptTagTest < Test::Unit::TestCase
|
4
5
|
test "get all should get all script tags" do
|
5
|
-
fake
|
6
|
+
fake('script_tags', method: :get, status: 200, body: load_fixture('script_tags'))
|
6
7
|
script_tags = ShopifyAPI::ScriptTag.all
|
7
|
-
assert_equal
|
8
|
+
assert_equal("http://js-aplenty.com/bar.js", script_tags.first.src)
|
8
9
|
end
|
9
10
|
|
10
11
|
test "get should get a script tag" do
|
11
|
-
fake
|
12
|
+
fake('script_tags/421379493', method: :get, status: 200, body: load_fixture('script_tag'))
|
12
13
|
script_tag = ShopifyAPI::ScriptTag.find(421379493)
|
13
|
-
assert_equal
|
14
|
+
assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
|
14
15
|
end
|
15
16
|
|
16
17
|
test "create should create a new script tag" do
|
17
|
-
fake
|
18
|
+
fake('script_tags', method: :post, status: 201, body: load_fixture('script_tag'))
|
18
19
|
script_tag = ShopifyAPI::ScriptTag.create(event: "onload", src: "http://js-aplenty.com/bar.js")
|
19
|
-
assert_equal
|
20
|
+
assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
|
20
21
|
end
|
21
22
|
|
22
23
|
test "editing script tag should update script tag" do
|
23
|
-
fake
|
24
|
+
fake('script_tags/421379493', method: :get, status: 200, body: load_fixture('script_tag'))
|
24
25
|
script_tag = ShopifyAPI::ScriptTag.find(421379493)
|
25
26
|
script_tag.src = "http://js-aplenty.com/bar.js"
|
26
|
-
fake
|
27
|
+
fake('script_tags/421379493', method: :put, status: 200, body: load_fixture('script_tag'))
|
27
28
|
script_tag.save
|
28
|
-
assert_equal
|
29
|
+
assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
|
29
30
|
end
|
30
31
|
end
|