solidus_graphql_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +93 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +0 -0
- data/CONTRIBUTING.md +57 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/LICENSE.md +26 -0
- data/README.md +245 -0
- data/Rakefile +43 -0
- data/app/controllers/spree/graphql_controller.rb +49 -0
- data/bin/console +17 -0
- data/bin/rails +9 -0
- data/bin/rails-engine +16 -0
- data/bin/rails-sandbox +18 -0
- data/bin/rake +8 -0
- data/bin/sandbox +84 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +5 -0
- data/lib/generators/solidus_graphql_api/install/install_generator.rb +8 -0
- data/lib/solidus_graphql_api.rb +11 -0
- data/lib/solidus_graphql_api/batch_loader.rb +114 -0
- data/lib/solidus_graphql_api/batch_loader/belongs_to.rb +30 -0
- data/lib/solidus_graphql_api/batch_loader/has_many.rb +24 -0
- data/lib/solidus_graphql_api/batch_loader/has_many_through.rb +42 -0
- data/lib/solidus_graphql_api/batch_loader/has_one.rb +22 -0
- data/lib/solidus_graphql_api/configuration.rb +19 -0
- data/lib/solidus_graphql_api/context.rb +76 -0
- data/lib/solidus_graphql_api/engine.rb +25 -0
- data/lib/solidus_graphql_api/factories.rb +11 -0
- data/lib/solidus_graphql_api/factories/address_factory.rb +8 -0
- data/lib/solidus_graphql_api/factories/country_factory.rb +12 -0
- data/lib/solidus_graphql_api/factories/store_factory.rb +16 -0
- data/lib/solidus_graphql_api/factories/taxonomy_factory.rb +26 -0
- data/lib/solidus_graphql_api/mutations/.keep +0 -0
- data/lib/solidus_graphql_api/mutations/base_mutation.rb +45 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_addresses_to_checkout.rb +41 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_payment_to_checkout.rb +45 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_to_cart.rb +30 -0
- data/lib/solidus_graphql_api/mutations/checkout/advance_checkout.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb +32 -0
- data/lib/solidus_graphql_api/mutations/checkout/complete_checkout.rb +31 -0
- data/lib/solidus_graphql_api/mutations/checkout/create_order.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/empty_cart.rb +29 -0
- data/lib/solidus_graphql_api/mutations/checkout/next_checkout_state.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/remove_from_cart.rb +33 -0
- data/lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb +40 -0
- data/lib/solidus_graphql_api/mutations/checkout/set_order_email.rb +29 -0
- data/lib/solidus_graphql_api/mutations/checkout/update_cart_quantity.rb +41 -0
- data/lib/solidus_graphql_api/mutations/user/mark_default_address.rb +31 -0
- data/lib/solidus_graphql_api/mutations/user/remove_from_address_book.rb +25 -0
- data/lib/solidus_graphql_api/mutations/user/save_in_address_book.rb +30 -0
- data/lib/solidus_graphql_api/queries/address/country_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/address/state_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/completed_orders_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/countries_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/country/states_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/line_item/variant_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/option_type/option_values_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/adjustments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/billing_address_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/line_items_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/payments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/shipments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/shipping_address_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/master_variant_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/option_types_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/product_properties_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/variants_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product_by_slug_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/product_property/property_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/products_query.rb +29 -0
- data/lib/solidus_graphql_api/queries/shipment/shipping_rates_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxon/children_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxon/parent_taxon_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxonomies_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxonomy/taxons_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/default_price_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/images_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/option_values_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/prices_query.rb +19 -0
- data/lib/solidus_graphql_api/schema.rb +40 -0
- data/lib/solidus_graphql_api/types/.keep +0 -0
- data/lib/solidus_graphql_api/types/address.rb +32 -0
- data/lib/solidus_graphql_api/types/base/argument.rb +10 -0
- data/lib/solidus_graphql_api/types/base/enum.rb +10 -0
- data/lib/solidus_graphql_api/types/base/field.rb +13 -0
- data/lib/solidus_graphql_api/types/base/input_object.rb +10 -0
- data/lib/solidus_graphql_api/types/base/interface.rb +11 -0
- data/lib/solidus_graphql_api/types/base/object.rb +25 -0
- data/lib/solidus_graphql_api/types/base/relay_node.rb +13 -0
- data/lib/solidus_graphql_api/types/base/scalar.rb +10 -0
- data/lib/solidus_graphql_api/types/base/union.rb +10 -0
- data/lib/solidus_graphql_api/types/country.rb +23 -0
- data/lib/solidus_graphql_api/types/credit_card.rb +18 -0
- data/lib/solidus_graphql_api/types/currency.rb +14 -0
- data/lib/solidus_graphql_api/types/image.rb +27 -0
- data/lib/solidus_graphql_api/types/input_objects/address_input.rb +24 -0
- data/lib/solidus_graphql_api/types/input_objects/products_query_input.rb +15 -0
- data/lib/solidus_graphql_api/types/interfaces/adjustment.rb +32 -0
- data/lib/solidus_graphql_api/types/interfaces/payment_source.rb +19 -0
- data/lib/solidus_graphql_api/types/json.rb +63 -0
- data/lib/solidus_graphql_api/types/line_item.rb +26 -0
- data/lib/solidus_graphql_api/types/manifest_item.rb +12 -0
- data/lib/solidus_graphql_api/types/mutation.rb +24 -0
- data/lib/solidus_graphql_api/types/option_type.rb +22 -0
- data/lib/solidus_graphql_api/types/option_value.rb +15 -0
- data/lib/solidus_graphql_api/types/order.rb +63 -0
- data/lib/solidus_graphql_api/types/payment.rb +15 -0
- data/lib/solidus_graphql_api/types/payment_method.rb +15 -0
- data/lib/solidus_graphql_api/types/price.rb +21 -0
- data/lib/solidus_graphql_api/types/product.rb +38 -0
- data/lib/solidus_graphql_api/types/product_property.rb +19 -0
- data/lib/solidus_graphql_api/types/promotion_adjustment.rb +17 -0
- data/lib/solidus_graphql_api/types/property.rb +14 -0
- data/lib/solidus_graphql_api/types/query.rb +84 -0
- data/lib/solidus_graphql_api/types/shipment.rb +23 -0
- data/lib/solidus_graphql_api/types/shipping_rate.rb +15 -0
- data/lib/solidus_graphql_api/types/state.rb +14 -0
- data/lib/solidus_graphql_api/types/store.rb +27 -0
- data/lib/solidus_graphql_api/types/tax_adjustment.rb +11 -0
- data/lib/solidus_graphql_api/types/taxon.rb +33 -0
- data/lib/solidus_graphql_api/types/taxonomy.rb +23 -0
- data/lib/solidus_graphql_api/types/user.rb +23 -0
- data/lib/solidus_graphql_api/types/user_error.rb +12 -0
- data/lib/solidus_graphql_api/types/variant.rb +39 -0
- data/lib/solidus_graphql_api/types/wallet_payment_source.rb +14 -0
- data/lib/solidus_graphql_api/version.rb +5 -0
- data/schema.graphql +2070 -0
- data/solidus_graphql_api.gemspec +43 -0
- data/spec/integration/mutations/add_to_cart_spec.rb +67 -0
- data/spec/integration/mutations/checkout/add_addresses_to_checkout_spec.rb +115 -0
- data/spec/integration/mutations/checkout/add_payment_to_checkout_spec.rb +87 -0
- data/spec/integration/mutations/checkout/advance_checkout_spec.rb +71 -0
- data/spec/integration/mutations/checkout/apply_coupon_code_spec.rb +76 -0
- data/spec/integration/mutations/checkout/complete_checkout_spec.rb +56 -0
- data/spec/integration/mutations/checkout/next_checkout_state_spec.rb +69 -0
- data/spec/integration/mutations/checkout/select_shipping_rate_spec.rb +89 -0
- data/spec/integration/mutations/create_order_spec.rb +55 -0
- data/spec/integration/mutations/empty_cart_spec.rb +58 -0
- data/spec/integration/mutations/mark_default_address_spec.rb +33 -0
- data/spec/integration/mutations/remove_from_address_book_spec.rb +48 -0
- data/spec/integration/mutations/remove_from_cart_spec.rb +65 -0
- data/spec/integration/mutations/save_in_address_book_spec.rb +90 -0
- data/spec/integration/mutations/set_order_email_spec.rb +61 -0
- data/spec/integration/mutations/update_cart_quantity_spec.rb +68 -0
- data/spec/integration/queries/completed_orders_spec.rb +158 -0
- data/spec/integration/queries/countries_spec.rb +18 -0
- data/spec/integration/queries/current_order_spec.rb +15 -0
- data/spec/integration/queries/current_store_spec.rb +15 -0
- data/spec/integration/queries/current_user_spec.rb +43 -0
- data/spec/integration/queries/product_by_slug_spec.rb +42 -0
- data/spec/integration/queries/products_spec.rb +40 -0
- data/spec/integration/queries/taxonomies_spec.rb +22 -0
- data/spec/lib/solidus_graphql_api/batch_loader/belongs_to_spec.rb +67 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_many_spec.rb +38 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_many_through_spec.rb +47 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_one_spec.rb +38 -0
- data/spec/lib/solidus_graphql_api/context_spec.rb +236 -0
- data/spec/lib/solidus_graphql_api/queries/address/country_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/address/state_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/completed_orders_query_spec.rb +12 -0
- data/spec/lib/solidus_graphql_api/queries/countries_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/country/states_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/line_item/variant_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/option_type/option_values_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/order/adjustments_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/order/billing_address_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/order/line_items_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/order/payments_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/order/shipments_query_spec.rb +18 -0
- data/spec/lib/solidus_graphql_api/queries/order/shipping_address_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/master_variant_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/option_types_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/product_properties_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/variants_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product_by_slug_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/product_property/property_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/products_query_spec.rb +49 -0
- data/spec/lib/solidus_graphql_api/queries/shipment/shipping_rates_query_spec.rb +18 -0
- data/spec/lib/solidus_graphql_api/queries/taxon/children_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/taxon/parent_taxon_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomies_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomy/taxons_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/default_price_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/variant/images_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/option_values_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/prices_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/schema_spec.rb +80 -0
- data/spec/lib/solidus_graphql_api/types/base/object_spec.rb +29 -0
- data/spec/lib/solidus_graphql_api/types/json_spec.rb +115 -0
- data/spec/lib/solidus_graphql_api/types/option_type_spec.rb +7 -0
- data/spec/lib/solidus_graphql_api/types/product_property_spec.rb +22 -0
- data/spec/lib/solidus_graphql_api/types/product_spec.rb +56 -0
- data/spec/lib/solidus_graphql_api/types/query_spec.rb +33 -0
- data/spec/lib/solidus_graphql_api/types/variant_spec.rb +58 -0
- data/spec/requests/spree/graphql_controller_spec.rb +17 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/expected_schema.graphql +2070 -0
- data/spec/support/graphql/mutations/add_addresses_to_checkout.gql +19 -0
- data/spec/support/graphql/mutations/add_payment_to_checkout.gql +13 -0
- data/spec/support/graphql/mutations/add_to_cart.gql +21 -0
- data/spec/support/graphql/mutations/advance_checkout.gql +13 -0
- data/spec/support/graphql/mutations/apply_coupon_code.gql +13 -0
- data/spec/support/graphql/mutations/complete_checkout.gql +13 -0
- data/spec/support/graphql/mutations/create_order.gql +11 -0
- data/spec/support/graphql/mutations/empty_cart.gql +17 -0
- data/spec/support/graphql/mutations/mark_default_address.gql +9 -0
- data/spec/support/graphql/mutations/next_checkout_state.gql +13 -0
- data/spec/support/graphql/mutations/remove_from_address_book.gql +14 -0
- data/spec/support/graphql/mutations/remove_from_cart.gql +17 -0
- data/spec/support/graphql/mutations/save_in_address_book.gql +57 -0
- data/spec/support/graphql/mutations/select_shipping_rate.gql +23 -0
- data/spec/support/graphql/mutations/set_order_email.gql +13 -0
- data/spec/support/graphql/mutations/update_cart_quantity.gql +18 -0
- data/spec/support/graphql/queries/completed_orders.gql +29 -0
- data/spec/support/graphql/queries/completed_orders/adjustments.gql +24 -0
- data/spec/support/graphql/queries/completed_orders/available_payment_methods.gql +15 -0
- data/spec/support/graphql/queries/completed_orders/billing_address.gql +40 -0
- data/spec/support/graphql/queries/completed_orders/line_items.gql +23 -0
- data/spec/support/graphql/queries/completed_orders/payments.gql +23 -0
- data/spec/support/graphql/queries/completed_orders/shipping_address.gql +40 -0
- data/spec/support/graphql/queries/countries.gql +24 -0
- data/spec/support/graphql/queries/current_order.gql +32 -0
- data/spec/support/graphql/queries/current_store.gql +24 -0
- data/spec/support/graphql/queries/current_user.gql +197 -0
- data/spec/support/graphql/queries/product_by_slug.gql +106 -0
- data/spec/support/graphql/queries/products.gql +7 -0
- data/spec/support/graphql/queries/taxonomies.gql +81 -0
- data/spec/support/graphql/responses/completed_orders.json.erb +58 -0
- data/spec/support/graphql/responses/completed_orders/adjustments.json.erb +34 -0
- data/spec/support/graphql/responses/completed_orders/available_payment_methods.json.erb +29 -0
- data/spec/support/graphql/responses/completed_orders/billing_address.json.erb +78 -0
- data/spec/support/graphql/responses/completed_orders/line_items.json.erb +43 -0
- data/spec/support/graphql/responses/completed_orders/payments.json.erb +27 -0
- data/spec/support/graphql/responses/completed_orders/shipping_address.json.erb +78 -0
- data/spec/support/graphql/responses/countries.json.erb +51 -0
- data/spec/support/graphql/responses/current_order.json.erb +36 -0
- data/spec/support/graphql/responses/current_store.json.erb +34 -0
- data/spec/support/graphql/responses/current_user.json.erb +232 -0
- data/spec/support/graphql/responses/product_by_slug.json.erb +123 -0
- data/spec/support/graphql/responses/taxonomies.json.erb +145 -0
- data/spec/support/helpers/graphql.rb +43 -0
- data/spec/support/matchers/graphql.rb +35 -0
- data/spec/support/shared_contexts/graphql_query_subject.rb +21 -0
- metadata +572 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :product_by_slug, query: :product_by_slug, freeze_date: true do
|
6
|
+
let!(:product) { create(:product, id: 1, name: 'Product', slug: 'slug', sku: 'SKU') }
|
7
|
+
|
8
|
+
let!(:option_type) { create(:option_type, id: 1, name: 'foo-size') }
|
9
|
+
let!(:option_value) { create(:option_value, id: 1, name: 'Size', option_type: option_type) }
|
10
|
+
let!(:product_option_type) { create(:product_option_type, id: 1, product: product, option_type: option_type) }
|
11
|
+
|
12
|
+
let!(:product_property) { create(:product_property, id: 1, product: product) }
|
13
|
+
|
14
|
+
let!(:first_variant) { create(:base_variant, product: product) }
|
15
|
+
let!(:second_variant) { create(:base_variant, product: product) }
|
16
|
+
|
17
|
+
before do
|
18
|
+
product.master.update!(option_values: [option_value])
|
19
|
+
end
|
20
|
+
|
21
|
+
field :productBySlug do
|
22
|
+
context "when the slug doesn't exist" do
|
23
|
+
let(:query_variables) { { slug: 'non-existent-slug' } }
|
24
|
+
|
25
|
+
it { expect(subject.dig(:data, :productBySlug)).to be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when the slug exists' do
|
29
|
+
let(:query_variables) { { slug: 'slug' } }
|
30
|
+
|
31
|
+
let(:args) do
|
32
|
+
{
|
33
|
+
product: product,
|
34
|
+
first_variant: first_variant,
|
35
|
+
second_variant: second_variant
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
it { is_expected.to match_response(:product_by_slug).with_args(args) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :products, query: :products, freeze_date: true do
|
6
|
+
connection_field :products do
|
7
|
+
subject { query_response.dig(:data, :products, :nodes) }
|
8
|
+
|
9
|
+
let(:current_user) { create :user }
|
10
|
+
let(:current_pricing_options) { Spree::Config.pricing_options_class.new }
|
11
|
+
let(:query_context) do
|
12
|
+
{ current_user: current_user,
|
13
|
+
current_pricing_options: current_pricing_options }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when products do not exist' do
|
17
|
+
it { is_expected.to eq [] }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when products exist' do
|
21
|
+
let!(:solidus_t_shirt) { create(:product, name: 'Solidus T-Shirt', id: 1, price: 19.99) }
|
22
|
+
let!(:ruby_mug) { create(:product, name: 'Ruby Mug', id: 2, price: 9.99) }
|
23
|
+
let!(:solidus_mug) { create(:product, name: 'Solidus Mug ', id: 3, price: 9.99) }
|
24
|
+
let!(:solidus_tote) { create(:product, name: 'Solidus Tote', id: 4, price: 15.99) }
|
25
|
+
|
26
|
+
context 'when no query is passed' do
|
27
|
+
it { is_expected.to match_array([{ id: solidus_t_shirt.id }, { id: ruby_mug.id }, { id: solidus_mug.id }, { id: solidus_tote.id }]) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when a query is passed' do
|
31
|
+
let(:taxon) { create(:taxon, products: [solidus_tote]) }
|
32
|
+
let(:search) { { price_range_any: ["Under $10.00", "$15.00 - $18.00"] } }
|
33
|
+
let(:taxon_id) { SolidusGraphqlApi::Schema.id_from_object(taxon, nil, nil) }
|
34
|
+
let(:query_variables) { { query: { taxon: taxon_id, keywords: "Solidus", search: search } } }
|
35
|
+
|
36
|
+
it { is_expected.to match_array([{ id: solidus_tote.id }]) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :taxonomies do
|
6
|
+
connection_field :taxonomies, query: :taxonomies, freeze_date: true do
|
7
|
+
context 'when taxonomies does not exists' do
|
8
|
+
it { expect(subject.dig(:data, :taxonomies, :nodes)).to eq [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when taxonomies exists' do
|
12
|
+
let!(:brand_taxonomy) { create(:taxonomy, :with_taxon_meta, id: 1, root_taxon_id: 1) }
|
13
|
+
let!(:category_taxonomy) { create(:taxonomy, id: 2, name: 'Category', root_taxon_id: 2) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
create(:taxon, id: 3, name: 'Solidus', parent: brand_taxonomy.root, taxonomy: brand_taxonomy)
|
17
|
+
end
|
18
|
+
|
19
|
+
it { is_expected.to match_response(:taxonomies) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::BatchLoader::BelongsTo do
|
6
|
+
subject(:loader) do
|
7
|
+
described_class.new(
|
8
|
+
object,
|
9
|
+
object.class.reflect_on_association(association),
|
10
|
+
options
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:options) { {} }
|
15
|
+
|
16
|
+
context 'with a regular association' do
|
17
|
+
with_model :Article, scope: :all do
|
18
|
+
model do
|
19
|
+
has_many :comments
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
with_model :Comment, scope: :all do
|
24
|
+
table do |t|
|
25
|
+
t.belongs_to :article
|
26
|
+
end
|
27
|
+
|
28
|
+
model do
|
29
|
+
belongs_to :article
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
let!(:object) { Comment.create!(article: Article.create!) }
|
34
|
+
let(:association) { :article }
|
35
|
+
|
36
|
+
it 'loads the association properly' do
|
37
|
+
expect(loader.load.sync).to eq(object.article)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with a polymorphic association' do
|
42
|
+
with_model :Image, scope: :all do
|
43
|
+
table do |t|
|
44
|
+
t.integer :imageable_id
|
45
|
+
t.string :imageable_type
|
46
|
+
end
|
47
|
+
|
48
|
+
model do
|
49
|
+
belongs_to :imageable, polymorphic: true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
with_model :Article, scope: :all do
|
54
|
+
model do
|
55
|
+
has_many :images, as: :imageable
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
let!(:object) { Image.create!(imageable: Article.create!) }
|
60
|
+
let(:association) { :imageable }
|
61
|
+
let(:options) { { klass: Article } }
|
62
|
+
|
63
|
+
it 'loads the association properly' do
|
64
|
+
expect(loader.load.sync).to eq(object.imageable)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::BatchLoader::HasMany do
|
6
|
+
subject(:loader) do
|
7
|
+
described_class.new(
|
8
|
+
article,
|
9
|
+
Article.reflect_on_association(:comments)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
with_model :Article, scope: :all do
|
14
|
+
model do
|
15
|
+
has_many :comments
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
with_model :Comment, scope: :all do
|
20
|
+
table do |t|
|
21
|
+
t.belongs_to :article
|
22
|
+
end
|
23
|
+
|
24
|
+
model do
|
25
|
+
belongs_to :article
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let!(:article) { Article.create! }
|
30
|
+
|
31
|
+
before do
|
32
|
+
article.comments.create!
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'loads the association properly' do
|
36
|
+
expect(loader.load.sync).to eq(article.comments)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::BatchLoader::HasManyThrough do
|
6
|
+
subject(:loader) do
|
7
|
+
described_class.new(
|
8
|
+
article,
|
9
|
+
Article.reflect_on_association(:comment_authors)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
with_model :Article, scope: :all do
|
14
|
+
model do
|
15
|
+
has_many :comments
|
16
|
+
has_many :comment_authors, through: :comments, source: :author
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
with_model :Comment, scope: :all do
|
21
|
+
table do |t|
|
22
|
+
t.belongs_to :article
|
23
|
+
t.belongs_to :author
|
24
|
+
end
|
25
|
+
|
26
|
+
model do
|
27
|
+
belongs_to :article
|
28
|
+
belongs_to :author
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
with_model :Author, scope: :all do
|
33
|
+
model do
|
34
|
+
has_many :comments
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
let!(:article) { Article.create! }
|
39
|
+
|
40
|
+
before do
|
41
|
+
article.comments.create!(author: Author.create!)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'loads the association properly' do
|
45
|
+
expect(loader.load.sync).to eq(article.comment_authors)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::BatchLoader::HasOne do
|
6
|
+
subject(:loader) do
|
7
|
+
described_class.new(
|
8
|
+
article,
|
9
|
+
Article.reflect_on_association(:image)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
with_model :Article, scope: :all do
|
14
|
+
model do
|
15
|
+
has_one :image
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
with_model :Image, scope: :all do
|
20
|
+
table do |t|
|
21
|
+
t.belongs_to :article
|
22
|
+
end
|
23
|
+
|
24
|
+
model do
|
25
|
+
belongs_to :article
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let!(:article) { Article.create! }
|
30
|
+
|
31
|
+
before do
|
32
|
+
article.create_image!
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'loads the association properly' do
|
36
|
+
expect(loader.load.sync).to eq(article.image)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Context do
|
6
|
+
let(:schema_context) { described_class.new(request: request) }
|
7
|
+
|
8
|
+
let(:headers) do
|
9
|
+
headers_hash = {}
|
10
|
+
headers_hash['Authorization'] = "Bearer #{authorization_token}" if defined?(authorization_token) && authorization_token
|
11
|
+
headers_hash['X-Spree-Order-Token'] = order_token if defined?(order_token) && order_token
|
12
|
+
headers_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:request) { ActionDispatch::TestRequest.create.tap { |request| request.headers.merge!(headers) } }
|
16
|
+
|
17
|
+
describe '#to_h' do
|
18
|
+
subject { schema_context.to_h }
|
19
|
+
|
20
|
+
let(:current_user) { Spree::User.new }
|
21
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
22
|
+
let!(:default_store) { create(:store, default: true) }
|
23
|
+
let(:current_order) { build(:order) }
|
24
|
+
let(:current_pricing_options) { Spree::Config.pricing_options_class.new }
|
25
|
+
let(:order_token) { "order_token" }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(schema_context).to receive(:current_user).and_return(current_user)
|
29
|
+
allow(schema_context).to receive(:current_ability).and_return(current_ability)
|
30
|
+
allow(schema_context).to receive(:current_order).and_return(current_order)
|
31
|
+
allow(schema_context).to receive(:current_pricing_options).and_return(current_pricing_options)
|
32
|
+
end
|
33
|
+
|
34
|
+
it { is_expected.to be_an(Hash) }
|
35
|
+
|
36
|
+
it { is_expected.to have_key(:current_user) }
|
37
|
+
it { expect(subject[:current_user]).to eq current_user }
|
38
|
+
|
39
|
+
it { is_expected.to have_key(:current_ability) }
|
40
|
+
it { expect(subject[:current_ability]).to eq current_ability }
|
41
|
+
|
42
|
+
it { is_expected.to have_key(:current_store) }
|
43
|
+
it { expect(subject[:current_store]).to eq default_store }
|
44
|
+
|
45
|
+
it { is_expected.to have_key(:current_order) }
|
46
|
+
it { expect(subject[:current_order]).to eq current_order }
|
47
|
+
|
48
|
+
it { is_expected.to have_key(:current_pricing_options) }
|
49
|
+
it { expect(subject[:current_pricing_options]).to eq current_pricing_options }
|
50
|
+
|
51
|
+
it { is_expected.to have_key(:order_token) }
|
52
|
+
it { expect(subject[:order_token]).to eq order_token }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#current_user' do
|
56
|
+
subject { schema_context.current_user }
|
57
|
+
|
58
|
+
context 'when headers do not contains the authorization token' do
|
59
|
+
it { is_expected.to be_nil }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when headers contains the authorization token' do
|
63
|
+
let!(:user) { create(:user).tap(&:generate_spree_api_key!) }
|
64
|
+
|
65
|
+
context 'and the authorization token is invalid' do
|
66
|
+
let(:authorization_token) { 'wrongauthorizationtoken' }
|
67
|
+
|
68
|
+
it { is_expected.to be_nil }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'and the authorization token is valid' do
|
72
|
+
let(:authorization_token) { user.spree_api_key }
|
73
|
+
|
74
|
+
it { is_expected.to eq user }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#current_ability' do
|
80
|
+
subject { schema_context.current_ability }
|
81
|
+
|
82
|
+
after { subject }
|
83
|
+
|
84
|
+
context 'when headers do not contains the authorization token' do
|
85
|
+
it { is_expected.to be_a Spree::Ability }
|
86
|
+
it { expect(Spree::Ability).to receive(:new).with(nil) }
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when headers contains the authorization token' do
|
90
|
+
let!(:user) { create(:user).tap(&:generate_spree_api_key!) }
|
91
|
+
|
92
|
+
context 'and the authorization token is invalid' do
|
93
|
+
let(:authorization_token) { 'wrongauthorizationtoken' }
|
94
|
+
|
95
|
+
it { is_expected.to be_a Spree::Ability }
|
96
|
+
it { expect(Spree::Ability).to receive(:new).with(nil) }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'and the authorization token is valid' do
|
100
|
+
let(:authorization_token) { user.spree_api_key }
|
101
|
+
|
102
|
+
it { is_expected.to be_a Spree::Ability }
|
103
|
+
it { expect(Spree::Ability).to receive(:new).with(user) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#current_store' do
|
109
|
+
subject { schema_context.current_store }
|
110
|
+
|
111
|
+
let!(:default_store) { create(:store, default: true) }
|
112
|
+
|
113
|
+
it { is_expected.to eq default_store }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#current_pricing_options' do
|
117
|
+
subject { schema_context.current_pricing_options }
|
118
|
+
|
119
|
+
let(:default_currency) { 'EUR' }
|
120
|
+
let(:country_iso) { 'IT-it' }
|
121
|
+
let!(:default_store) do
|
122
|
+
create(:store, default: true, default_currency: default_currency, cart_tax_country_iso: country_iso)
|
123
|
+
end
|
124
|
+
|
125
|
+
it { is_expected.to be_a Spree::Config.pricing_options_class }
|
126
|
+
|
127
|
+
it do
|
128
|
+
expect(Spree::Config.pricing_options_class).to receive(:new).with(
|
129
|
+
currency: default_currency,
|
130
|
+
country_iso: country_iso
|
131
|
+
)
|
132
|
+
subject
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#order_token' do
|
137
|
+
subject { schema_context.order_token }
|
138
|
+
|
139
|
+
let(:order_token) { "order_token" }
|
140
|
+
|
141
|
+
it { is_expected.to eq order_token }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#current_order' do
|
145
|
+
subject { schema_context.current_order }
|
146
|
+
|
147
|
+
let(:current_store) { create :store, default: true }
|
148
|
+
|
149
|
+
before do
|
150
|
+
allow(schema_context).to receive(:current_user).and_return(current_user)
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when there is a current user' do
|
154
|
+
let(:current_user) { create :user }
|
155
|
+
|
156
|
+
before do
|
157
|
+
allow(schema_context).to receive(:current_user).and_return(current_user)
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when the current user has one incompleted order in the current store' do
|
161
|
+
let!(:order) { create :order, user: current_user, store: current_store }
|
162
|
+
|
163
|
+
it { is_expected.to eq order }
|
164
|
+
|
165
|
+
context 'when is provided an order token for an incompleted order in the current store' do
|
166
|
+
let(:other_order) { create :order, store: current_store }
|
167
|
+
let(:order_token) { other_order.guest_token }
|
168
|
+
|
169
|
+
it { is_expected.to eq order }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when the current user has many incompleted orders in the current store' do
|
174
|
+
let!(:first_created_order) { create :order, user: current_user, store: current_store, created_at: Time.zone.yesterday }
|
175
|
+
let!(:last_created_order) { create :order, user: current_user, store: current_store, created_at: Time.zone.today }
|
176
|
+
|
177
|
+
it { is_expected.to eq last_created_order }
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when the current user has one completed order in the current store' do
|
181
|
+
let!(:order) { create :completed_order_with_totals, user: current_user, store: current_store }
|
182
|
+
|
183
|
+
it { is_expected.to be_nil }
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'when the current user has one incompleted order in another store' do
|
187
|
+
let(:other_store) { create :store, default: false }
|
188
|
+
let(:order) { create :order, user: current_user, store: other_store }
|
189
|
+
|
190
|
+
before do
|
191
|
+
current_store
|
192
|
+
order
|
193
|
+
end
|
194
|
+
|
195
|
+
it { is_expected.to be_nil }
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'when the current user does not have any orders' do
|
199
|
+
it { is_expected.to be_nil }
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when there is no current user' do
|
204
|
+
let(:current_user) {}
|
205
|
+
let(:order_token) {}
|
206
|
+
|
207
|
+
context 'when is provided an order token for an incompleted order in the current store' do
|
208
|
+
let(:order) { create :order, store: current_store }
|
209
|
+
let(:order_token) { order.guest_token }
|
210
|
+
|
211
|
+
it { is_expected.to eq order }
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'when is provided an order token for a completed order in the current store' do
|
215
|
+
let(:order) { create :completed_order_with_totals, store: current_store }
|
216
|
+
let(:order_token) { order.guest_token }
|
217
|
+
|
218
|
+
it { is_expected.to be_nil }
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'when is provided an order token for an incompleted order in another store' do
|
222
|
+
let(:other_store) { create :store, default: false }
|
223
|
+
let(:order) { create :order, user: current_user, store: other_store }
|
224
|
+
let(:order_token) { order.guest_token }
|
225
|
+
|
226
|
+
before { current_store }
|
227
|
+
|
228
|
+
it { is_expected.to be_nil }
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'when is provided no order token' do
|
232
|
+
it { is_expected.to be_nil }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|