shopify_api 9.2.0 → 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 +0 -1
- data/.rubocop.yml +23 -3
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +153 -0
- data/Gemfile_ar51 +1 -1
- data/README.md +41 -31
- data/RELEASING +10 -6
- data/Rakefile +10 -6
- data/dev.yml +11 -0
- data/docs/graphql.md +1 -1
- data/docs/index.md +1 -1
- 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 +8 -6
- 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 +4 -3
- 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 +11 -6
- 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 +2 -3
- 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 +14 -11
- 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 +2 -2
- 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 +16 -18
- data/lib/shopify_api/resources/webhook.rb +1 -0
- data/lib/shopify_api/resources.rb +1 -0
- data/lib/shopify_api/session.rb +29 -19
- data/lib/shopify_api/version.rb +2 -1
- data/lib/shopify_api.rb +9 -1
- data/lib/verify_docs.rb +1 -0
- data/service.yml +2 -5
- data/shopify_api.gemspec +12 -5
- 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 +55 -56
- 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 +27 -27
- 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 +44 -32
- 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 +159 -48
- 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 -4
- data/test/tender_transaction_test.rb +3 -3
- data/test/test_helper.rb +13 -11
- 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 +23 -54
- data/test/webhook_test.rb +10 -7
- metadata +34 -12
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/.travis.yml +0 -28
data/test/collection_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CollectionTest < Test::Unit::TestCase
|
@@ -6,23 +7,23 @@ class CollectionTest < Test::Unit::TestCase
|
|
6
7
|
ShopifyAPI::Base.activate_session(available_version)
|
7
8
|
|
8
9
|
fake(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
'collections',
|
11
|
+
url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
|
12
|
+
method: :get,
|
13
|
+
status: 200,
|
14
|
+
body: load_fixture('collection'),
|
15
|
+
extension: false
|
15
16
|
)
|
16
17
|
|
17
18
|
collection = ShopifyAPI::Collection.find(1)
|
18
19
|
|
19
20
|
fake(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
'products',
|
22
|
+
url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
|
23
|
+
method: :get,
|
24
|
+
status: 200,
|
25
|
+
body: load_fixture('collection_products'),
|
26
|
+
extension: false
|
26
27
|
)
|
27
28
|
assert_equal [632910392, 921728736], collection.products.map(&:id)
|
28
29
|
end
|
@@ -32,17 +33,17 @@ class CollectionTest < Test::Unit::TestCase
|
|
32
33
|
ShopifyAPI::Base.activate_session(old_version)
|
33
34
|
|
34
35
|
fake(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
'collections',
|
37
|
+
url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
|
38
|
+
method: :get,
|
39
|
+
status: 200,
|
40
|
+
body: load_fixture('collection'),
|
41
|
+
extension: false
|
41
42
|
)
|
42
43
|
|
43
44
|
collection = ShopifyAPI::Collection.find(1)
|
44
45
|
|
45
|
-
assert_raises
|
46
|
+
assert_raises(NotImplementedError) do
|
46
47
|
collection.products
|
47
48
|
end
|
48
49
|
end
|
data/test/countable_test.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CountableTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
|
-
fake
|
7
|
+
fake("products/count", body: '{"count": 16}')
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_count_products
|
10
11
|
count = ShopifyAPI::Product.count
|
11
|
-
assert_equal
|
12
|
+
assert_equal(16, count)
|
12
13
|
end
|
13
14
|
end
|
data/test/currency_test.rb
CHANGED
@@ -4,17 +4,17 @@ require 'test_helper'
|
|
4
4
|
class CurrencyTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
super
|
7
|
-
fake
|
7
|
+
fake("currencies", method: :get, body: load_fixture('currencies'))
|
8
8
|
end
|
9
9
|
|
10
10
|
context "Currency" do
|
11
11
|
should 'return a list of enabled currencies' do
|
12
12
|
currencies = ShopifyAPI::Currency.all
|
13
|
-
assert_equal
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
13
|
+
assert_equal(4, currencies.count)
|
14
|
+
assert_equal(%w(AUD EUR GBP HKD), currencies.map(&:currency))
|
15
|
+
assert_equal([true, true, true, false], currencies.map(&:enabled))
|
16
16
|
currencies.each do |currency|
|
17
|
-
assert_equal
|
17
|
+
assert_equal("2018-10-03T14:44:08-04:00", currency.rate_updated_at)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CustomCollectionTest < Test::Unit::TestCase
|
4
5
|
test "#create should create a custom collection" do
|
5
|
-
fake
|
6
|
-
link = ShopifyAPI::CustomCollection.create(:
|
7
|
-
assert_equal
|
6
|
+
fake("custom_collections", method: :post, status: 201, body: load_fixture('custom_collection'))
|
7
|
+
link = ShopifyAPI::CustomCollection.create(title: "Macbooks", image: { src: "http://example.com/rails_logo.gif" })
|
8
|
+
assert_equal(1063001463, link.id)
|
8
9
|
end
|
9
10
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CustomerSavedSearchTest < Test::Unit::TestCase
|
@@ -7,21 +8,30 @@ class CustomerSavedSearchTest < Test::Unit::TestCase
|
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_get_customers_from_customer_saved_search
|
10
|
-
fake
|
11
|
-
|
12
|
-
|
11
|
+
fake(
|
12
|
+
'customers/search.json?customer_saved_search_id=8899730',
|
13
|
+
body: load_fixture('customer_saved_search_customers'),
|
14
|
+
extension: false
|
15
|
+
)
|
16
|
+
assert_equal(1, @customer_saved_search.customers.length)
|
17
|
+
assert_equal(112223902, @customer_saved_search.customers.first.id)
|
13
18
|
end
|
14
19
|
|
15
20
|
def test_get_customers_from_customer_saved_search_with_params
|
16
|
-
fake
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
fake(
|
22
|
+
'customers/search.json?customer_saved_search_id=8899730&limit=1',
|
23
|
+
body: load_fixture('customer_saved_search_customers'),
|
24
|
+
extension: false
|
25
|
+
)
|
26
|
+
customers = @customer_saved_search.customers(limit: 1)
|
27
|
+
assert_equal(1, customers.length)
|
28
|
+
assert_equal(112223902, customers.first.id)
|
20
29
|
end
|
21
30
|
|
22
31
|
private
|
32
|
+
|
23
33
|
def load_customer_saved_search
|
24
|
-
fake
|
34
|
+
fake('customer_saved_searches/8899730', body: load_fixture('customer_saved_search'))
|
25
35
|
@customer_saved_search = ShopifyAPI::CustomerSavedSearch.find(8899730)
|
26
36
|
end
|
27
37
|
end
|
data/test/customer_test.rb
CHANGED
@@ -1,50 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CustomerTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
7
|
|
7
|
-
fake
|
8
|
+
fake('customers/207119551', body: load_fixture('customers'))
|
8
9
|
|
9
10
|
@customer = ShopifyAPI::Customer.find(207119551)
|
10
11
|
end
|
11
12
|
|
12
13
|
test "search should get a customers collection" do
|
13
|
-
fake
|
14
|
+
fake(
|
15
|
+
"customers/search.json?query=Bob+country%3AUnited+States",
|
16
|
+
extension: false,
|
17
|
+
body: load_fixture('customers_search')
|
18
|
+
)
|
14
19
|
|
15
20
|
results = ShopifyAPI::Customer.search(query: 'Bob country:United States')
|
16
|
-
assert_equal
|
21
|
+
assert_equal('Bob', results.first.first_name)
|
17
22
|
end
|
18
23
|
|
19
24
|
test "account_activation_url should create an account activation url" do
|
20
|
-
fake
|
25
|
+
fake(
|
26
|
+
"customers/207119551/account_activation_url",
|
27
|
+
method: :post,
|
28
|
+
body: load_fixture('customers_account_activation_url')
|
29
|
+
)
|
21
30
|
|
22
31
|
activation_url = "http://apple.myshopify.com/account/activate/207119551/86688abf23572680740b1c062fa37111-1458248616"
|
23
|
-
assert_equal
|
32
|
+
assert_equal(activation_url, @customer.account_activation_url)
|
24
33
|
end
|
25
34
|
|
26
35
|
test "#send_invite with no params" do
|
27
36
|
customer_invite_fixture = load_fixture('customer_invite')
|
28
37
|
customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
|
29
|
-
fake
|
38
|
+
fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
|
30
39
|
|
31
40
|
customer_invite_response = @customer.send_invite
|
32
41
|
|
33
|
-
assert_equal
|
34
|
-
assert_kind_of
|
35
|
-
assert_equal
|
42
|
+
assert_equal('{"customer_invite":{}}', WebMock.last_request.body)
|
43
|
+
assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
|
44
|
+
assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
|
36
45
|
end
|
37
46
|
|
38
47
|
test "#send_invite with params" do
|
39
48
|
customer_invite_fixture = load_fixture('customer_invite')
|
40
49
|
customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
|
41
|
-
fake
|
42
|
-
|
50
|
+
fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
|
43
51
|
|
44
52
|
customer_invite_response = @customer.send_invite(ShopifyAPI::CustomerInvite.new(customer_invite['customer_invite']))
|
45
53
|
|
46
|
-
assert_equal
|
47
|
-
assert_kind_of
|
48
|
-
assert_equal
|
54
|
+
assert_equal(customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body))
|
55
|
+
assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
|
56
|
+
assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
|
49
57
|
end
|
50
58
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
require "active_support/log_subscriber/test_helper"
|
3
4
|
require 'json'
|
@@ -9,18 +10,21 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
9
10
|
|
10
11
|
def setup
|
11
12
|
super
|
12
|
-
@page = { :
|
13
|
-
@ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION}
|
13
|
+
@page = { page: { id: 1, title: 'Shopify API' } }.to_json
|
14
|
+
@ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} " \
|
15
|
+
"ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
|
14
16
|
@request_headers = "Headers: {\"Accept\"=>\"application/json\", " \
|
15
|
-
"#{@ua_header}, \"X-Shopify-Access-Token\"=>\"
|
17
|
+
"#{@ua_header}, \"X-Shopify-Access-Token\"=>\"[FILTERED]\"}"
|
16
18
|
|
17
19
|
ShopifyAPI::Base.clear_session
|
18
|
-
fake(
|
20
|
+
fake(
|
21
|
+
"apis",
|
19
22
|
url: "https://app.shopify.com/services/apis.json",
|
20
23
|
method: :get,
|
21
24
|
status: 200,
|
22
25
|
api_version: :stub,
|
23
|
-
body: load_fixture('apis')
|
26
|
+
body: load_fixture('apis')
|
27
|
+
)
|
24
28
|
ShopifyAPI::ApiVersion.fetch_known_versions
|
25
29
|
session = ShopifyAPI::Session.new(
|
26
30
|
domain: "https://this-is-my-test-shop.myshopify.com",
|
@@ -30,8 +34,8 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
30
34
|
|
31
35
|
ShopifyAPI::Base.activate_session(session)
|
32
36
|
|
33
|
-
ActiveResource::LogSubscriber.attach_to
|
34
|
-
ActiveResource::DetailedLogSubscriber.attach_to
|
37
|
+
ActiveResource::LogSubscriber.attach_to(:active_resource)
|
38
|
+
ActiveResource::DetailedLogSubscriber.attach_to(:active_resource_detailed)
|
35
39
|
end
|
36
40
|
|
37
41
|
def teardown
|
@@ -45,7 +49,7 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
45
49
|
end
|
46
50
|
|
47
51
|
test "logging on #find" do
|
48
|
-
fake
|
52
|
+
fake("pages/1", method: :get, body: @page)
|
49
53
|
|
50
54
|
ShopifyAPI::Page.find(1)
|
51
55
|
|
@@ -64,9 +68,9 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
64
68
|
end
|
65
69
|
|
66
70
|
test "logging on #find with an error" do
|
67
|
-
fake
|
71
|
+
fake("pages/2", method: :get, body: nil, status: 404)
|
68
72
|
|
69
|
-
assert_raises
|
73
|
+
assert_raises(ActiveResource::ResourceNotFound) do
|
70
74
|
ShopifyAPI::Page.find(2)
|
71
75
|
end
|
72
76
|
|
@@ -103,7 +107,7 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
103
107
|
|
104
108
|
ShopifyAPI::Page.find(1)
|
105
109
|
|
106
|
-
assert_equal
|
110
|
+
assert_equal(1, @logger.logged(:warn).size)
|
107
111
|
|
108
112
|
assert_match(
|
109
113
|
%r{\[DEPRECATED\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
|
@@ -125,7 +129,7 @@ class LogSubscriberTest < Test::Unit::TestCase
|
|
125
129
|
|
126
130
|
ShopifyAPI::Page.find(1)
|
127
131
|
|
128
|
-
assert_equal
|
132
|
+
assert_equal(1, @logger.logged(:warn).size)
|
129
133
|
|
130
134
|
assert_match(
|
131
135
|
%r{\[API Version Warning\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
|
@@ -4,30 +4,31 @@ require 'test_helper'
|
|
4
4
|
class DiscountCodeBatchTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
super
|
7
|
-
fake
|
7
|
+
fake('price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch'))
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_get_batch
|
11
|
-
batch = ShopifyAPI::DiscountCodeBatch.find
|
11
|
+
batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
|
12
12
|
|
13
|
-
assert_equal
|
13
|
+
assert_equal(989355119, batch.id)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_get_batch_discount_codes
|
17
|
-
fake
|
17
|
+
fake(
|
18
|
+
'price_rules/102586120/batch/989355119/discount_codes',
|
18
19
|
method: :get,
|
19
20
|
status: 200,
|
20
21
|
body: load_fixture('discount_code_batch_discount_codes')
|
21
|
-
|
22
|
-
batch = ShopifyAPI::DiscountCodeBatch.find
|
22
|
+
)
|
23
|
+
batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
|
23
24
|
discount_code_job = batch.discount_code_job
|
24
25
|
|
25
|
-
assert_equal
|
26
|
-
assert
|
26
|
+
assert_equal(3, discount_code_job.count)
|
27
|
+
assert(discount_code_job[2].errors.present?)
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_create_batch
|
30
|
-
fake
|
31
|
+
fake('price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch'))
|
31
32
|
batch = ShopifyAPI::DiscountCodeBatch.new
|
32
33
|
batch.prefix_options[:price_rule_id] = 102586120
|
33
34
|
discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
|
@@ -35,6 +36,6 @@ class DiscountCodeBatchTest < Test::Unit::TestCase
|
|
35
36
|
batch.save
|
36
37
|
|
37
38
|
expected_body = { discount_codes: discount_codes }.to_json
|
38
|
-
assert_equal
|
39
|
+
assert_equal(expected_body, WebMock.last_request.body)
|
39
40
|
end
|
40
41
|
end
|
data/test/discount_code_test.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class DiscountCodeTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
super
|
6
|
-
fake
|
7
|
+
fake('price_rules/102586120/discount_codes/1002091923', body: load_fixture('discount_code'))
|
7
8
|
|
8
|
-
@discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: {price_rule_id: 102586120})
|
9
|
+
@discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: { price_rule_id: 102586120 })
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_get_discount_code
|
12
|
-
fake
|
13
|
-
discount_code = ShopifyAPI::DiscountCode.find
|
13
|
+
fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_code'))
|
14
|
+
discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: { price_rule_id: 102586120 })
|
14
15
|
|
15
|
-
assert_equal
|
16
|
+
assert_equal(1002091923, discount_code.id)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_get_all_discount_codes
|
19
|
-
fake
|
20
|
-
discount_codes = ShopifyAPI::DiscountCode.all
|
20
|
+
fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes'))
|
21
|
+
discount_codes = ShopifyAPI::DiscountCode.all(params: { price_rule_id: 102586120 })
|
21
22
|
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
23
|
+
assert_equal(1, discount_codes.length)
|
24
|
+
assert_equal(1002091923, discount_codes.first.id)
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_create_discount_code
|
27
|
-
fake
|
28
|
+
fake('price_rules/102586120/discount_codes', method: :post, status: 201, body: load_fixture('discount_code'))
|
28
29
|
discount_code = ShopifyAPI::DiscountCode.new
|
29
30
|
discount_code.prefix_options[:price_rule_id] = 102586120
|
30
31
|
discount_code.code = "SUMMERSALE10"
|
31
32
|
discount_code.save
|
32
33
|
|
33
|
-
assert_equal
|
34
|
+
assert_equal('{"discount_code":{"code":"SUMMERSALE10"}}', WebMock.last_request.body)
|
34
35
|
end
|
35
36
|
|
36
37
|
def test_update_discount_code
|
@@ -38,16 +39,21 @@ class DiscountCodeTest < Test::Unit::TestCase
|
|
38
39
|
discount_code_response['discount_code']['code'] = "WINTERSALE50"
|
39
40
|
@discount_code.code = "WINTERSALE50"
|
40
41
|
|
41
|
-
fake
|
42
|
+
fake(
|
43
|
+
'price_rules/102586120/discount_codes/1002091923',
|
44
|
+
method: :put,
|
45
|
+
status: 200,
|
46
|
+
body: ActiveSupport::JSON.encode(discount_code_response)
|
47
|
+
)
|
42
48
|
|
43
49
|
@discount_code.save
|
44
50
|
|
45
|
-
assert_equal
|
51
|
+
assert_equal(discount_code_response['discount_code']['code'], @discount_code.code)
|
46
52
|
end
|
47
53
|
|
48
54
|
def test_delete_discount_code
|
49
|
-
fake
|
55
|
+
fake('price_rules/102586120/discount_codes/1002091923', method: :delete, body: 'destroyed')
|
50
56
|
|
51
|
-
assert
|
57
|
+
assert(@discount_code.destroy)
|
52
58
|
end
|
53
59
|
end
|