duodealer_api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class ShippingRateTest < Test::Unit::TestCase
|
|
6
|
+
test ":get lists all shipping rates for a given checkout" do
|
|
7
|
+
fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
|
|
8
|
+
checkouts = DuodealerAPI::Checkout.all
|
|
9
|
+
|
|
10
|
+
fake "checkouts/#{checkouts.first.id}/shipping_rates",
|
|
11
|
+
method: :get, status: 200, body: load_fixture('checkouts')
|
|
12
|
+
shipping_rates = DuodealerAPI::ShippingRate.find(:all, params: { checkout_id: checkouts.first.id })
|
|
13
|
+
|
|
14
|
+
assert_equal 2, shipping_rates.first.shipping_rates.length
|
|
15
|
+
assert_equal 'canada_post-INT.TP.BOGUS-4.00', shipping_rates.first.shipping_rates.first.id
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ShippingZoneTest < Test::Unit::TestCase
|
|
4
|
+
test "get all should get all shipping zones" do
|
|
5
|
+
fake 'shipping_zones', :method => :get, :status => 200, :body => load_fixture('shipping_zones')
|
|
6
|
+
checkout = DuodealerAPI::ShippingZone.all
|
|
7
|
+
assert_equal 1, checkout.first.id
|
|
8
|
+
assert_equal "Canada", checkout.first.name
|
|
9
|
+
end
|
|
10
|
+
end
|
data/test/shop_test.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ShopTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
super
|
|
6
|
+
fake "shop"
|
|
7
|
+
@shop = DuodealerAPI::Shop.current
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_current_should_return_current_shop
|
|
11
|
+
assert @shop.is_a?(DuodealerAPI::Shop)
|
|
12
|
+
assert_equal "Apple Computers", @shop.name
|
|
13
|
+
assert_equal "apple.duodealer.com", @shop.duodealer_domain
|
|
14
|
+
assert_equal 690933842, @shop.id
|
|
15
|
+
assert_equal "2007-12-31T19:00:00-05:00", @shop.created_at
|
|
16
|
+
assert_nil @shop.tax_shipping
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_current_with_options_should_return_current_shop
|
|
20
|
+
fake "shop.json?fields%5B%5D=name&fields%5B%5D=duodealer_domain", :extension => false, :method => :get, :status => 201, :body => load_fixture('shop')
|
|
21
|
+
|
|
22
|
+
@shop = DuodealerAPI::Shop.current(params: { fields: [:name, :duodealer_domain]})
|
|
23
|
+
assert @shop.is_a?(DuodealerAPI::Shop)
|
|
24
|
+
assert_equal "Apple Computers", @shop.name
|
|
25
|
+
assert_equal "apple.duodealer.com", @shop.duodealer_domain
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_get_all_metafields_for_shop
|
|
29
|
+
fake "metafields"
|
|
30
|
+
|
|
31
|
+
metafields = @shop.metafields
|
|
32
|
+
|
|
33
|
+
assert_equal 3, metafields.length
|
|
34
|
+
assert metafields.all?{|m| m.is_a?(DuodealerAPI::Metafield)}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_get_2_metafields_for_shop
|
|
38
|
+
body = ActiveSupport::JSON.decode load_fixture 'metafields'
|
|
39
|
+
body['metafields'].slice! 2, 1
|
|
40
|
+
|
|
41
|
+
fake 'metafields.json?limit=2', body: body.to_json, extension: false
|
|
42
|
+
|
|
43
|
+
metafields = @shop.metafields limit: 2
|
|
44
|
+
|
|
45
|
+
assert_equal 2, metafields.length
|
|
46
|
+
assert metafields.all?{ |m| m.is_a? DuodealerAPI::Metafield }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_add_metafield
|
|
50
|
+
fake "metafields", :method => :post, :status => 201, :body =>load_fixture('metafield')
|
|
51
|
+
|
|
52
|
+
field = @shop.add_metafield(DuodealerAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
|
|
53
|
+
assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(WebMock.last_request.body)
|
|
54
|
+
assert !field.new_record?
|
|
55
|
+
assert_equal "contact", field.namespace
|
|
56
|
+
assert_equal "email", field.key
|
|
57
|
+
assert_equal "123@example.com", field.value
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_events
|
|
61
|
+
fake "events"
|
|
62
|
+
|
|
63
|
+
events = @shop.events
|
|
64
|
+
|
|
65
|
+
assert_equal 3, events.length
|
|
66
|
+
assert events.all?{|m| m.is_a?(DuodealerAPI::Event)}
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class SmartCollectionTest < Test::Unit::TestCase
|
|
4
|
+
test "Smart Collection creation" do
|
|
5
|
+
fake "smart_collections", :method => :post, :status => 201, :body => load_fixture('smart_collection')
|
|
6
|
+
rules = { :column => "title", :relation => "starts_with", :condition => "mac" }
|
|
7
|
+
smart_collection = DuodealerAPI::SmartCollection.create(:title => "Macbooks", :rules => rules)
|
|
8
|
+
assert_equal 1063001432, smart_collection.id
|
|
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 = DuodealerAPI::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 = DuodealerAPI::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)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class StorefrontAccessTokenTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_storefront_access_token
|
|
6
|
+
fake "storefront_access_tokens", :method => :post, :body => load_fixture('storefront_access_token')
|
|
7
|
+
storefront_access_token = DuodealerAPI::StorefrontAccessToken.create(title: 'Test')
|
|
8
|
+
assert_equal 1, storefront_access_token.id
|
|
9
|
+
assert_equal "Test", storefront_access_token.title
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_delete_storefront_access_token
|
|
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'
|
|
15
|
+
|
|
16
|
+
storefront_access_tokens = DuodealerAPI::StorefrontAccessToken.find(1)
|
|
17
|
+
assert storefront_access_tokens.destroy
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_get_storefront_access_tokens
|
|
21
|
+
fake "storefront_access_tokens", method: :get, status: 201, body: load_fixture('storefront_access_tokens')
|
|
22
|
+
|
|
23
|
+
tokens = DuodealerAPI::StorefrontAccessToken.all
|
|
24
|
+
|
|
25
|
+
assert_equal 2, tokens.size
|
|
26
|
+
assert_equal 1, tokens.first.id
|
|
27
|
+
assert_equal 2, tokens.last.id
|
|
28
|
+
assert_equal 'Test 1', tokens.first.title
|
|
29
|
+
assert_equal 'Test 2', tokens.last.title
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
class TaxServiceTest < Test::Unit::TestCase
|
|
3
|
+
test "tax service creation" do
|
|
4
|
+
fake "tax_services", :method => :post, :status => 202, :body => load_fixture('tax_service')
|
|
5
|
+
tax_service = DuodealerAPI::TaxService.create(:name => "My Tax Service", :url => "https://mytaxservice.com")
|
|
6
|
+
assert_equal '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}', WebMock.last_request.body
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class TenderTransactionTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
8
|
+
fake "tender_transactions", method: :get, body: load_fixture('tender_transactions')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "Tender Transaction" do
|
|
12
|
+
should 'return a list of transactions' do
|
|
13
|
+
tender_transactions = DuodealerAPI::TenderTransaction.all
|
|
14
|
+
assert_equal 3, tender_transactions.length
|
|
15
|
+
assert_equal [1, 2, 3], tender_transactions.map(&:id)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
require 'webmock/minitest'
|
|
4
|
+
require_relative 'lib/webmock_extensions/last_request'
|
|
5
|
+
require 'mocha/setup'
|
|
6
|
+
require 'pry'
|
|
7
|
+
|
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
10
|
+
|
|
11
|
+
WebMock.disable_net_connect!
|
|
12
|
+
require 'duodealer_api'
|
|
13
|
+
|
|
14
|
+
# setup DuodealerAPI with fake api_key and secret
|
|
15
|
+
module Test
|
|
16
|
+
module Unit
|
|
17
|
+
class TestCase < Minitest::Test
|
|
18
|
+
def self.test(string, &block)
|
|
19
|
+
define_method("test_#{string}", &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.should(string, &block)
|
|
23
|
+
self.test("should_#{string}", &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.context(string)
|
|
27
|
+
yield
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def setup
|
|
31
|
+
ActiveResource::Base.format = :json
|
|
32
|
+
DuodealerAPI.constants.each do |const|
|
|
33
|
+
begin
|
|
34
|
+
const = mod.const_get(const)
|
|
35
|
+
const.format = :json if const.respond_to?(:format=)
|
|
36
|
+
rescue NameError
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
DuodealerAPI::Base.clear_session
|
|
41
|
+
|
|
42
|
+
fake("apis",
|
|
43
|
+
url: "https://app.duodealer.com/services/apis.json",
|
|
44
|
+
method: :get,
|
|
45
|
+
status: 200,
|
|
46
|
+
api_version: :stub,
|
|
47
|
+
body: load_fixture('apis'))
|
|
48
|
+
|
|
49
|
+
DuodealerAPI::ApiVersion.fetch_known_versions
|
|
50
|
+
session = DuodealerAPI::Session.new(
|
|
51
|
+
domain: "https://this-is-my-test-shop.duodealer.com",
|
|
52
|
+
token: "token_test_helper",
|
|
53
|
+
api_version: '2019-01',
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
DuodealerAPI::Base.activate_session(session)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def teardown
|
|
60
|
+
DuodealerAPI::Base.clear_session
|
|
61
|
+
DuodealerAPI::Base.site = nil
|
|
62
|
+
DuodealerAPI::Base.password = nil
|
|
63
|
+
DuodealerAPI::Base.user = nil
|
|
64
|
+
|
|
65
|
+
DuodealerAPI::ApiVersion.clear_known_versions
|
|
66
|
+
DuodealerAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Custom Assertions
|
|
70
|
+
def assert_not(expression)
|
|
71
|
+
refute expression, "Expected <#{expression}> to be false!"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def assert_nothing_raised
|
|
75
|
+
yield
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def assert_not_includes(array, value)
|
|
79
|
+
refute array.include?(value)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def assert_includes(array, value)
|
|
83
|
+
assert array.include?(value)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def load_fixture(name, format=:json)
|
|
87
|
+
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def assert_request_body(expected)
|
|
91
|
+
assert_equal expected, WebMock.last_request.body
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def fake(endpoint, options={})
|
|
95
|
+
request_body = options.has_key?(:request_body) ? options.delete(:request_body) : nil
|
|
96
|
+
body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
|
|
97
|
+
format = options.delete(:format) || :json
|
|
98
|
+
method = options.delete(:method) || :get
|
|
99
|
+
api_version = options.delete(:api_version) || DuodealerAPI::ApiVersion.find_version('2019-01')
|
|
100
|
+
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
|
101
|
+
status = options.delete(:status) || 200
|
|
102
|
+
url = if options.has_key?(:url)
|
|
103
|
+
options[:url]
|
|
104
|
+
else
|
|
105
|
+
"https://this-is-my-test-shop.duodealer.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
stubbing = WebMock.stub_request(method, url)
|
|
109
|
+
stubbing = stubbing.with(body: request_body) if request_body
|
|
110
|
+
stubbing.to_return(
|
|
111
|
+
body: body, status: status, headers: { content_type: "text/#{format}", content_length: 1 }.merge(options)
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def ar_version_before?(version_string)
|
|
116
|
+
Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def ar_version_after?(version_string)
|
|
120
|
+
Gem::Version.new(version_string) < Gem::Version.new(ActiveResource::VERSION::STRING)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class TransactionTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
super
|
|
6
|
+
fake "orders/450789469/transactions/389404469", :method => :get, :body => load_fixture('transaction')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
context "Transaction" do
|
|
10
|
+
context "#find" do
|
|
11
|
+
should "find a specific transaction" do
|
|
12
|
+
transaction = DuodealerAPI::Transaction.find(389404469, :params => {:order_id => 450789469})
|
|
13
|
+
assert_equal "409.94", transaction.amount
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class UsageChargeTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_usage_charges
|
|
6
|
+
fake "recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge')
|
|
7
|
+
|
|
8
|
+
usage_charge = DuodealerAPI::UsageCharge.new(description: '1000 emails', price: 1.0)
|
|
9
|
+
usage_charge.prefix_options = {recurring_application_charge_id: 654381177}
|
|
10
|
+
assert usage_charge.save
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_get_usage_charges
|
|
14
|
+
fake "recurring_application_charges/654381177/usage_charges/359376002", method: :get, status: 201, body: load_fixture('usage_charge')
|
|
15
|
+
|
|
16
|
+
usage_charge = DuodealerAPI::UsageCharge.find(359376002, params: {recurring_application_charge_id: 654381177})
|
|
17
|
+
|
|
18
|
+
assert_equal "1000 emails", usage_charge.description
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
data/test/user_test.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class UserTest < Test::Unit::TestCase
|
|
4
|
+
test 'get should get a user' do
|
|
5
|
+
fake 'users/799407056', method: :get, status: 200, body: load_fixture('user')
|
|
6
|
+
|
|
7
|
+
user = DuodealerAPI::User.find(799407056)
|
|
8
|
+
assert_equal 799407056, user.id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'get should get all users' do
|
|
12
|
+
fake 'users', method: :get, status: 200, body: load_fixture('users')
|
|
13
|
+
|
|
14
|
+
users = DuodealerAPI::User.all
|
|
15
|
+
assert_equal 799407056, users.first.id
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class VariantTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_get_variants
|
|
6
|
+
fake "products/632910392/variants", :method => :get, :body => load_fixture('variants')
|
|
7
|
+
|
|
8
|
+
variants = DuodealerAPI::Variant.find(:all, :params => { :product_id => 632910392 })
|
|
9
|
+
assert_equal variants.map(&:id).sort, [39072856, 49148385, 457924702, 808950810]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_get_variant_namespaced
|
|
13
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
|
14
|
+
|
|
15
|
+
v = DuodealerAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
|
16
|
+
assert_equal 632910392, v.product_id
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_get_variant
|
|
20
|
+
fake "variants/808950810", :method => :get, :body => load_fixture('variant')
|
|
21
|
+
|
|
22
|
+
v = DuodealerAPI::Variant.find(808950810)
|
|
23
|
+
assert_equal 632910392, v.product_id
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_product_id_should_be_accessible_if_via_product_endpoint
|
|
27
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
|
28
|
+
|
|
29
|
+
v = DuodealerAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
|
30
|
+
assert_equal 632910392, v.product_id
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_product_id_should_be_accessible_if_via_variant_endpoint
|
|
34
|
+
fake "variants/808950810", :method => :get, :body => load_fixture('variant')
|
|
35
|
+
|
|
36
|
+
v = DuodealerAPI::Variant.find(808950810)
|
|
37
|
+
assert_equal 632910392, v.product_id
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_delete_variant
|
|
41
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
|
42
|
+
fake "products/632910392/variants/808950810", :method => :delete, :body => 'destroyed'
|
|
43
|
+
v = DuodealerAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
|
44
|
+
assert v.destroy
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class WebhookTest < Test::Unit::TestCase
|
|
4
|
+
test 'create should create a webhook' do
|
|
5
|
+
fake 'webhooks', :method => :post, :status => 201, :body => load_fixture('webhook')
|
|
6
|
+
webhook = DuodealerAPI::Webhook.create(address: "http://www.yoloship.it/webhook", topic: "orders/create", format: "json")
|
|
7
|
+
assert_equal "http://www.yoloship.it/webhook", webhook.address
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test 'get should retrieve a webhook' do
|
|
11
|
+
fake 'webhooks/123456', :method => :get, :status => 200, :body => load_fixture('webhook')
|
|
12
|
+
webhook = DuodealerAPI::Webhook.find(123456)
|
|
13
|
+
assert_equal "http://www.yoloship.it/webhook", webhook.address
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'find all should return all webhooks' do
|
|
17
|
+
fake 'webhooks', :method => :get, :status => 200, :body => load_fixture('webhooks')
|
|
18
|
+
webhook = DuodealerAPI::Webhook.all
|
|
19
|
+
assert_equal 123456, webhook.first.id
|
|
20
|
+
end
|
|
21
|
+
end
|