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/blog_test.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
class BlogTest < Test::Unit::TestCase
|
3
4
|
test "blog creation" do
|
4
|
-
fake
|
5
|
-
|
6
|
-
assert_equal
|
5
|
+
fake("blogs", method: :post, status: 202, body: load_fixture('blog'))
|
6
|
+
ShopifyAPI::Blog.create(title: "Test Blog")
|
7
|
+
assert_equal('{"blog":{"title":"Test Blog"}}', WebMock.last_request.body)
|
7
8
|
end
|
8
9
|
end
|
@@ -1,17 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CarrierServiceTest < Test::Unit::TestCase
|
4
5
|
test 'new should create carrier service' do
|
5
|
-
fake
|
6
|
-
carrier_service = ShopifyAPI::CarrierService.new(:
|
6
|
+
fake("carrier_services", method: :post, body: load_fixture('carrier_service'))
|
7
|
+
carrier_service = ShopifyAPI::CarrierService.new(name: "Some Postal Service")
|
7
8
|
carrier_service.save
|
8
|
-
assert_equal
|
9
|
+
assert_equal("Some Postal Service", carrier_service.name)
|
9
10
|
end
|
10
11
|
|
11
12
|
test 'find should return the carrier service' do
|
12
|
-
fake
|
13
|
+
fake("carrier_services/123456", method: :get, body: load_fixture('carrier_service'))
|
13
14
|
carrier_service = ShopifyAPI::CarrierService.find(123456)
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
15
|
+
assert_equal(123456, carrier_service.id)
|
16
|
+
assert_equal("Some Postal Service", carrier_service.name)
|
16
17
|
end
|
17
18
|
end
|
data/test/cart_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CartTest < Test::Unit::TestCase
|
@@ -10,4 +11,4 @@ class CartTest < Test::Unit::TestCase
|
|
10
11
|
assert_equal 1, carts.first.line_items.size
|
11
12
|
assert_equal 'test', carts.first.line_items.first.title
|
12
13
|
end
|
13
|
-
end
|
14
|
+
end
|
data/test/collect_test.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CollectTest < Test::Unit::TestCase
|
4
5
|
test "#create should create a collect" do
|
5
|
-
fake
|
6
|
-
link = ShopifyAPI::Collect.create(:
|
7
|
-
assert_equal
|
6
|
+
fake("collects", method: :post, status: 201, body: load_fixture('collect'))
|
7
|
+
link = ShopifyAPI::Collect.create(product_id: 921728736, collection_id: 841564295)
|
8
|
+
assert_equal(841564295, link.id)
|
8
9
|
end
|
9
10
|
end
|
@@ -1,42 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class CollectionListingTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_get_collection_listings
|
6
|
-
fake
|
6
|
+
fake("collection_listings", method: :get, status: 201, body: load_fixture('collection_listings'))
|
7
7
|
|
8
8
|
collection_listings = ShopifyAPI::CollectionListing.find(:all)
|
9
9
|
|
10
|
-
assert_equal
|
11
|
-
assert_equal
|
12
|
-
assert_equal
|
10
|
+
assert_equal(1, collection_listings.count)
|
11
|
+
assert_equal(1, collection_listings.first.collection_id)
|
12
|
+
assert_equal('Home page', collection_listings.first.title)
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_get_collection_listing
|
16
|
-
fake
|
16
|
+
fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
|
17
17
|
|
18
18
|
collection_listing = ShopifyAPI::CollectionListing.find(1)
|
19
19
|
|
20
|
-
assert_equal
|
21
|
-
assert_equal
|
20
|
+
assert_equal(1, collection_listing.collection_id)
|
21
|
+
assert_equal('Home page', collection_listing.title)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_get_collection_listing_reload
|
25
|
-
fake
|
25
|
+
fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
|
26
26
|
|
27
27
|
collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
|
28
28
|
collection_listing.reload
|
29
29
|
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
30
|
+
assert_equal(1, collection_listing.collection_id)
|
31
|
+
assert_equal('Home page', collection_listing.title)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_get_collection_listing_product_ids
|
35
|
-
fake
|
35
|
+
fake(
|
36
|
+
"collection_listings/1/product_ids",
|
37
|
+
method: :get,
|
38
|
+
status: 201,
|
39
|
+
body: load_fixture('collection_listing_product_ids')
|
40
|
+
)
|
36
41
|
|
37
42
|
collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
|
38
43
|
|
39
|
-
assert_equal
|
44
|
+
assert_equal([1, 2], collection_listing.product_ids)
|
40
45
|
end
|
41
46
|
|
42
47
|
def test_get_collection_listing_product_ids_multi_page_with_cursor
|
@@ -61,8 +66,8 @@ class CollectionListingTest < Test::Unit::TestCase
|
|
61
66
|
)
|
62
67
|
|
63
68
|
product_ids = collection_listing.product_ids
|
64
|
-
assert_equal
|
65
|
-
assert
|
69
|
+
assert_equal([1, 2], product_ids)
|
70
|
+
assert(product_ids.next_page?)
|
66
71
|
|
67
72
|
fake(
|
68
73
|
"collection_listings/1/product_ids",
|
@@ -74,6 +79,6 @@ class CollectionListingTest < Test::Unit::TestCase
|
|
74
79
|
)
|
75
80
|
|
76
81
|
next_page = product_ids.fetch_next_page
|
77
|
-
assert_equal
|
82
|
+
assert_equal([3, 4], next_page)
|
78
83
|
end
|
79
84
|
end
|
@@ -3,23 +3,23 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class CollectionPublicationTest < Test::Unit::TestCase
|
5
5
|
def test_get_all_collection_publications
|
6
|
-
fake
|
6
|
+
fake('publications/55650051/collection_publications', body: load_fixture('collection_publications'))
|
7
7
|
collection_publications = ShopifyAPI::CollectionPublication.find(:all, params: { publication_id: 55650051 })
|
8
8
|
|
9
|
-
assert_equal
|
10
|
-
assert_equal
|
9
|
+
assert_equal(96062799894, collection_publications.first.id)
|
10
|
+
assert_equal(55650051, collection_publications.first.publication_id)
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_get_collection_publication
|
14
|
-
fake
|
14
|
+
fake('publications/55650051/collection_publications/647162527768', body: load_fixture('collection_publication'))
|
15
15
|
collection_publication = ShopifyAPI::CollectionPublication.find(647162527768, params: { publication_id: 55650051 })
|
16
16
|
|
17
|
-
assert_equal
|
18
|
-
assert_equal
|
17
|
+
assert_equal(96062799894, collection_publication.id)
|
18
|
+
assert_equal(55650051, collection_publication.publication_id)
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_create_collection_publication
|
22
|
-
fake
|
22
|
+
fake('publications/55650051/collection_publications', method: :post, body: load_fixture('collection_publication'))
|
23
23
|
ShopifyAPI::CollectionPublication.create(
|
24
24
|
publication_id: 55650051,
|
25
25
|
published_at: "2018-01-29T14:06:08-05:00",
|
@@ -35,6 +35,6 @@ class CollectionPublicationTest < Test::Unit::TestCase
|
|
35
35
|
},
|
36
36
|
}.to_json
|
37
37
|
|
38
|
-
assert_equal
|
38
|
+
assert_equal(expected_body, WebMock.last_request.body)
|
39
39
|
end
|
40
40
|
end
|
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
17
|
"#{@ua_header}, \"X-Shopify-Access-Token\"=>\"access_token\"}"
|
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},
|