shopify_api 9.0.2 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/workflows/build.yml +41 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +23 -3
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +43 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +151 -0
- data/Gemfile_ar51 +1 -1
- data/README.md +47 -31
- data/RELEASING +10 -6
- data/Rakefile +16 -5
- data/SECURITY.md +59 -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 +6 -7
- data/lib/active_resource/json_errors.rb +8 -2
- data/lib/shopify_api.rb +8 -1
- 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/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.rb +1 -0
- 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 +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 +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/session.rb +43 -14
- data/lib/shopify_api/version.rb +2 -1
- data/lib/verify_docs.rb +8 -0
- data/service.yml +1 -1
- data/shopify_api.gemspec +13 -6
- 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 +15 -11
- data/test/discount_code_batch_test.rb +41 -0
- 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/discount_code_batch.json +14 -0
- data/test/fixtures/discount_code_batch_discount_codes.json +21 -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 +215 -147
- 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/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 +7 -9
- 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 +234 -43
- 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 +30 -15
- 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/shipping_zone_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ShippingZoneTest < Test::Unit::TestCase
|
4
5
|
test "get all should get all shipping zones" do
|
5
|
-
fake
|
6
|
+
fake('shipping_zones', method: :get, status: 200, body: load_fixture('shipping_zones'))
|
6
7
|
checkout = ShopifyAPI::ShippingZone.all
|
7
|
-
assert_equal
|
8
|
-
assert_equal
|
8
|
+
assert_equal(1, checkout.first.id)
|
9
|
+
assert_equal("Canada", checkout.first.name)
|
9
10
|
end
|
10
11
|
end
|
data/test/shop_test.rb
CHANGED
@@ -1,68 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ShopTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
|
-
fake
|
7
|
+
fake("shop")
|
7
8
|
@shop = ShopifyAPI::Shop.current
|
8
9
|
end
|
9
10
|
|
10
11
|
def test_current_should_return_current_shop
|
11
|
-
assert
|
12
|
-
assert_equal
|
13
|
-
assert_equal
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
16
|
-
assert_nil
|
12
|
+
assert(@shop.is_a?(ShopifyAPI::Shop))
|
13
|
+
assert_equal("Apple Computers", @shop.name)
|
14
|
+
assert_equal("apple.myshopify.com", @shop.myshopify_domain)
|
15
|
+
assert_equal(690933842, @shop.id)
|
16
|
+
assert_equal("2007-12-31T19:00:00-05:00", @shop.created_at)
|
17
|
+
assert_nil(@shop.tax_shipping)
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_current_with_options_should_return_current_shop
|
20
|
-
fake
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
fake(
|
22
|
+
"shop.json?fields%5B%5D=name&fields%5B%5D=myshopify_domain",
|
23
|
+
extension: false,
|
24
|
+
method: :get,
|
25
|
+
status: 201,
|
26
|
+
body: load_fixture('shop')
|
27
|
+
)
|
28
|
+
|
29
|
+
@shop = ShopifyAPI::Shop.current(params: { fields: [:name, :myshopify_domain] })
|
30
|
+
assert(@shop.is_a?(ShopifyAPI::Shop))
|
31
|
+
assert_equal("Apple Computers", @shop.name)
|
32
|
+
assert_equal("apple.myshopify.com", @shop.myshopify_domain)
|
26
33
|
end
|
27
34
|
|
28
35
|
def test_get_all_metafields_for_shop
|
29
|
-
fake
|
36
|
+
fake("metafields")
|
30
37
|
|
31
38
|
metafields = @shop.metafields
|
32
39
|
|
33
|
-
assert_equal
|
34
|
-
assert
|
40
|
+
assert_equal(3, metafields.length)
|
41
|
+
assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
|
35
42
|
end
|
36
43
|
|
37
44
|
def test_get_2_metafields_for_shop
|
38
|
-
body = ActiveSupport::JSON.decode
|
39
|
-
body['metafields'].slice!
|
45
|
+
body = ActiveSupport::JSON.decode(load_fixture('metafields'))
|
46
|
+
body['metafields'].slice!(2, 1)
|
40
47
|
|
41
|
-
fake
|
48
|
+
fake('metafields.json?limit=2', body: body.to_json, extension: false)
|
42
49
|
|
43
|
-
metafields = @shop.metafields
|
50
|
+
metafields = @shop.metafields(limit: 2)
|
44
51
|
|
45
|
-
assert_equal
|
46
|
-
assert
|
52
|
+
assert_equal(2, metafields.length)
|
53
|
+
assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
|
47
54
|
end
|
48
55
|
|
49
56
|
def test_add_metafield
|
50
|
-
fake
|
51
|
-
|
52
|
-
field = @shop.add_metafield(
|
53
|
-
|
54
|
-
|
55
|
-
assert_equal
|
56
|
-
|
57
|
-
|
57
|
+
fake("metafields", method: :post, status: 201, body: load_fixture('metafield'))
|
58
|
+
|
59
|
+
field = @shop.add_metafield(
|
60
|
+
ShopifyAPI::Metafield.new(namespace: "contact", key: "email", value: "123@example.com", value_type: "string")
|
61
|
+
)
|
62
|
+
assert_equal(
|
63
|
+
ActiveSupport::JSON.decode(
|
64
|
+
'{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'
|
65
|
+
),
|
66
|
+
ActiveSupport::JSON.decode(WebMock.last_request.body)
|
67
|
+
)
|
68
|
+
assert(!field.new_record?)
|
69
|
+
assert_equal("contact", field.namespace)
|
70
|
+
assert_equal("email", field.key)
|
71
|
+
assert_equal("123@example.com", field.value)
|
58
72
|
end
|
59
73
|
|
60
74
|
def test_events
|
61
|
-
fake
|
75
|
+
fake("events")
|
62
76
|
|
63
77
|
events = @shop.events
|
64
78
|
|
65
|
-
assert_equal
|
66
|
-
assert
|
79
|
+
assert_equal(3, events.length)
|
80
|
+
assert(events.all? { |m| m.is_a?(ShopifyAPI::Event) })
|
67
81
|
end
|
68
82
|
end
|
@@ -1,35 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class SmartCollectionTest < Test::Unit::TestCase
|
4
5
|
test "Smart Collection creation" do
|
5
|
-
fake
|
6
|
-
rules = { :
|
7
|
-
smart_collection = ShopifyAPI::SmartCollection.create(:
|
8
|
-
assert_equal
|
9
|
-
end
|
10
|
-
|
11
|
-
test "Smart Collection get products gets all products in a smart collection" do
|
12
|
-
fake "smart_collections/1063001432", method: :get, status: 200, body: load_fixture('smart_collection')
|
13
|
-
smart_collection = ShopifyAPI::SmartCollection.find(1063001432)
|
14
|
-
|
15
|
-
fake "products.json?collection_id=1063001432",
|
16
|
-
method: :get,
|
17
|
-
status: 200,
|
18
|
-
body:
|
19
|
-
load_fixture('smart_collection_products'),
|
20
|
-
extension: false
|
21
|
-
assert_equal [632910392, 921728736], smart_collection.products.map(&:id)
|
22
|
-
end
|
23
|
-
|
24
|
-
test "Smart Collection get products with only_sorted=only_manual gets only manually sorted products" do
|
25
|
-
fake "smart_collections/1063001432", method: :get, status: 200, body: load_fixture('smart_collection')
|
26
|
-
smart_collection = ShopifyAPI::SmartCollection.find(1063001432)
|
27
|
-
|
28
|
-
fake "smart_collections/1063001432/products.json?only_sorted=only_manual",
|
29
|
-
method: :get,
|
30
|
-
status: 200,
|
31
|
-
body: load_fixture('smart_collection_products'),
|
32
|
-
extension: false
|
33
|
-
assert_equal [632910392, 921728736], smart_collection.products(only_sorted: "only_manual").map(&:id)
|
6
|
+
fake("smart_collections", method: :post, status: 201, body: load_fixture('smart_collection'))
|
7
|
+
rules = { column: "title", relation: "starts_with", condition: "mac" }
|
8
|
+
smart_collection = ShopifyAPI::SmartCollection.create(title: "Macbooks", rules: rules)
|
9
|
+
assert_equal(1063001432, smart_collection.id)
|
34
10
|
end
|
35
11
|
end
|
@@ -1,32 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class StorefrontAccessTokenTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_create_storefront_access_token
|
6
|
-
fake
|
6
|
+
fake("storefront_access_tokens", method: :post, body: load_fixture('storefront_access_token'))
|
7
7
|
storefront_access_token = ShopifyAPI::StorefrontAccessToken.create(title: 'Test')
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
8
|
+
assert_equal(1, storefront_access_token.id)
|
9
|
+
assert_equal("Test", storefront_access_token.title)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_delete_storefront_access_token
|
13
|
-
fake
|
14
|
-
fake
|
15
|
-
|
13
|
+
fake('storefront_access_tokens/1', method: :get, status: 200, body: load_fixture('storefront_access_token'))
|
14
|
+
fake('storefront_access_tokens/1', method: :delete, status: 200, body: 'destroyed')
|
16
15
|
storefront_access_tokens = ShopifyAPI::StorefrontAccessToken.find(1)
|
17
|
-
assert
|
16
|
+
assert(storefront_access_tokens.destroy)
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_get_storefront_access_tokens
|
21
|
-
fake
|
20
|
+
fake("storefront_access_tokens", method: :get, status: 201, body: load_fixture('storefront_access_tokens'))
|
22
21
|
|
23
22
|
tokens = ShopifyAPI::StorefrontAccessToken.all
|
24
23
|
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
27
|
-
assert_equal
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
24
|
+
assert_equal(2, tokens.size)
|
25
|
+
assert_equal(1, tokens.first.id)
|
26
|
+
assert_equal(2, tokens.last.id)
|
27
|
+
assert_equal('Test 1', tokens.first.title)
|
28
|
+
assert_equal('Test 2', tokens.last.title)
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
data/test/tax_service_test.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
class TaxServiceTest < Test::Unit::TestCase
|
3
4
|
test "tax service creation" do
|
4
|
-
fake
|
5
|
-
|
6
|
-
assert_equal
|
7
|
-
|
5
|
+
fake("tax_services", method: :post, status: 202, body: load_fixture('tax_service'))
|
6
|
+
ShopifyAPI::TaxService.create(name: "My Tax Service", url: "https://mytaxservice.com")
|
7
|
+
assert_equal(
|
8
|
+
'{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}',
|
9
|
+
WebMock.last_request.body
|
10
|
+
)
|
8
11
|
end
|
9
12
|
end
|
@@ -5,14 +5,14 @@ require 'test_helper'
|
|
5
5
|
class TenderTransactionTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
super
|
8
|
-
fake
|
8
|
+
fake("tender_transactions", method: :get, body: load_fixture('tender_transactions'))
|
9
9
|
end
|
10
10
|
|
11
11
|
context "Tender Transaction" do
|
12
12
|
should 'return a list of transactions' do
|
13
13
|
tender_transactions = ShopifyAPI::TenderTransaction.all
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
14
|
+
assert_equal(3, tender_transactions.length)
|
15
|
+
assert_equal([1, 2, 3], tender_transactions.map(&:id))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rubygems'
|
2
3
|
require 'minitest/autorun'
|
3
4
|
require 'webmock/minitest'
|
4
5
|
require_relative 'lib/webmock_extensions/last_request'
|
5
|
-
require 'mocha/
|
6
|
+
require 'mocha/minitest'
|
6
7
|
require 'pry'
|
7
8
|
|
8
9
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -23,7 +24,7 @@ module Test
|
|
23
24
|
self.test("should_#{string}", &block)
|
24
25
|
end
|
25
26
|
|
26
|
-
def self.context(
|
27
|
+
def self.context(_string)
|
27
28
|
yield
|
28
29
|
end
|
29
30
|
|
@@ -34,6 +35,7 @@ module Test
|
|
34
35
|
const = mod.const_get(const)
|
35
36
|
const.format = :json if const.respond_to?(:format=)
|
36
37
|
rescue NameError
|
38
|
+
# Do nothing
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -68,7 +70,7 @@ module Test
|
|
68
70
|
|
69
71
|
# Custom Assertions
|
70
72
|
def assert_not(expression)
|
71
|
-
refute
|
73
|
+
refute(expression, "Expected <#{expression}> to be false!")
|
72
74
|
end
|
73
75
|
|
74
76
|
def assert_nothing_raised
|
@@ -76,30 +78,30 @@ module Test
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def assert_not_includes(array, value)
|
79
|
-
refute
|
81
|
+
refute(array.include?(value))
|
80
82
|
end
|
81
83
|
|
82
84
|
def assert_includes(array, value)
|
83
|
-
assert
|
85
|
+
assert(array.include?(value))
|
84
86
|
end
|
85
87
|
|
86
|
-
def load_fixture(name, format
|
88
|
+
def load_fixture(name, format = :json)
|
87
89
|
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
|
88
90
|
end
|
89
91
|
|
90
92
|
def assert_request_body(expected)
|
91
|
-
assert_equal
|
93
|
+
assert_equal(expected, WebMock.last_request.body)
|
92
94
|
end
|
93
95
|
|
94
|
-
def fake(endpoint, options={})
|
95
|
-
request_body = options.
|
96
|
-
body
|
96
|
+
def fake(endpoint, options = {})
|
97
|
+
request_body = options.key?(:request_body) ? options.delete(:request_body) : nil
|
98
|
+
body = options.key?(:body) ? options.delete(:body) : load_fixture(endpoint)
|
97
99
|
format = options.delete(:format) || :json
|
98
100
|
method = options.delete(:method) || :get
|
99
101
|
api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.find_version('2019-01')
|
100
|
-
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
102
|
+
extension = ".#{options.delete(:extension) || 'json'}" unless options[:extension] == false
|
101
103
|
status = options.delete(:status) || 200
|
102
|
-
url = if options.
|
104
|
+
url = if options.key?(:url)
|
103
105
|
options[:url]
|
104
106
|
else
|
105
107
|
"https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
|
data/test/transaction_test.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class TransactionTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
|
-
fake
|
7
|
+
fake("orders/450789469/transactions/389404469", method: :get, body: load_fixture('transaction'))
|
7
8
|
end
|
8
9
|
|
9
10
|
context "Transaction" do
|
10
11
|
context "#find" do
|
11
12
|
should "find a specific transaction" do
|
12
|
-
transaction = ShopifyAPI::Transaction.find(389404469, :
|
13
|
-
assert_equal
|
13
|
+
transaction = ShopifyAPI::Transaction.find(389404469, params: { order_id: 450789469 })
|
14
|
+
assert_equal("409.94", transaction.amount)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/test/usage_charge_test.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class UsageChargeTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_create_usage_charges
|
6
|
-
fake
|
6
|
+
fake("recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge'))
|
7
7
|
|
8
8
|
usage_charge = ShopifyAPI::UsageCharge.new(description: '1000 emails', price: 1.0)
|
9
|
-
usage_charge.prefix_options = {recurring_application_charge_id: 654381177}
|
10
|
-
assert
|
9
|
+
usage_charge.prefix_options = { recurring_application_charge_id: 654381177 }
|
10
|
+
assert(usage_charge.save)
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_get_usage_charges
|
14
|
-
fake
|
14
|
+
fake(
|
15
|
+
"recurring_application_charges/654381177/usage_charges/359376002",
|
16
|
+
method: :get,
|
17
|
+
status: 201,
|
18
|
+
body: load_fixture('usage_charge')
|
19
|
+
)
|
15
20
|
|
16
|
-
usage_charge = ShopifyAPI::UsageCharge.find(359376002, params: {recurring_application_charge_id: 654381177})
|
21
|
+
usage_charge = ShopifyAPI::UsageCharge.find(359376002, params: { recurring_application_charge_id: 654381177 })
|
17
22
|
|
18
|
-
assert_equal
|
23
|
+
assert_equal("1000 emails", usage_charge.description)
|
19
24
|
end
|
20
|
-
|
21
25
|
end
|
data/test/user_test.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class UserTest < Test::Unit::TestCase
|
4
5
|
test 'get should get a user' do
|
5
6
|
fake 'users/799407056', method: :get, status: 200, body: load_fixture('user')
|
6
|
-
|
7
|
+
|
7
8
|
user = ShopifyAPI::User.find(799407056)
|
8
9
|
assert_equal 799407056, user.id
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
test 'get should get all users' do
|
12
13
|
fake 'users', method: :get, status: 200, body: load_fixture('users')
|
13
|
-
|
14
|
+
|
14
15
|
users = ShopifyAPI::User.all
|
15
16
|
assert_equal 799407056, users.first.id
|
16
17
|
end
|
data/test/variant_test.rb
CHANGED
@@ -1,46 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class VariantTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
refresh_variant
|
8
|
+
end
|
4
9
|
|
5
10
|
def test_get_variants
|
6
|
-
fake
|
11
|
+
fake("products/632910392/variants", method: :get, body: load_fixture('variants'))
|
7
12
|
|
8
|
-
variants = ShopifyAPI::Variant.find(:all, :
|
9
|
-
assert_equal
|
13
|
+
variants = ShopifyAPI::Variant.find(:all, params: { product_id: 632910392 })
|
14
|
+
assert_equal(variants.map(&:id).sort, [39072856, 49148385, 457924702, 808950810])
|
10
15
|
end
|
11
16
|
|
12
17
|
def test_get_variant_namespaced
|
13
|
-
|
14
|
-
|
15
|
-
v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
16
|
-
assert_equal 632910392, v.product_id
|
18
|
+
assert_equal(632910392, @variant.product_id)
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_get_variant
|
20
|
-
|
21
|
-
|
22
|
-
v = ShopifyAPI::Variant.find(808950810)
|
23
|
-
assert_equal 632910392, v.product_id
|
22
|
+
assert_equal(632910392, @variant.product_id)
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_product_id_should_be_accessible_if_via_product_endpoint
|
27
|
-
|
28
|
-
|
29
|
-
v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
30
|
-
assert_equal 632910392, v.product_id
|
26
|
+
assert_equal(632910392, @variant.product_id)
|
31
27
|
end
|
32
28
|
|
33
29
|
def test_product_id_should_be_accessible_if_via_variant_endpoint
|
34
|
-
|
35
|
-
|
36
|
-
v = ShopifyAPI::Variant.find(808950810)
|
37
|
-
assert_equal 632910392, v.product_id
|
30
|
+
assert_equal(632910392, @variant.product_id)
|
38
31
|
end
|
39
32
|
|
40
33
|
def test_delete_variant
|
41
|
-
fake
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
fake("products/632910392/variants/808950810", method: :delete, body: 'destroyed')
|
35
|
+
assert(@variant.destroy)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_read_only_inventory_quantity
|
39
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
40
|
+
refresh_variant(api_version: ShopifyAPI::Base.api_version)
|
41
|
+
assert_equal(10, @variant.inventory_quantity)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api
|
45
|
+
ShopifyAPI::Base.api_version = :unstable
|
46
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
47
|
+
@variant.inventory_quantity_adjustment = 8
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_setting_variant_inventory_quantity_fails_in_the_unstable_api
|
52
|
+
ShopifyAPI::Base.api_version = :unstable
|
53
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
54
|
+
@variant.inventory_quantity = 8
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api
|
59
|
+
ShopifyAPI::Base.api_version = :unstable
|
60
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
61
|
+
@variant.old_inventory_quantity = 8
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def refresh_variant(api_version: nil)
|
68
|
+
fake(
|
69
|
+
"products/632910392/variants/808950810", method: :get, body: load_fixture('variant'), api_version: api_version
|
70
|
+
)
|
71
|
+
@variant = ShopifyAPI::Variant.find(808950810, params: { product_id: 632910392 })
|
45
72
|
end
|
46
73
|
end
|