shopify_api 4.9.0 → 9.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/probots.yml +2 -0
- data/.github/workflows/build.yml +41 -0
- data/.gitignore +5 -1
- data/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +491 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +6 -2
- data/Gemfile.lock +151 -0
- data/Gemfile_ar41 +5 -0
- data/Gemfile_ar50 +5 -0
- data/Gemfile_ar51 +5 -0
- data/Gemfile_ar_master +0 -1
- data/README.md +492 -100
- data/RELEASING +10 -9
- data/Rakefile +21 -5
- data/SECURITY.md +59 -0
- data/docker-compose.yml +13 -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 +241 -0
- data/docs/index.md +639 -0
- data/lib/active_resource/connection_ext.rb +1 -0
- data/lib/active_resource/detailed_log_subscriber.rb +43 -7
- data/lib/active_resource/json_errors.rb +8 -2
- data/lib/shopify_api.rb +16 -6
- data/lib/shopify_api/api_access.rb +57 -0
- data/lib/shopify_api/api_version.rb +206 -0
- data/lib/shopify_api/connection.rb +7 -4
- data/lib/shopify_api/countable.rb +3 -2
- data/lib/shopify_api/disable_prefix_check.rb +31 -0
- data/lib/shopify_api/events.rb +2 -1
- data/lib/shopify_api/graphql.rb +103 -0
- data/lib/shopify_api/graphql/http_client.rb +22 -0
- data/lib/shopify_api/graphql/railtie.rb +17 -0
- data/lib/shopify_api/graphql/task.rake +100 -0
- data/lib/shopify_api/limits.rb +9 -9
- data/lib/shopify_api/message_enricher.rb +25 -0
- data/lib/shopify_api/meta.rb +14 -0
- data/lib/shopify_api/metafields.rb +5 -4
- data/lib/shopify_api/paginated_collection.rb +69 -0
- data/lib/shopify_api/pagination_link_headers.rb +34 -0
- data/lib/shopify_api/resources.rb +3 -1
- data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
- data/lib/shopify_api/resources/access_scope.rb +10 -0
- 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/api_permission.rb +9 -0
- 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/array_base.rb +13 -0
- data/lib/shopify_api/resources/article.rb +3 -2
- data/lib/shopify_api/resources/asset.rb +28 -23
- data/lib/shopify_api/resources/assigned_fulfillment_order.rb +16 -0
- data/lib/shopify_api/resources/base.rb +101 -24
- data/lib/shopify_api/resources/billing_address.rb +2 -1
- 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/checkout.rb +27 -1
- data/lib/shopify_api/resources/collect.rb +2 -0
- data/lib/shopify_api/resources/collection.rb +14 -0
- data/lib/shopify_api/resources/collection_listing.rb +11 -1
- data/lib/shopify_api/resources/collection_publication.rb +10 -0
- data/lib/shopify_api/resources/comment.rb +20 -5
- data/lib/shopify_api/resources/country.rb +1 -0
- data/lib/shopify_api/resources/currency.rb +6 -0
- data/lib/shopify_api/resources/custom_collection.rb +7 -6
- 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_message.rb → customer_invite.rb} +1 -0
- data/lib/shopify_api/resources/customer_saved_search.rb +4 -1
- data/lib/shopify_api/resources/discount_code.rb +1 -0
- data/lib/shopify_api/resources/discount_code_batch.rb +34 -0
- 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 +2 -0
- data/lib/shopify_api/resources/fulfillment.rb +46 -3
- data/lib/shopify_api/resources/fulfillment_event.rb +2 -1
- data/lib/shopify_api/resources/fulfillment_order.rb +151 -0
- data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +5 -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 +21 -0
- data/lib/shopify_api/resources/gift_card.rb +1 -0
- data/lib/shopify_api/resources/image.rb +4 -3
- data/lib/shopify_api/resources/inventory_item.rb +6 -0
- data/lib/shopify_api/resources/inventory_level.rb +54 -0
- data/lib/shopify_api/resources/line_item.rb +10 -1
- data/lib/shopify_api/resources/location.rb +4 -0
- data/lib/shopify_api/resources/marketing_event.rb +3 -0
- data/lib/shopify_api/resources/metafield.rb +2 -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 +25 -5
- 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.rb +7 -0
- data/lib/shopify_api/resources/payment_details.rb +1 -0
- data/lib/shopify_api/resources/ping.rb +3 -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 +33 -7
- data/lib/shopify_api/resources/product_listing.rb +9 -1
- data/lib/shopify_api/resources/product_publication.rb +10 -0
- data/lib/shopify_api/resources/province.rb +1 -0
- data/lib/shopify_api/resources/publication.rb +5 -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 +6 -4
- 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 +2 -1
- data/lib/shopify_api/resources/shipping_rate.rb +7 -0
- data/lib/shopify_api/resources/shipping_zone.rb +1 -0
- data/lib/shopify_api/resources/shop.rb +10 -7
- data/lib/shopify_api/resources/smart_collection.rb +3 -3
- 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/tender_transaction.rb +6 -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/session.rb +109 -45
- data/lib/shopify_api/version.rb +2 -1
- data/lib/verify_docs.rb +8 -0
- data/service.yml +8 -0
- data/shopify_api.gemspec +19 -8
- data/test/abandoned_checkouts_test.rb +29 -0
- data/test/access_scope_test.rb +23 -0
- 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_permission_test.rb +9 -0
- data/test/api_version_test.rb +157 -0
- 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 +78 -0
- data/test/base_test.rb +147 -59
- data/test/blog_test.rb +4 -3
- data/test/carrier_service_test.rb +7 -6
- data/test/cart_test.rb +2 -1
- data/test/checkouts_test.rb +72 -4
- data/test/collect_test.rb +4 -3
- data/test/collection_listing_test.rb +56 -13
- data/test/collection_publication_test.rb +40 -0
- data/test/collection_test.rb +50 -0
- data/test/countable_test.rb +3 -2
- data/test/currency_test.rb +21 -0
- 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 +113 -19
- data/test/discount_code_batch_test.rb +41 -0
- data/test/discount_code_test.rb +22 -16
- data/test/draft_order_test.rb +68 -52
- data/test/fixtures/abandoned_checkout.json +184 -0
- data/test/fixtures/abandoned_checkouts.json +186 -0
- data/test/fixtures/access_scopes.json +10 -0
- data/test/fixtures/api_versions.json +38 -0
- data/test/fixtures/apis.json +42 -0
- data/test/fixtures/assigned_fulfillment_orders.json +80 -0
- data/test/fixtures/checkout.json +160 -0
- data/test/fixtures/checkouts.json +25 -49
- data/test/fixtures/collection.json +17 -0
- data/test/fixtures/collection_listing_product_ids2.json +1 -0
- data/test/fixtures/collection_products.json +47 -0
- data/test/fixtures/collection_publication.json +11 -0
- data/test/fixtures/collection_publications.json +13 -0
- data/test/fixtures/currencies.json +25 -0
- data/test/fixtures/discount_code_batch.json +14 -0
- data/test/fixtures/discount_code_batch_discount_codes.json +21 -0
- data/test/fixtures/fulfillment_order.json +39 -0
- data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
- data/test/fixtures/fulfillment_orders.json +80 -0
- data/test/fixtures/fulfillments.json +53 -0
- data/test/fixtures/graphql/2019-10.json +1083 -0
- data/test/fixtures/graphql/dummy_schema.rb +16 -0
- data/test/fixtures/graphql/unstable.json +1083 -0
- data/test/fixtures/inventory_level.json +7 -0
- data/test/fixtures/inventory_levels.json +24 -0
- data/test/fixtures/order_with_properties.json +373 -0
- data/test/fixtures/payment.json +7 -0
- data/test/fixtures/payments.json +9 -0
- data/test/fixtures/ping/conversation.json +1 -0
- data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
- data/test/fixtures/ping/message.json +1 -0
- data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
- data/test/fixtures/product_listing_product_ids.json +1 -1
- data/test/fixtures/product_listing_product_ids2.json +1 -0
- data/test/fixtures/product_publication.json +11 -0
- data/test/fixtures/product_publications.json +13 -0
- data/test/fixtures/publications.json +9 -0
- data/test/fixtures/shipping_rates.json +12 -0
- data/test/fixtures/smart_collection_products.json +155 -0
- data/test/fixtures/tender_transactions.json +52 -0
- data/test/fulfillment_event_test.rb +31 -26
- data/test/fulfillment_order_test.rb +530 -0
- data/test/fulfillment_order_test_helper.rb +8 -0
- data/test/fulfillment_request_test.rb +10 -8
- data/test/fulfillment_service_test.rb +13 -12
- data/test/fulfillment_test.rb +198 -20
- data/test/fulfillment_v2_test.rb +66 -0
- data/test/gift_card_test.rb +6 -4
- data/test/graphql/http_client_test.rb +26 -0
- data/test/graphql_test.rb +190 -0
- data/test/image_test.rb +19 -17
- data/test/inventory_level_test.rb +68 -0
- data/test/lib/webmock_extensions/last_request.rb +16 -0
- data/test/limits_test.rb +4 -3
- data/test/location_test.rb +15 -0
- data/test/marketing_event_test.rb +21 -21
- data/test/message_enricher_test.rb +45 -0
- data/test/meta_test.rb +47 -0
- data/test/metafield_test.rb +30 -20
- data/test/order_risk_test.rb +17 -16
- data/test/order_test.rb +110 -17
- data/test/pagination_test.rb +290 -0
- data/test/payment_test.rb +19 -0
- data/test/policy_test.rb +6 -5
- data/test/price_rule_test.rb +20 -15
- data/test/product_listing_test.rb +72 -15
- data/test/product_publication_test.rb +40 -0
- data/test/product_test.rb +80 -19
- data/test/publication_test.rb +12 -0
- data/test/recurring_application_charge_test.rb +105 -50
- 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 +497 -111
- data/test/shipping_rate_test.rb +17 -0
- data/test/shipping_zone_test.rb +4 -3
- data/test/shop_test.rb +47 -33
- data/test/smart_collection_test.rb +5 -4
- data/test/storefront_access_token_test.rb +13 -15
- data/test/tax_service_test.rb +7 -3
- data/test/tender_transaction_test.rb +18 -0
- data/test/test_helper.rb +98 -67
- 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 -20
- data/test/webhook_test.rb +10 -7
- metadata +196 -37
- data/.travis.yml +0 -36
- data/CHANGELOG +0 -292
- data/Gemfile_ar30 +0 -6
- data/Gemfile_ar31 +0 -6
- data/Gemfile_ar32 +0 -6
- data/Gemfile_ar40 +0 -6
- data/bin/shopify +0 -3
- data/lib/active_resource/base_ext.rb +0 -21
- data/lib/active_resource/disable_prefix_check.rb +0 -36
- data/lib/active_resource/to_query.rb +0 -10
- data/lib/shopify_api/json_format.rb +0 -18
- data/lib/shopify_api/resources/discount.rb +0 -11
- data/lib/shopify_api/resources/o_auth.rb +0 -9
- data/test/discount_test.rb +0 -52
- data/test/fixtures/discount.json +0 -17
- data/test/fixtures/discount_disabled.json +0 -17
- data/test/fixtures/discounts.json +0 -34
- data/test/fixtures/o_auth_revoke.json +0 -5
- data/test/o_auth_test.rb +0 -8
@@ -1,79 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ApplicationChargeTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_application_charge_create
|
6
|
-
fake
|
6
|
+
fake("application_charges", method: :post, status: 201, body: load_fixture('application_charge'))
|
7
7
|
|
8
8
|
charge = ShopifyAPI::ApplicationCharge.create(
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
name: "iPod Cleaning",
|
10
|
+
price: 5.00,
|
11
|
+
return_url: "http://google.com"
|
12
12
|
)
|
13
13
|
|
14
|
-
assert_equal
|
14
|
+
assert_equal(
|
15
|
+
'https://this-is-my-test-shop.myshopify.com/admin/charges/803742/confirm_application_charge?' \
|
16
|
+
'signature=BAhpA55DDA%3D%3D--55b44e274e438c619be4631c804abcbcb6ee915a',
|
17
|
+
charge.confirmation_url
|
18
|
+
)
|
15
19
|
end
|
16
20
|
|
17
21
|
def test_get_application_charge
|
18
|
-
fake
|
22
|
+
fake("application_charges/803742", method: :get, status: 201, body: load_fixture('application_charge'))
|
19
23
|
|
20
24
|
charge = ShopifyAPI::ApplicationCharge.find(803742)
|
21
25
|
|
22
|
-
assert_equal
|
26
|
+
assert_equal("iPod Cleaning", charge.name)
|
23
27
|
end
|
24
28
|
|
25
29
|
def test_list_application_charges
|
26
|
-
fake
|
30
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
27
31
|
|
28
32
|
charges = ShopifyAPI::ApplicationCharge.find(:all)
|
29
33
|
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
34
|
+
assert_equal(4, charges.size)
|
35
|
+
assert_equal("iPhone Case", charges.last.name)
|
32
36
|
end
|
33
37
|
|
34
38
|
def test_list_pending_application_charges
|
35
|
-
fake
|
39
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
36
40
|
|
37
41
|
pending_charges = ShopifyAPI::ApplicationCharge.pending
|
38
42
|
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
43
|
+
assert_equal(1, pending_charges.size)
|
44
|
+
assert_equal("Screen Replacement", pending_charges.first.name)
|
41
45
|
end
|
42
46
|
|
43
47
|
def test_list_expired_application_charges
|
44
|
-
fake
|
48
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
45
49
|
|
46
50
|
expired_charges = ShopifyAPI::ApplicationCharge.expired
|
47
51
|
|
48
|
-
assert_equal
|
49
|
-
assert_equal
|
52
|
+
assert_equal(1, expired_charges.size)
|
53
|
+
assert_equal("iPod Cleaning", expired_charges.first.name)
|
50
54
|
end
|
51
55
|
|
52
56
|
def test_list_accepted_application_charges
|
53
|
-
fake
|
57
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
54
58
|
|
55
59
|
accepted_charges = ShopifyAPI::ApplicationCharge.accepted
|
56
60
|
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
61
|
+
assert_equal(1, accepted_charges.size)
|
62
|
+
assert_equal("iPhone Case", accepted_charges.first.name)
|
59
63
|
end
|
60
64
|
|
61
65
|
def test_list_declined_application_charges
|
62
|
-
fake
|
66
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
63
67
|
|
64
68
|
declined_charges = ShopifyAPI::ApplicationCharge.declined
|
65
69
|
|
66
|
-
assert_equal
|
67
|
-
assert_equal
|
70
|
+
assert_equal(1, declined_charges.size)
|
71
|
+
assert_equal("Magic Mouse", declined_charges.first.name)
|
68
72
|
end
|
69
73
|
|
70
74
|
def test_activate_application_charge
|
71
|
-
fake
|
72
|
-
fake
|
75
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
76
|
+
fake("application_charges/803740/activate", method: :post, status: 200, body: "{}")
|
73
77
|
|
74
78
|
charge = ShopifyAPI::ApplicationCharge.accepted
|
75
79
|
|
76
|
-
assert
|
80
|
+
assert(charge.last.activate)
|
77
81
|
end
|
78
|
-
|
79
82
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ApplicationCreditTest < Test::Unit::TestCase
|
4
5
|
def test_application_credit_create
|
5
|
-
fake
|
6
|
+
fake("application_credits", method: :post, status: 201, body: load_fixture('application_credit'))
|
6
7
|
|
7
8
|
credit = ShopifyAPI::ApplicationCredit.create(
|
8
9
|
description: "refund for application charge",
|
@@ -11,25 +12,25 @@ class ApplicationCreditTest < Test::Unit::TestCase
|
|
11
12
|
shop_id: 487168
|
12
13
|
)
|
13
14
|
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
15
|
+
assert_equal('refund for application charge', credit.description)
|
16
|
+
assert_equal('5.00', credit.amount)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_get_application_credit
|
19
|
-
fake
|
20
|
+
fake("application_credits/803742", method: :get, status: 201, body: load_fixture('application_credit'))
|
20
21
|
|
21
22
|
credit = ShopifyAPI::ApplicationCredit.find(803742)
|
22
23
|
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
24
|
+
assert_equal('refund for application charge', credit.description)
|
25
|
+
assert_equal('5.00', credit.amount)
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_list_application_credits
|
28
|
-
fake
|
29
|
+
fake("application_credits", method: :get, status: 201, body: load_fixture('application_credits'))
|
29
30
|
|
30
31
|
credit = ShopifyAPI::ApplicationCredit.find(:all)
|
31
32
|
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
33
|
+
assert_equal(2, credit.size)
|
34
|
+
assert_equal('10.00', credit.last.amount)
|
34
35
|
end
|
35
36
|
end
|
data/test/article_test.rb
CHANGED
@@ -1,73 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ArticleTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_create_article
|
6
|
-
fake
|
7
|
-
article = ShopifyAPI::Article.new(:
|
6
|
+
fake("blogs/1008414260/articles", method: :post, body: load_fixture('article'))
|
7
|
+
article = ShopifyAPI::Article.new(blog_id: 1008414260)
|
8
8
|
article.save
|
9
|
-
assert_equal
|
9
|
+
assert_equal("First Post", article.title)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_get_article
|
13
|
-
fake
|
13
|
+
fake("articles/6242736", method: :get, body: load_fixture('article'))
|
14
14
|
article = ShopifyAPI::Article.find(6242736)
|
15
|
-
assert_equal
|
16
|
-
assert_equal
|
15
|
+
assert_equal("First Post", article.title)
|
16
|
+
assert_equal(1008414260, article.blog_id)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_get_articles
|
20
|
-
fake
|
20
|
+
fake("articles", method: :get, body: load_fixture('articles'))
|
21
21
|
articles = ShopifyAPI::Article.all
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
22
|
+
assert_equal(3, articles.length)
|
23
|
+
assert_equal(1008414260, articles.first.blog_id)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_get_articles_namespaced
|
27
|
-
fake
|
28
|
-
articles = ShopifyAPI::Article.find(:all, :
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
27
|
+
fake("blogs/1008414260/articles", method: :get, body: load_fixture('articles'))
|
28
|
+
articles = ShopifyAPI::Article.find(:all, params: { blog_id: 1008414260 })
|
29
|
+
assert_equal(3, articles.length)
|
30
|
+
assert_equal(1008414260, articles.first.blog_id)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_get_article_namespaced
|
34
|
-
fake
|
35
|
-
article = ShopifyAPI::Article.find(6242736, :
|
36
|
-
assert_equal
|
37
|
-
assert_equal
|
34
|
+
fake("blogs/1008414260/articles/6242736", method: :get, body: load_fixture('article'))
|
35
|
+
article = ShopifyAPI::Article.find(6242736, params: { blog_id: 1008414260 })
|
36
|
+
assert_equal("First Post", article.title)
|
37
|
+
assert_equal(1008414260, article.blog_id)
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_get_authors
|
41
|
-
fake
|
41
|
+
fake("articles/authors", method: :get, body: load_fixture('authors'))
|
42
42
|
authors = ShopifyAPI::Article.authors
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
43
|
+
assert_equal("Shopify", authors.first)
|
44
|
+
assert_equal("development shop", authors.last)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_get_authors_for_blog_id
|
48
|
-
fake
|
49
|
-
authors = ShopifyAPI::Article.authors(:
|
50
|
-
assert_equal
|
48
|
+
fake("blogs/1008414260/articles/authors", method: :get, body: load_fixture('authors'))
|
49
|
+
authors = ShopifyAPI::Article.authors(blog_id: 1008414260)
|
50
|
+
assert_equal(3, authors.length)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_get_tags
|
54
|
-
fake
|
54
|
+
fake("articles/tags", method: :get, body: load_fixture('tags'))
|
55
55
|
tags = ShopifyAPI::Article.tags
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
56
|
+
assert_equal("consequuntur", tags.first)
|
57
|
+
assert_equal("repellendus", tags.last)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_get_tags_for_blog_id
|
61
|
-
fake
|
62
|
-
tags = ShopifyAPI::Article.tags(:
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
61
|
+
fake("blogs/1008414260/articles/tags", method: :get, body: load_fixture('tags'))
|
62
|
+
tags = ShopifyAPI::Article.tags(blog_id: 1008414260)
|
63
|
+
assert_equal("consequuntur", tags.first)
|
64
|
+
assert_equal("repellendus", tags.last)
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_get_popular_tags
|
68
|
-
fake
|
69
|
-
tags = ShopifyAPI::Article.tags(:
|
70
|
-
assert_equal
|
68
|
+
fake("articles/tags.json?limit=1&popular=1", extension: false, method: :get, body: load_fixture('tags'))
|
69
|
+
tags = ShopifyAPI::Article.tags(popular: 1, limit: 1)
|
70
|
+
assert_equal(3, tags.length)
|
71
71
|
end
|
72
|
-
|
73
72
|
end
|
data/test/asset_test.rb
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class AssetTest < Test::Unit::TestCase
|
4
5
|
def test_get_assetss
|
5
|
-
fake
|
6
|
-
|
6
|
+
fake("themes/1/assets", method: :get, body: load_fixture('assets'))
|
7
|
+
ShopifyAPI::Asset.find(:all, params: { theme_id: 1 })
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_get_asset_namespaced
|
10
|
-
fake
|
11
|
-
|
11
|
+
fake(
|
12
|
+
"themes/1/assets.json?asset%5Bkey%5D=templates%2Findex.liquid&theme_id=1",
|
13
|
+
extension: false,
|
14
|
+
method: :get,
|
15
|
+
body: load_fixture('asset')
|
16
|
+
)
|
17
|
+
ShopifyAPI::Asset.find('templates/index.liquid', params: { theme_id: 1 })
|
12
18
|
end
|
13
19
|
|
14
20
|
def test_get_asset
|
15
|
-
fake
|
16
|
-
|
21
|
+
fake(
|
22
|
+
"assets.json?asset%5Bkey%5D=templates%2Findex.liquid", extension: false, method: :get, body: load_fixture('asset')
|
23
|
+
)
|
24
|
+
ShopifyAPI::Asset.find('templates/index.liquid')
|
17
25
|
end
|
18
26
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
require 'fulfillment_order_test_helper'
|
4
|
+
|
5
|
+
class AssignedFulFillmentOrderTest < Test::Unit::TestCase
|
6
|
+
include FulfillmentOrderTestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@url_prefix = url_prefix_for_activated_session_for('2020-01')
|
11
|
+
@fulfillment_order_fixture = load_fixture('assigned_fulfillment_orders')
|
12
|
+
end
|
13
|
+
|
14
|
+
context "AssignedFulfillmentOrder" do
|
15
|
+
context ".new" do
|
16
|
+
should "raise NotImplementedError when api_version is older than 2020-01" do
|
17
|
+
url_prefix_for_activated_session_for('2019-10')
|
18
|
+
|
19
|
+
assert_raises(NotImplementedError) do
|
20
|
+
ShopifyAPI::AssignedFulfillmentOrder.new(ActiveSupport::JSON.decode(@fulfillment_order_fixture))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#all" do
|
26
|
+
should "raise NotImplementedError when api_version is older than 2020-01" do
|
27
|
+
@url_prefix = url_prefix_for_activated_session_for('2019-10')
|
28
|
+
|
29
|
+
fake 'assigned_fulfillment_orders',
|
30
|
+
url: "#{@url_prefix}/assigned_fulfillment_orders.json",
|
31
|
+
method: :get,
|
32
|
+
body: @fulfillment_order_fixture,
|
33
|
+
extension: false
|
34
|
+
|
35
|
+
assert_raises(NotImplementedError) do
|
36
|
+
ShopifyAPI::AssignedFulfillmentOrder.all(params: { assigned_status: 'cancellation_requested' })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "list assigned fulfillment orders by assigned_status" do
|
41
|
+
fake 'assigned_fulfillment_orders',
|
42
|
+
url: "#{@url_prefix}/assigned_fulfillment_orders.json?assigned_status=cancellation_requested",
|
43
|
+
method: :get,
|
44
|
+
body: @fulfillment_order_fixture,
|
45
|
+
extension: false
|
46
|
+
|
47
|
+
assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
|
48
|
+
params: { assigned_status: 'cancellation_requested' }
|
49
|
+
)
|
50
|
+
|
51
|
+
assert_equal 2, assigned_fulfillment_orders.count
|
52
|
+
assigned_fulfillment_orders.each do |fulfillment_order|
|
53
|
+
assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
54
|
+
assert_equal 'in_progress', fulfillment_order.status
|
55
|
+
assert_equal 'cancellation_accepted', fulfillment_order.request_status
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should "be able to list assigned fulfillment orders by location_ids" do
|
60
|
+
assigned_location_id = 905684977
|
61
|
+
fake 'assigned_fulfillment_orders',
|
62
|
+
url: "#{@url_prefix}/assigned_fulfillment_orders.json?location_ids%5B%5D=#{assigned_location_id}",
|
63
|
+
method: :get,
|
64
|
+
body: @fulfillment_order_fixture, extension: false
|
65
|
+
|
66
|
+
assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
|
67
|
+
params: { location_ids: [assigned_location_id] }
|
68
|
+
)
|
69
|
+
|
70
|
+
assert_equal 2, assigned_fulfillment_orders.count
|
71
|
+
assigned_fulfillment_orders.each do |fulfillment_order|
|
72
|
+
assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
73
|
+
assert_equal assigned_location_id, fulfillment_order.assigned_location_id
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/test/base_test.rb
CHANGED
@@ -1,120 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
|
-
|
3
|
+
require "active_support/log_subscriber/test_helper"
|
3
4
|
|
4
5
|
class BaseTest < Test::Unit::TestCase
|
5
|
-
|
6
6
|
def setup
|
7
|
-
|
8
|
-
@
|
7
|
+
super
|
8
|
+
@session1 = ShopifyAPI::Session.new(domain: 'shop1.myshopify.com', token: 'token1', api_version: '2019-01')
|
9
|
+
@session2 = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-01')
|
9
10
|
end
|
10
11
|
|
11
12
|
def teardown
|
13
|
+
super
|
12
14
|
clear_header('X-Custom')
|
13
15
|
end
|
14
16
|
|
15
17
|
test '#activate_session should set site and headers for given session' do
|
16
|
-
ShopifyAPI::Base.activate_session
|
18
|
+
ShopifyAPI::Base.activate_session(@session1)
|
17
19
|
|
18
|
-
assert_nil
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
20
|
+
assert_nil(ActiveResource::Base.site)
|
21
|
+
assert_equal('https://shop1.myshopify.com', ShopifyAPI::Base.site.to_s)
|
22
|
+
assert_equal('https://shop1.myshopify.com', ShopifyAPI::Shop.site.to_s)
|
21
23
|
|
22
|
-
assert_nil
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
24
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
25
|
+
assert_equal('token1', ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
26
|
+
assert_equal('token1', ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
25
27
|
end
|
26
28
|
|
27
29
|
test '#clear_session should clear base site settings from Base' do
|
28
30
|
ShopifyAPI::Base.site = "https://foo:bar@www.zombo.com"
|
29
31
|
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
32
|
+
assert_equal("foo", ShopifyAPI::Base.user)
|
33
|
+
assert_equal("bar", ShopifyAPI::Base.password)
|
34
|
+
|
35
|
+
ShopifyAPI::Base.clear_session
|
36
|
+
|
37
|
+
assert_nil(ShopifyAPI::Base.user)
|
38
|
+
assert_nil(ShopifyAPI::Base.password)
|
39
|
+
assert_nil(ShopifyAPI::Base.site)
|
40
|
+
end
|
41
|
+
|
42
|
+
# test to check session reset api version remains the same after session reset
|
43
|
+
test '#clear_session should not change the api_version' do
|
44
|
+
ShopifyAPI::Base.site = "https://zoo:lion@www.zoo.com"
|
45
|
+
|
46
|
+
assert_equal("zoo", ShopifyAPI::Base.user)
|
47
|
+
assert_equal("lion", ShopifyAPI::Base.password)
|
32
48
|
|
33
49
|
ShopifyAPI::Base.clear_session
|
34
50
|
|
35
|
-
|
36
|
-
|
37
|
-
|
51
|
+
assert_nil(ShopifyAPI::Base.user)
|
52
|
+
assert_nil(ShopifyAPI::Base.password)
|
53
|
+
assert_nil(ShopifyAPI::Base.site)
|
54
|
+
assert_equal(ShopifyAPI::Base.api_version, @session1.api_version)
|
38
55
|
end
|
39
56
|
|
40
57
|
test '#clear_session should clear site and headers from Base' do
|
41
|
-
ShopifyAPI::Base.activate_session
|
58
|
+
ShopifyAPI::Base.activate_session(@session1)
|
42
59
|
ShopifyAPI::Base.clear_session
|
43
60
|
|
44
|
-
assert_nil
|
45
|
-
assert_nil
|
46
|
-
assert_nil
|
61
|
+
assert_nil(ActiveResource::Base.site)
|
62
|
+
assert_nil(ShopifyAPI::Base.site)
|
63
|
+
assert_nil(ShopifyAPI::Shop.site)
|
47
64
|
|
48
|
-
assert_nil
|
49
|
-
assert_nil
|
50
|
-
assert_nil
|
65
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
66
|
+
assert_nil(ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
67
|
+
assert_nil(ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
51
68
|
end
|
52
69
|
|
53
70
|
test '#activate_session with one session, then clearing and activating with another session should send request to correct shop' do
|
54
|
-
ShopifyAPI::Base.activate_session
|
71
|
+
ShopifyAPI::Base.activate_session(@session1)
|
55
72
|
ShopifyAPI::Base.clear_session
|
56
|
-
ShopifyAPI::Base.activate_session
|
73
|
+
ShopifyAPI::Base.activate_session(@session2)
|
57
74
|
|
58
|
-
assert_nil
|
59
|
-
assert_equal
|
60
|
-
assert_equal
|
75
|
+
assert_nil(ActiveResource::Base.site)
|
76
|
+
assert_equal('https://shop2.myshopify.com', ShopifyAPI::Base.site.to_s)
|
77
|
+
assert_equal('https://shop2.myshopify.com', ShopifyAPI::Shop.site.to_s)
|
61
78
|
|
62
|
-
assert_nil
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
79
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
80
|
+
assert_equal('token2', ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
81
|
+
assert_equal('token2', ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
65
82
|
end
|
66
83
|
|
67
84
|
test '#activate_session with nil raises an InvalidSessionError' do
|
68
|
-
assert_raises
|
69
|
-
ShopifyAPI::Base.activate_session
|
85
|
+
assert_raises(ShopifyAPI::Base::InvalidSessionError) do
|
86
|
+
ShopifyAPI::Base.activate_session(nil)
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
90
|
test "#delete should send custom headers with request" do
|
74
|
-
ShopifyAPI::Base.activate_session
|
91
|
+
ShopifyAPI::Base.activate_session(@session1)
|
75
92
|
ShopifyAPI::Base.headers['X-Custom'] = 'abc'
|
76
|
-
ShopifyAPI::Base.connection
|
77
|
-
|
93
|
+
ShopifyAPI::Base.connection
|
94
|
+
.expects(:delete)
|
95
|
+
.with('/admin/api/2019-01/bases/1.json', has_entry('X-Custom', 'abc'))
|
96
|
+
ShopifyAPI::Base.delete("1")
|
78
97
|
end
|
79
98
|
|
80
99
|
test "#headers includes the User-Agent" do
|
81
100
|
assert_not_includes ActiveResource::Base.headers.keys, 'User-Agent'
|
82
|
-
assert_includes
|
101
|
+
assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
|
83
102
|
thread = Thread.new do
|
84
|
-
assert_includes
|
103
|
+
assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
|
85
104
|
end
|
86
105
|
thread.join
|
87
106
|
end
|
88
107
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
108
|
+
test "prefix= will forward to resource when the value does not start with admin" do
|
109
|
+
session = ShopifyAPI::Session.new(domain: 'shop1.myshopify.com', token: 'token1', api_version: '2019-01')
|
110
|
+
ShopifyAPI::Base.activate_session(session)
|
111
|
+
silence_warnings do
|
112
|
+
TestResource.prefix = 'a/regular/path/'
|
94
113
|
end
|
95
114
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
115
|
+
assert_equal('/admin/api/2019-01/a/regular/path/', TestResource.prefix)
|
116
|
+
end
|
117
|
+
|
118
|
+
test "prefix= will raise an error if value starts with with /admin" do
|
119
|
+
assert_raises(ArgumentError) do
|
120
|
+
TestResource.prefix = '/admin/old/prefix/structure/'
|
101
121
|
end
|
102
122
|
end
|
103
123
|
|
104
|
-
|
105
|
-
|
124
|
+
test "#headers propagates changes to subclasses" do
|
125
|
+
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
126
|
+
assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
|
127
|
+
assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
|
128
|
+
end
|
129
|
+
|
130
|
+
test "#headers clears changes to subclasses" do
|
131
|
+
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
132
|
+
assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
|
133
|
+
ShopifyAPI::Base.headers['X-Custom'] = nil
|
134
|
+
assert_nil(ShopifyAPI::Product.headers['X-Custom'])
|
135
|
+
end
|
136
|
+
|
137
|
+
test "#headers set in the main thread affect spawned threads" do
|
138
|
+
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
139
|
+
Thread.new do
|
140
|
+
assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
|
141
|
+
end.join
|
142
|
+
end
|
143
|
+
|
144
|
+
test "#headers set in spawned threads do not affect the main thread" do
|
145
|
+
Thread.new do
|
106
146
|
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
147
|
+
end.join
|
148
|
+
assert_nil(ShopifyAPI::Base.headers['X-Custom'])
|
149
|
+
end
|
150
|
+
|
151
|
+
test "using a different version changes the url" do
|
152
|
+
release_2019_01 = ShopifyAPI::Session.new(domain: 'shop1.myshopify.com', token: 'token1', api_version: '2019-01')
|
153
|
+
unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
|
154
|
+
|
155
|
+
fake(
|
156
|
+
"shop",
|
157
|
+
url: "https://shop1.myshopify.com/admin/api/2019-01/shop.json",
|
158
|
+
method: :get,
|
159
|
+
status: 201,
|
160
|
+
body: '{ "shop": { "id": 1 } }'
|
161
|
+
)
|
162
|
+
fake(
|
163
|
+
"shop",
|
164
|
+
url: "https://shop2.myshopify.com/admin/api/unstable/shop.json",
|
165
|
+
method: :get,
|
166
|
+
status: 201,
|
167
|
+
body: '{ "shop": { "id": 2 } }'
|
168
|
+
)
|
169
|
+
|
170
|
+
ShopifyAPI::Base.activate_session(release_2019_01)
|
171
|
+
assert_equal(1, ShopifyAPI::Shop.current.id)
|
172
|
+
|
173
|
+
ShopifyAPI::Base.activate_session(unstable_version)
|
174
|
+
assert_equal(2, ShopifyAPI::Shop.current.id)
|
175
|
+
end
|
176
|
+
|
177
|
+
test "#api_version= should set ApiVersion" do
|
178
|
+
ShopifyAPI::Base.api_version = '2019-04'
|
179
|
+
assert_equal('2019-04', ShopifyAPI::Base.api_version.to_s)
|
180
|
+
end
|
111
181
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
182
|
+
test "#api_version= nil should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
|
183
|
+
ShopifyAPI::Base.api_version = nil
|
184
|
+
assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
|
185
|
+
end
|
186
|
+
|
187
|
+
test "#api_version= ShopifyAPI::ApiVersion::NullVersion should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
|
188
|
+
ShopifyAPI::Base.api_version = ShopifyAPI::ApiVersion::NullVersion
|
189
|
+
assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
|
190
|
+
end
|
191
|
+
|
192
|
+
test "#version_validation! does not raise is api_version is newer or equal to minimum supported version" do
|
193
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
194
|
+
assert_nil(ShopifyAPI::Base::version_validation!('2020-01'))
|
195
|
+
end
|
196
|
+
|
197
|
+
test "#version_validation! raises NotImplemetedError if api_version is older than minimum supported version" do
|
198
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
199
|
+
exception = assert_raises(NotImplementedError) do
|
200
|
+
ShopifyAPI::Base::version_validation!('2020-01')
|
117
201
|
end
|
202
|
+
assert_equal('The minimum supported version is 2020-01.', exception.message)
|
118
203
|
end
|
119
204
|
|
120
205
|
def clear_header(header)
|
@@ -122,4 +207,7 @@ class BaseTest < Test::Unit::TestCase
|
|
122
207
|
klass.headers.delete(header)
|
123
208
|
end
|
124
209
|
end
|
210
|
+
|
211
|
+
class TestResource < ShopifyAPI::Base
|
212
|
+
end
|
125
213
|
end
|