duodealer_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +23 -0
- data/Gemfile +5 -0
- data/Gemfile_ar41 +5 -0
- data/Gemfile_ar50 +5 -0
- data/Gemfile_ar51 +5 -0
- data/Gemfile_ar_master +5 -0
- data/RELEASING +13 -0
- data/Rakefile +44 -0
- data/docker-compose.yml +13 -0
- data/docs/graphql.md +191 -0
- data/duodealer_api.gemspec +38 -0
- data/lib/active_resource/connection_ext.rb +10 -0
- data/lib/active_resource/detailed_log_subscriber.rb +52 -0
- data/lib/active_resource/json_errors.rb +31 -0
- data/lib/duodealer_api.rb +33 -0
- data/lib/duodealer_api/api_version.rb +205 -0
- data/lib/duodealer_api/connection.rb +35 -0
- data/lib/duodealer_api/countable.rb +14 -0
- data/lib/duodealer_api/disable_prefix_check.rb +31 -0
- data/lib/duodealer_api/events.rb +7 -0
- data/lib/duodealer_api/graphql.rb +79 -0
- data/lib/duodealer_api/graphql/http_client.rb +22 -0
- data/lib/duodealer_api/graphql/railtie.rb +17 -0
- data/lib/duodealer_api/graphql/task.rake +97 -0
- data/lib/duodealer_api/limits.rb +76 -0
- data/lib/duodealer_api/message_enricher.rb +23 -0
- data/lib/duodealer_api/meta.rb +15 -0
- data/lib/duodealer_api/metafields.rb +20 -0
- data/lib/duodealer_api/paginated_collection.rb +69 -0
- data/lib/duodealer_api/pagination_link_headers.rb +33 -0
- data/lib/duodealer_api/resources.rb +3 -0
- data/lib/duodealer_api/resources/abandoned_checkout.rb +7 -0
- data/lib/duodealer_api/resources/access_scope.rb +10 -0
- data/lib/duodealer_api/resources/access_token.rb +8 -0
- data/lib/duodealer_api/resources/address.rb +4 -0
- data/lib/duodealer_api/resources/announcement.rb +4 -0
- data/lib/duodealer_api/resources/api_permission.rb +9 -0
- data/lib/duodealer_api/resources/application_charge.rb +15 -0
- data/lib/duodealer_api/resources/application_credit.rb +4 -0
- data/lib/duodealer_api/resources/array_base.rb +13 -0
- data/lib/duodealer_api/resources/article.rb +21 -0
- data/lib/duodealer_api/resources/asset.rb +100 -0
- data/lib/duodealer_api/resources/assigned_fulfillment_order.rb +16 -0
- data/lib/duodealer_api/resources/base.rb +162 -0
- data/lib/duodealer_api/resources/billing_address.rb +4 -0
- data/lib/duodealer_api/resources/blog.rb +10 -0
- data/lib/duodealer_api/resources/carrier_service.rb +4 -0
- data/lib/duodealer_api/resources/cart.rb +4 -0
- data/lib/duodealer_api/resources/checkout.rb +30 -0
- data/lib/duodealer_api/resources/collect.rb +6 -0
- data/lib/duodealer_api/resources/collection.rb +14 -0
- data/lib/duodealer_api/resources/collection_listing.rb +18 -0
- data/lib/duodealer_api/resources/collection_publication.rb +10 -0
- data/lib/duodealer_api/resources/comment.rb +9 -0
- data/lib/duodealer_api/resources/country.rb +4 -0
- data/lib/duodealer_api/resources/currency.rb +6 -0
- data/lib/duodealer_api/resources/custom_collection.rb +19 -0
- data/lib/duodealer_api/resources/customer.rb +29 -0
- data/lib/duodealer_api/resources/customer_group.rb +5 -0
- data/lib/duodealer_api/resources/customer_invite.rb +4 -0
- data/lib/duodealer_api/resources/customer_saved_search.rb +11 -0
- data/lib/duodealer_api/resources/discount_code.rb +9 -0
- data/lib/duodealer_api/resources/draft_order.rb +14 -0
- data/lib/duodealer_api/resources/draft_order_invoice.rb +4 -0
- data/lib/duodealer_api/resources/event.rb +8 -0
- data/lib/duodealer_api/resources/fulfillment.rb +47 -0
- data/lib/duodealer_api/resources/fulfillment_event.rb +15 -0
- data/lib/duodealer_api/resources/fulfillment_order.rb +137 -0
- data/lib/duodealer_api/resources/fulfillment_order_locations_for_move.rb +4 -0
- data/lib/duodealer_api/resources/fulfillment_request.rb +15 -0
- data/lib/duodealer_api/resources/fulfillment_service.rb +4 -0
- data/lib/duodealer_api/resources/fulfillment_v2.rb +20 -0
- data/lib/duodealer_api/resources/gift_card.rb +7 -0
- data/lib/duodealer_api/resources/image.rb +16 -0
- data/lib/duodealer_api/resources/inventory_item.rb +6 -0
- data/lib/duodealer_api/resources/inventory_level.rb +55 -0
- data/lib/duodealer_api/resources/line_item.rb +14 -0
- data/lib/duodealer_api/resources/location.rb +8 -0
- data/lib/duodealer_api/resources/marketing_event.rb +10 -0
- data/lib/duodealer_api/resources/metafield.rb +13 -0
- data/lib/duodealer_api/resources/note_attribute.rb +4 -0
- data/lib/duodealer_api/resources/option.rb +4 -0
- data/lib/duodealer_api/resources/order.rb +43 -0
- data/lib/duodealer_api/resources/order_risk.rb +8 -0
- data/lib/duodealer_api/resources/page.rb +6 -0
- data/lib/duodealer_api/resources/payment.rb +7 -0
- data/lib/duodealer_api/resources/payment_details.rb +4 -0
- data/lib/duodealer_api/resources/ping.rb +3 -0
- data/lib/duodealer_api/resources/policy.rb +7 -0
- data/lib/duodealer_api/resources/price_rule.rb +8 -0
- data/lib/duodealer_api/resources/product.rb +35 -0
- data/lib/duodealer_api/resources/product_listing.rb +16 -0
- data/lib/duodealer_api/resources/product_publication.rb +10 -0
- data/lib/duodealer_api/resources/province.rb +5 -0
- data/lib/duodealer_api/resources/publication.rb +5 -0
- data/lib/duodealer_api/resources/receipt.rb +4 -0
- data/lib/duodealer_api/resources/recurring_application_charge.rb +31 -0
- data/lib/duodealer_api/resources/redirect.rb +4 -0
- data/lib/duodealer_api/resources/refund.rb +14 -0
- data/lib/duodealer_api/resources/report.rb +4 -0
- data/lib/duodealer_api/resources/resource_feedback.rb +19 -0
- data/lib/duodealer_api/resources/rule.rb +4 -0
- data/lib/duodealer_api/resources/script_tag.rb +4 -0
- data/lib/duodealer_api/resources/shipping_address.rb +4 -0
- data/lib/duodealer_api/resources/shipping_line.rb +4 -0
- data/lib/duodealer_api/resources/shipping_rate.rb +7 -0
- data/lib/duodealer_api/resources/shipping_zone.rb +4 -0
- data/lib/duodealer_api/resources/shop.rb +25 -0
- data/lib/duodealer_api/resources/smart_collection.rb +19 -0
- data/lib/duodealer_api/resources/storefront_access_token.rb +4 -0
- data/lib/duodealer_api/resources/tax_line.rb +4 -0
- data/lib/duodealer_api/resources/tax_service.rb +4 -0
- data/lib/duodealer_api/resources/tender_transaction.rb +6 -0
- data/lib/duodealer_api/resources/theme.rb +4 -0
- data/lib/duodealer_api/resources/transaction.rb +5 -0
- data/lib/duodealer_api/resources/usage_charge.rb +5 -0
- data/lib/duodealer_api/resources/user.rb +4 -0
- data/lib/duodealer_api/resources/variant.rb +8 -0
- data/lib/duodealer_api/resources/webhook.rb +4 -0
- data/lib/duodealer_api/session.rb +171 -0
- data/lib/duodealer_api/version.rb +3 -0
- data/shipit.rubygems.yml +1 -0
- data/test/abandoned_checkouts_test.rb +29 -0
- data/test/access_scope_test.rb +23 -0
- data/test/access_token_test.rb +19 -0
- data/test/active_resource/json_errors_test.rb +19 -0
- data/test/api_permission_test.rb +9 -0
- data/test/api_version_test.rb +157 -0
- data/test/application_charge_test.rb +79 -0
- data/test/application_credit_test.rb +35 -0
- data/test/article_test.rb +73 -0
- data/test/asset_test.rb +18 -0
- data/test/assigned_fulfillment_order_test.rb +77 -0
- data/test/base_test.rb +198 -0
- data/test/blog_test.rb +8 -0
- data/test/carrier_service_test.rb +17 -0
- data/test/cart_test.rb +13 -0
- data/test/checkouts_test.rb +77 -0
- data/test/collect_test.rb +9 -0
- data/test/collection_listing_test.rb +79 -0
- data/test/collection_publication_test.rb +40 -0
- data/test/collection_test.rb +49 -0
- data/test/countable_test.rb +13 -0
- data/test/currency_test.rb +21 -0
- data/test/custom_collection_test.rb +9 -0
- data/test/customer_saved_search_test.rb +27 -0
- data/test/customer_test.rb +50 -0
- data/test/detailed_log_subscriber_test.rb +139 -0
- data/test/discount_code_test.rb +53 -0
- data/test/draft_order_test.rb +151 -0
- 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/access_token_delegate.json +4 -0
- data/test/fixtures/api_versions.json +38 -0
- data/test/fixtures/apis.json +42 -0
- data/test/fixtures/application_charge.json +16 -0
- data/test/fixtures/application_charges.json +57 -0
- data/test/fixtures/application_credit.json +12 -0
- data/test/fixtures/application_credits.json +24 -0
- data/test/fixtures/article.json +15 -0
- data/test/fixtures/articles.json +39 -0
- data/test/fixtures/asset.json +9 -0
- data/test/fixtures/assets.json +136 -0
- data/test/fixtures/assigned_fulfillment_orders.json +78 -0
- data/test/fixtures/authors.json +1 -0
- data/test/fixtures/blog.json +13 -0
- data/test/fixtures/blogs.json +13 -0
- data/test/fixtures/carrier_service.json +9 -0
- data/test/fixtures/carts.json +43 -0
- data/test/fixtures/checkout.json +160 -0
- data/test/fixtures/checkouts.json +162 -0
- data/test/fixtures/collect.json +12 -0
- data/test/fixtures/collection.json +17 -0
- data/test/fixtures/collection_listing.json +11 -0
- data/test/fixtures/collection_listing_product_ids.json +1 -0
- data/test/fixtures/collection_listing_product_ids2.json +1 -0
- data/test/fixtures/collection_listings.json +13 -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/custom_collection.json +17 -0
- data/test/fixtures/customer_invite.json +9 -0
- data/test/fixtures/customer_saved_search.json +9 -0
- data/test/fixtures/customer_saved_search_customers.json +60 -0
- data/test/fixtures/customers.json +59 -0
- data/test/fixtures/customers_account_activation_url.json +3 -0
- data/test/fixtures/customers_search.json +60 -0
- data/test/fixtures/discount_code.json +10 -0
- data/test/fixtures/discount_codes.json +12 -0
- data/test/fixtures/draft_order.json +159 -0
- data/test/fixtures/draft_order_completed.json +159 -0
- data/test/fixtures/draft_order_invoice.json +9 -0
- data/test/fixtures/draft_orders.json +161 -0
- data/test/fixtures/engagement.json +15 -0
- data/test/fixtures/events.json +31 -0
- data/test/fixtures/fulfillment.json +49 -0
- data/test/fixtures/fulfillment_event.json +12 -0
- data/test/fixtures/fulfillment_order.json +38 -0
- data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
- data/test/fixtures/fulfillment_orders.json +78 -0
- data/test/fixtures/fulfillment_request.json +28 -0
- data/test/fixtures/fulfillment_service.json +10 -0
- data/test/fixtures/fulfillments.json +53 -0
- data/test/fixtures/gift_card.json +20 -0
- data/test/fixtures/gift_card_disabled.json +20 -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/image.json +10 -0
- data/test/fixtures/images.json +20 -0
- data/test/fixtures/inventory_level.json +7 -0
- data/test/fixtures/inventory_levels.json +24 -0
- data/test/fixtures/marketing_event.json +28 -0
- data/test/fixtures/marketing_events.json +54 -0
- data/test/fixtures/metafield.json +12 -0
- data/test/fixtures/metafields.json +34 -0
- data/test/fixtures/order.json +297 -0
- data/test/fixtures/order_risk.json +14 -0
- data/test/fixtures/order_risks.json +28 -0
- data/test/fixtures/order_with_properties.json +373 -0
- data/test/fixtures/orders.json +299 -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/policies.json +8 -0
- data/test/fixtures/price_rule.json +27 -0
- data/test/fixtures/price_rules.json +28 -0
- data/test/fixtures/product.json +116 -0
- data/test/fixtures/product_listing.json +86 -0
- data/test/fixtures/product_listing_product_ids.json +1 -0
- data/test/fixtures/product_listing_product_ids2.json +1 -0
- data/test/fixtures/product_listings.json +174 -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/recurring_application_charge.json +22 -0
- data/test/fixtures/recurring_application_charge_adjustment.json +5 -0
- data/test/fixtures/recurring_application_charges.json +106 -0
- data/test/fixtures/redirect.json +7 -0
- data/test/fixtures/refund.json +112 -0
- data/test/fixtures/report.json +9 -0
- data/test/fixtures/reports.json +11 -0
- data/test/fixtures/script_tag.json +10 -0
- data/test/fixtures/script_tags.json +18 -0
- data/test/fixtures/shipping_rates.json +12 -0
- data/test/fixtures/shipping_zones.json +315 -0
- data/test/fixtures/shop.json +26 -0
- data/test/fixtures/smart_collection.json +21 -0
- data/test/fixtures/smart_collection_products.json +155 -0
- data/test/fixtures/storefront_access_token.json +9 -0
- data/test/fixtures/storefront_access_tokens.json +18 -0
- data/test/fixtures/tags.json +1 -0
- data/test/fixtures/tax_service.json +9 -0
- data/test/fixtures/tender_transactions.json +52 -0
- data/test/fixtures/transaction.json +29 -0
- data/test/fixtures/usage_charge.json +11 -0
- data/test/fixtures/usage_charges.json +23 -0
- data/test/fixtures/user.json +21 -0
- data/test/fixtures/users.json +42 -0
- data/test/fixtures/variant.json +23 -0
- data/test/fixtures/variants.json +88 -0
- data/test/fixtures/webhook.json +10 -0
- data/test/fixtures/webhooks.json +18 -0
- data/test/fulfillment_event_test.rb +69 -0
- data/test/fulfillment_order_test.rb +462 -0
- data/test/fulfillment_order_test_helper.rb +7 -0
- data/test/fulfillment_request_test.rb +33 -0
- data/test/fulfillment_service_test.rb +17 -0
- data/test/fulfillment_test.rb +224 -0
- data/test/fulfillment_v2_test.rb +62 -0
- data/test/gift_card_test.rb +22 -0
- data/test/graphql/http_client_test.rb +26 -0
- data/test/graphql_test.rb +147 -0
- data/test/image_test.rb +39 -0
- data/test/inventory_level_test.rb +59 -0
- data/test/lib/webmock_extensions/last_request.rb +16 -0
- data/test/limits_test.rb +38 -0
- data/test/location_test.rb +14 -0
- data/test/marketing_event_test.rb +68 -0
- data/test/message_enricher_test.rb +45 -0
- data/test/meta_test.rb +49 -0
- data/test/metafield_test.rb +46 -0
- data/test/order_risk_test.rb +46 -0
- data/test/order_test.rb +125 -0
- data/test/pagination_test.rb +257 -0
- data/test/payment_test.rb +19 -0
- data/test/policy_test.rb +19 -0
- data/test/price_rule_test.rb +65 -0
- data/test/product_listing_test.rb +97 -0
- data/test/product_publication_test.rb +40 -0
- data/test/product_test.rb +60 -0
- data/test/publication_test.rb +12 -0
- data/test/recurring_application_charge_test.rb +142 -0
- data/test/redirect_test.rb +9 -0
- data/test/refund_test.rb +32 -0
- data/test/report_test.rb +35 -0
- data/test/resource_feedback_test.rb +42 -0
- data/test/script_tag_test.rb +30 -0
- data/test/session_test.rb +366 -0
- data/test/shipping_rate_test.rb +17 -0
- data/test/shipping_zone_test.rb +10 -0
- data/test/shop_test.rb +68 -0
- data/test/smart_collection_test.rb +35 -0
- data/test/storefront_access_token_test.rb +32 -0
- data/test/tax_service_test.rb +9 -0
- data/test/tender_transaction_test.rb +18 -0
- data/test/test_helper.rb +124 -0
- data/test/transaction_test.rb +17 -0
- data/test/usage_charge_test.rb +21 -0
- data/test/user_test.rb +17 -0
- data/test/variant_test.rb +46 -0
- data/test/webhook_test.rb +21 -0
- metadata +541 -0
data/test/blog_test.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class BlogTest < Test::Unit::TestCase
|
3
|
+
test "blog creation" do
|
4
|
+
fake "blogs", :method => :post, :status => 202, :body => load_fixture('blog')
|
5
|
+
blog = DuodealerAPI::Blog.create(:title => "Test Blog")
|
6
|
+
assert_equal '{"blog":{"title":"Test Blog"}}', WebMock.last_request.body
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CarrierServiceTest < Test::Unit::TestCase
|
4
|
+
test 'new should create carrier service' do
|
5
|
+
fake "carrier_services", :method => :post, :body => load_fixture('carrier_service')
|
6
|
+
carrier_service = DuodealerAPI::CarrierService.new(:name => "Some Postal Service")
|
7
|
+
carrier_service.save
|
8
|
+
assert_equal "Some Postal Service" , carrier_service.name
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'find should return the carrier service' do
|
12
|
+
fake "carrier_services/123456", :method => :get, :body => load_fixture('carrier_service')
|
13
|
+
carrier_service = DuodealerAPI::CarrierService.find(123456)
|
14
|
+
assert_equal 123456 , carrier_service.id
|
15
|
+
assert_equal "Some Postal Service", carrier_service.name
|
16
|
+
end
|
17
|
+
end
|
data/test/cart_test.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CartTest < Test::Unit::TestCase
|
4
|
+
test 'all should return all carts' do
|
5
|
+
fake 'carts'
|
6
|
+
carts = DuodealerAPI::Cart.all
|
7
|
+
assert_equal carts.size, 2
|
8
|
+
assert_equal 2, carts.first.id
|
9
|
+
assert_equal "3eed8183d4281db6ea82ee2b8f23e9cc", carts.first.token
|
10
|
+
assert_equal 1, carts.first.line_items.size
|
11
|
+
assert_equal 'test', carts.first.line_items.first.title
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CheckoutsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@expected_checkouts = JSON.parse(load_fixture('checkouts'))['checkouts']
|
9
|
+
@expected_checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
|
10
|
+
end
|
11
|
+
|
12
|
+
test ".headers includes a version" do
|
13
|
+
assert_equal "2016-09-06", DuodealerAPI::Checkout.headers["X-DuoDealer-Checkout-Version"]
|
14
|
+
assert_nil DuodealerAPI::Base.headers["X-DuoDealer-Checkout-Version"]
|
15
|
+
end
|
16
|
+
|
17
|
+
test ":create creates a checkout" do
|
18
|
+
fake 'checkouts', method: :post, status: 201, body: load_fixture('checkout')
|
19
|
+
|
20
|
+
checkout = DuodealerAPI::Checkout.create
|
21
|
+
|
22
|
+
assert_equal @expected_checkout_id, checkout.id
|
23
|
+
end
|
24
|
+
|
25
|
+
test "get all checkouts indexed by token" do
|
26
|
+
fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
|
27
|
+
|
28
|
+
checkouts = DuodealerAPI::Checkout.all
|
29
|
+
|
30
|
+
assert_equal @expected_checkout_id, checkouts.first.id
|
31
|
+
assert_equal @expected_checkouts.size, checkouts.size
|
32
|
+
end
|
33
|
+
|
34
|
+
test ":complete completes a checkout" do
|
35
|
+
fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
|
36
|
+
|
37
|
+
checkout = DuodealerAPI::Checkout.find(@expected_checkout_id)
|
38
|
+
|
39
|
+
fake "checkouts/#{@expected_checkout_id}/complete", method: :post, status: 200, body: load_fixture('checkouts')
|
40
|
+
|
41
|
+
checkout.complete
|
42
|
+
end
|
43
|
+
|
44
|
+
test ":ready? returns true when status is 201" do
|
45
|
+
fake "checkouts/#{@expected_checkout_id}", method: :get, status: 201, body: load_fixture('checkout')
|
46
|
+
checkout = DuodealerAPI::Checkout.find(@expected_checkout_id)
|
47
|
+
|
48
|
+
assert_predicate checkout, :ready?
|
49
|
+
end
|
50
|
+
|
51
|
+
test ":ready? returns false when status is 202" do
|
52
|
+
fake "checkouts/#{@expected_checkout_id}", method: :get, status: 202, body: load_fixture('checkout')
|
53
|
+
checkout = DuodealerAPI::Checkout.find(@expected_checkout_id)
|
54
|
+
|
55
|
+
refute_predicate checkout, :ready?
|
56
|
+
end
|
57
|
+
|
58
|
+
test ":payments returns payments for a checkout" do
|
59
|
+
fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
|
60
|
+
checkout = DuodealerAPI::Checkout.find(@expected_checkout_id)
|
61
|
+
|
62
|
+
fake "checkouts/#{@expected_checkout_id}/payments", method: :get, status: 202, body: load_fixture('payments')
|
63
|
+
|
64
|
+
assert_equal 10.00, checkout.payments.first.amount
|
65
|
+
end
|
66
|
+
|
67
|
+
test ":shipping_rates returns shipping rates for a checkout" do
|
68
|
+
fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
|
69
|
+
checkout = DuodealerAPI::Checkout.find(@expected_checkout_id)
|
70
|
+
|
71
|
+
fake("checkouts/#{@expected_checkout_id}/shipping_rates",
|
72
|
+
method: :get,
|
73
|
+
status: 202,
|
74
|
+
body: load_fixture('shipping_rates'))
|
75
|
+
assert_equal "canada_post-INT.TP.BOGUS-4.00", checkout.shipping_rates.first.id
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CollectTest < Test::Unit::TestCase
|
4
|
+
test "#create should create a collect" do
|
5
|
+
fake "collects", :method => :post, :status => 201, :body => load_fixture('collect')
|
6
|
+
link = DuodealerAPI::Collect.create(:product_id => 921728736, :collection_id => 841564295)
|
7
|
+
assert_equal 841564295, link.id
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CollectionListingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_collection_listings
|
6
|
+
fake "collection_listings", method: :get, status: 201, body: load_fixture('collection_listings')
|
7
|
+
|
8
|
+
collection_listings = DuodealerAPI::CollectionListing.find(:all)
|
9
|
+
|
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
|
+
end
|
14
|
+
|
15
|
+
def test_get_collection_listing
|
16
|
+
fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')
|
17
|
+
|
18
|
+
collection_listing = DuodealerAPI::CollectionListing.find(1)
|
19
|
+
|
20
|
+
assert_equal 1, collection_listing.collection_id
|
21
|
+
assert_equal 'Home page', collection_listing.title
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_collection_listing_reload
|
25
|
+
fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')
|
26
|
+
|
27
|
+
collection_listing = DuodealerAPI::CollectionListing.new(collection_id: 1)
|
28
|
+
collection_listing.reload
|
29
|
+
|
30
|
+
assert_equal 1, collection_listing.collection_id
|
31
|
+
assert_equal 'Home page', collection_listing.title
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_collection_listing_product_ids
|
35
|
+
fake "collection_listings/1/product_ids", method: :get, status: 201, body: load_fixture('collection_listing_product_ids')
|
36
|
+
|
37
|
+
collection_listing = DuodealerAPI::CollectionListing.new(collection_id: 1)
|
38
|
+
|
39
|
+
assert_equal [1, 2], collection_listing.product_ids
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_collection_listing_product_ids_multi_page_with_cursor
|
43
|
+
version = DuodealerAPI::ApiVersion.find_version('2019-07')
|
44
|
+
DuodealerAPI::Base.api_version = version.to_s
|
45
|
+
|
46
|
+
collection_listing = DuodealerAPI::CollectionListing.new(collection_id: 1)
|
47
|
+
|
48
|
+
url = "https://this-is-my-test-shop.duodealer.com/admin/api/2019-07/collection_listings/1/product_ids.json"
|
49
|
+
|
50
|
+
next_page_info = "notarealpageinfobutthatsokay"
|
51
|
+
next_page_url = "#{url}?page_info=#{next_page_info}"
|
52
|
+
link_header = "<#{next_page_url}>; rel=\"next\""
|
53
|
+
|
54
|
+
fake(
|
55
|
+
"collection_listings/1/product_ids",
|
56
|
+
method: :get,
|
57
|
+
status: 201,
|
58
|
+
url: url,
|
59
|
+
body: load_fixture('collection_listing_product_ids'),
|
60
|
+
link: link_header,
|
61
|
+
)
|
62
|
+
|
63
|
+
product_ids = collection_listing.product_ids
|
64
|
+
assert_equal [1, 2], product_ids
|
65
|
+
assert product_ids.next_page?
|
66
|
+
|
67
|
+
fake(
|
68
|
+
"collection_listings/1/product_ids",
|
69
|
+
method: :get,
|
70
|
+
status: 201,
|
71
|
+
url: next_page_url,
|
72
|
+
body: load_fixture('collection_listing_product_ids2'),
|
73
|
+
link: link_header,
|
74
|
+
)
|
75
|
+
|
76
|
+
next_page = product_ids.fetch_next_page
|
77
|
+
assert_equal [3, 4], next_page
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CollectionPublicationTest < Test::Unit::TestCase
|
5
|
+
def test_get_all_collection_publications
|
6
|
+
fake 'publications/55650051/collection_publications', body: load_fixture('collection_publications')
|
7
|
+
collection_publications = DuodealerAPI::CollectionPublication.find(:all, params: { publication_id: 55650051 })
|
8
|
+
|
9
|
+
assert_equal 96062799894, collection_publications.first.id
|
10
|
+
assert_equal 55650051, collection_publications.first.publication_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_collection_publication
|
14
|
+
fake 'publications/55650051/collection_publications/647162527768', body: load_fixture('collection_publication')
|
15
|
+
collection_publication = DuodealerAPI::CollectionPublication.find(647162527768, params: { publication_id: 55650051 })
|
16
|
+
|
17
|
+
assert_equal 96062799894, collection_publication.id
|
18
|
+
assert_equal 55650051, collection_publication.publication_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_create_collection_publication
|
22
|
+
fake 'publications/55650051/collection_publications', method: :post, body: load_fixture('collection_publication')
|
23
|
+
DuodealerAPI::CollectionPublication.create(
|
24
|
+
publication_id: 55650051,
|
25
|
+
published_at: "2018-01-29T14:06:08-05:00",
|
26
|
+
published: true,
|
27
|
+
collection_id: 8267093571
|
28
|
+
)
|
29
|
+
|
30
|
+
expected_body = {
|
31
|
+
collection_publication: {
|
32
|
+
published_at: "2018-01-29T14:06:08-05:00",
|
33
|
+
published: true,
|
34
|
+
collection_id: 8267093571,
|
35
|
+
},
|
36
|
+
}.to_json
|
37
|
+
|
38
|
+
assert_equal expected_body, WebMock.last_request.body
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CollectionTest < Test::Unit::TestCase
|
4
|
+
test "Collection get products gets all products in a collection on 2020-01 version" do
|
5
|
+
available_version = DuodealerAPI::Session.new(domain: 'shop2.duodealer.com', token: 'token2', api_version: '2020-01')
|
6
|
+
DuodealerAPI::Base.activate_session(available_version)
|
7
|
+
|
8
|
+
fake(
|
9
|
+
'collections',
|
10
|
+
url: 'https://shop2.duodealer.com/admin/api/2020-01/collections/1.json',
|
11
|
+
method: :get,
|
12
|
+
status: 200,
|
13
|
+
body: load_fixture('collection'),
|
14
|
+
extension: false
|
15
|
+
)
|
16
|
+
|
17
|
+
collection = DuodealerAPI::Collection.find(1)
|
18
|
+
|
19
|
+
fake(
|
20
|
+
'products',
|
21
|
+
url: 'https://shop2.duodealer.com/admin/api/2020-01/collections/1/products.json',
|
22
|
+
method: :get,
|
23
|
+
status: 200,
|
24
|
+
body: load_fixture('collection_products'),
|
25
|
+
extension: false
|
26
|
+
)
|
27
|
+
assert_equal [632910392, 921728736], collection.products.map(&:id)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "Collection get products fails on older api version" do
|
31
|
+
old_version = DuodealerAPI::Session.new(domain: 'shop2.duodealer.com', token: 'token2', api_version: '2019-10')
|
32
|
+
DuodealerAPI::Base.activate_session(old_version)
|
33
|
+
|
34
|
+
fake(
|
35
|
+
'collections',
|
36
|
+
url: 'https://shop2.duodealer.com/admin/api/2019-10/collections/1.json',
|
37
|
+
method: :get,
|
38
|
+
status: 200,
|
39
|
+
body: load_fixture('collection'),
|
40
|
+
extension: false
|
41
|
+
)
|
42
|
+
|
43
|
+
collection = DuodealerAPI::Collection.find(1)
|
44
|
+
|
45
|
+
assert_raises NotImplementedError do
|
46
|
+
collection.products
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'test_helper'
|
4
|
+
class CurrencyTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
fake "currencies", method: :get, body: load_fixture('currencies')
|
8
|
+
end
|
9
|
+
|
10
|
+
context "Currency" do
|
11
|
+
should 'return a list of enabled currencies' do
|
12
|
+
currencies = DuodealerAPI::Currency.all
|
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
|
+
currencies.each do |currency|
|
17
|
+
assert_equal "2018-10-03T14:44:08-04:00", currency.rate_updated_at
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CustomCollectionTest < Test::Unit::TestCase
|
4
|
+
test "#create should create a custom collection" do
|
5
|
+
fake "custom_collections", :method => :post, :status => 201, :body => load_fixture('custom_collection')
|
6
|
+
link = DuodealerAPI::CustomCollection.create(:title => "Macbooks", :image => { :src => "http://example.com/rails_logo.gif" })
|
7
|
+
assert_equal 1063001463, link.id
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CustomerSavedSearchTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
load_customer_saved_search
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_customers_from_customer_saved_search
|
10
|
+
fake 'customers/search.json?customer_saved_search_id=8899730', :body => load_fixture('customer_saved_search_customers'), :extension => false
|
11
|
+
assert_equal 1, @customer_saved_search.customers.length
|
12
|
+
assert_equal 112223902, @customer_saved_search.customers.first.id
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_get_customers_from_customer_saved_search_with_params
|
16
|
+
fake 'customers/search.json?customer_saved_search_id=8899730&limit=1', :body => load_fixture('customer_saved_search_customers'), :extension => false
|
17
|
+
customers = @customer_saved_search.customers(:limit => 1)
|
18
|
+
assert_equal 1, customers.length
|
19
|
+
assert_equal 112223902, customers.first.id
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def load_customer_saved_search
|
24
|
+
fake 'customer_saved_searches/8899730', :body => load_fixture('customer_saved_search')
|
25
|
+
@customer_saved_search = DuodealerAPI::CustomerSavedSearch.find(8899730)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CustomerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
|
7
|
+
fake 'customers/207119551', body: load_fixture('customers')
|
8
|
+
|
9
|
+
@customer = DuodealerAPI::Customer.find(207119551)
|
10
|
+
end
|
11
|
+
|
12
|
+
test "search should get a customers collection" do
|
13
|
+
fake "customers/search.json?query=Bob+country%3AUnited+States", :extension => false, :body => load_fixture('customers_search')
|
14
|
+
|
15
|
+
results = DuodealerAPI::Customer.search(query: 'Bob country:United States')
|
16
|
+
assert_equal 'Bob', results.first.first_name
|
17
|
+
end
|
18
|
+
|
19
|
+
test "account_activation_url should create an account activation url" do
|
20
|
+
fake "customers/207119551/account_activation_url", :method => :post, :body => load_fixture('customers_account_activation_url')
|
21
|
+
|
22
|
+
activation_url = "http://apple.duodealer.com/account/activate/207119551/86688abf23572680740b1c062fa37111-1458248616"
|
23
|
+
assert_equal activation_url, @customer.account_activation_url
|
24
|
+
end
|
25
|
+
|
26
|
+
test "#send_invite with no params" do
|
27
|
+
customer_invite_fixture = load_fixture('customer_invite')
|
28
|
+
customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
|
29
|
+
fake 'customers/207119551/send_invite', method: :post, body: customer_invite_fixture
|
30
|
+
|
31
|
+
customer_invite_response = @customer.send_invite
|
32
|
+
|
33
|
+
assert_equal '{"customer_invite":{}}', WebMock.last_request.body
|
34
|
+
assert_kind_of DuodealerAPI::CustomerInvite, customer_invite_response
|
35
|
+
assert_equal customer_invite['customer_invite']['to'], customer_invite_response.to
|
36
|
+
end
|
37
|
+
|
38
|
+
test "#send_invite with params" do
|
39
|
+
customer_invite_fixture = load_fixture('customer_invite')
|
40
|
+
customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
|
41
|
+
fake 'customers/207119551/send_invite', method: :post, body: customer_invite_fixture
|
42
|
+
|
43
|
+
|
44
|
+
customer_invite_response = @customer.send_invite(DuodealerAPI::CustomerInvite.new(customer_invite['customer_invite']))
|
45
|
+
|
46
|
+
assert_equal customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body)
|
47
|
+
assert_kind_of DuodealerAPI::CustomerInvite, customer_invite_response
|
48
|
+
assert_equal customer_invite['customer_invite']['to'], customer_invite_response.to
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require "active_support/log_subscriber/test_helper"
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class LogSubscriberTest < Test::Unit::TestCase
|
6
|
+
include ActiveSupport::LogSubscriber::TestHelper
|
7
|
+
|
8
|
+
attr_reader :request_headers
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@page = { :page => { :id => 1, :title => 'Duodealer API' } }.to_json
|
13
|
+
@ua_header = "\"User-Agent\"=>\"DuodealerAPI/#{DuodealerAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
|
14
|
+
@request_headers = "Headers: {\"Accept\"=>\"application/json\", " \
|
15
|
+
"#{@ua_header}, \"X-DuoDealer-Access-Token\"=>\"access_token\"}"
|
16
|
+
|
17
|
+
DuodealerAPI::Base.clear_session
|
18
|
+
fake("apis",
|
19
|
+
url: "https://app.duodealer.com/services/apis.json",
|
20
|
+
method: :get,
|
21
|
+
status: 200,
|
22
|
+
api_version: :stub,
|
23
|
+
body: load_fixture('apis'))
|
24
|
+
DuodealerAPI::ApiVersion.fetch_known_versions
|
25
|
+
session = DuodealerAPI::Session.new(
|
26
|
+
domain: "https://this-is-my-test-shop.duodealer.com",
|
27
|
+
token: "access_token",
|
28
|
+
api_version: '2019-01'
|
29
|
+
)
|
30
|
+
|
31
|
+
DuodealerAPI::Base.activate_session(session)
|
32
|
+
|
33
|
+
ActiveResource::LogSubscriber.attach_to :active_resource
|
34
|
+
ActiveResource::DetailedLogSubscriber.attach_to :active_resource_detailed
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
super
|
39
|
+
DuodealerAPI::ApiVersion.clear_known_versions
|
40
|
+
DuodealerAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_logger(logger)
|
44
|
+
ActiveResource::Base.logger = logger
|
45
|
+
end
|
46
|
+
|
47
|
+
test "logging on #find" do
|
48
|
+
fake "pages/1", :method => :get, :body => @page
|
49
|
+
|
50
|
+
DuodealerAPI::Page.find(1)
|
51
|
+
|
52
|
+
assert_equal(4, @logger.logged(:info).size)
|
53
|
+
assert_equal(
|
54
|
+
"GET https://this-is-my-test-shop.duodealer.com:443/admin/api/2019-01/pages/1.json",
|
55
|
+
@logger.logged(:info)[0]
|
56
|
+
)
|
57
|
+
assert_match(/\-\-\> 200/, @logger.logged(:info)[1])
|
58
|
+
assert_equal(request_headers, @logger.logged(:info)[2])
|
59
|
+
assert_match(
|
60
|
+
%r{(Response:\n\{\"page\"\:\{\"id\"\:1,\"title\"\:\"Duodealer API\"\}\})|
|
61
|
+
(Response:\n\{\"page\"\:\{\"title\"\:\"Duodealer API\",\"id\"\:1\}\})},
|
62
|
+
@logger.logged(:info)[3]
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
test "logging on #find with an error" do
|
67
|
+
fake "pages/2", :method => :get, :body => nil, :status => 404
|
68
|
+
|
69
|
+
assert_raises ActiveResource::ResourceNotFound do
|
70
|
+
DuodealerAPI::Page.find(2)
|
71
|
+
end
|
72
|
+
|
73
|
+
if ar_version_before?('5.1.0')
|
74
|
+
assert_equal(4, @logger.logged(:info).size)
|
75
|
+
assert_equal(
|
76
|
+
"GET https://this-is-my-test-shop.duodealer.com:443/admin/api/2019-01/pages/2.json",
|
77
|
+
@logger.logged(:info)[0]
|
78
|
+
)
|
79
|
+
assert_match(/\-\-\> 404/, @logger.logged(:info)[1])
|
80
|
+
assert_equal(request_headers, @logger.logged(:info)[2])
|
81
|
+
assert_equal("Response:", @logger.logged(:info)[3])
|
82
|
+
else
|
83
|
+
assert_equal(2, @logger.logged(:error).size)
|
84
|
+
assert_equal(
|
85
|
+
"GET https://this-is-my-test-shop.duodealer.com:443/admin/api/2019-01/pages/2.json",
|
86
|
+
@logger.logged(:error)[0]
|
87
|
+
)
|
88
|
+
assert_match(/\-\-\> 404/, @logger.logged(:error)[1])
|
89
|
+
|
90
|
+
assert_equal(2, @logger.logged(:info).size)
|
91
|
+
assert_equal(request_headers, @logger.logged(:info)[0])
|
92
|
+
assert_equal("Response:", @logger.logged(:info)[1])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test "warns when the server responds with a x-duodealer-api-deprecated-reason header" do
|
97
|
+
fake(
|
98
|
+
"pages/1",
|
99
|
+
method: :get,
|
100
|
+
body: @page,
|
101
|
+
x_duodealer_api_deprecated_reason: 'https://help.duodealer.com/en/api/getting-started/api-deprecations'
|
102
|
+
)
|
103
|
+
|
104
|
+
DuodealerAPI::Page.find(1)
|
105
|
+
|
106
|
+
assert_equal 1, @logger.logged(:warn).size
|
107
|
+
|
108
|
+
assert_match(
|
109
|
+
%r{\[DEPRECATED\] DuodealerAPI made a call to GET /admin/api/2019-01/pages/1.json},
|
110
|
+
@logger.logged(:warn).first
|
111
|
+
)
|
112
|
+
assert_match(
|
113
|
+
%r{See https:\/\/help.duodealer.com\/en\/api\/getting-started\/api-deprecations for more details.},
|
114
|
+
@logger.logged(:warn).first
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
test "warns when the server responds with a x-duodealer-api-version-warning header" do
|
119
|
+
fake(
|
120
|
+
"pages/1",
|
121
|
+
method: :get,
|
122
|
+
body: @page,
|
123
|
+
x_duodealer_api_version_warning: 'https://duodealer.dev/concepts/about-apis/versioning'
|
124
|
+
)
|
125
|
+
|
126
|
+
DuodealerAPI::Page.find(1)
|
127
|
+
|
128
|
+
assert_equal 1, @logger.logged(:warn).size
|
129
|
+
|
130
|
+
assert_match(
|
131
|
+
%r{\[API Version Warning\] DuodealerAPI made a call to GET /admin/api/2019-01/pages/1.json},
|
132
|
+
@logger.logged(:warn).first
|
133
|
+
)
|
134
|
+
assert_match(
|
135
|
+
%r{See https:\/\/duodealer.dev\/concepts\/about-apis\/versioning for more details.},
|
136
|
+
@logger.logged(:warn).first
|
137
|
+
)
|
138
|
+
end
|
139
|
+
end
|