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,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Address::CountryQuery do
|
6
|
+
subject { described_class.new(address: address).call.sync }
|
7
|
+
|
8
|
+
let(:address) { create(:address) }
|
9
|
+
|
10
|
+
let(:country) { address.country }
|
11
|
+
|
12
|
+
it { is_expected.to eq(country) }
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Address::StateQuery do
|
6
|
+
subject { described_class.new(address: address).call.sync }
|
7
|
+
|
8
|
+
let(:address) { create(:address) }
|
9
|
+
|
10
|
+
let(:state) { address.state }
|
11
|
+
|
12
|
+
it { is_expected.to eq(state) }
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::CompletedOrdersQuery do
|
6
|
+
subject { described_class.new(user: user).call }
|
7
|
+
|
8
|
+
let(:user) { create :user }
|
9
|
+
let!(:orders) { create_list(:completed_order_with_totals, 2, user: user) }
|
10
|
+
|
11
|
+
it { is_expected.to eq orders }
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::CountriesQuery do
|
6
|
+
subject { described_class.new.call }
|
7
|
+
|
8
|
+
let!(:countries) { create_list(:country, 2) }
|
9
|
+
|
10
|
+
it { is_expected.to match_array(countries) }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Country::StatesQuery do
|
6
|
+
let(:country) { create(:country) }
|
7
|
+
|
8
|
+
let!(:states) { create_list(:state, 2, country: country) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(country: country).call.sync).to match_array(states) }
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::LineItem::VariantQuery do
|
6
|
+
let(:line_item) { create(:line_item) }
|
7
|
+
|
8
|
+
it { expect(described_class.new(line_item: line_item).call.sync).to eq(line_item.variant) }
|
9
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::OptionType::OptionValuesQuery do
|
6
|
+
let(:option_type) { create(:option_type) }
|
7
|
+
|
8
|
+
let!(:option_values) { create_list(:option_value, 2, option_type: option_type) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(option_type: option_type).call.sync).to match_array(option_values) }
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::AdjustmentsQuery do
|
6
|
+
let(:promotion) { create :promotion_with_order_adjustment }
|
7
|
+
let(:order) { create :completed_order_with_promotion, promotion: promotion }
|
8
|
+
|
9
|
+
it { expect(described_class.new(order: order).call.sync).to eq order.adjustments }
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::BillingAddressQuery do
|
6
|
+
let(:order) { create :order, bill_address: billing_address }
|
7
|
+
|
8
|
+
let(:billing_address) { create :bill_address }
|
9
|
+
|
10
|
+
it { expect(described_class.new(order: order).call.sync).to eq billing_address }
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::LineItemsQuery do
|
6
|
+
let(:order) { create :order_with_line_items, line_items_count: 2 }
|
7
|
+
|
8
|
+
it { expect(described_class.new(order: order).call.sync).to eq order.line_items }
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::PaymentsQuery do
|
6
|
+
let(:order) { create :completed_order_with_pending_payment }
|
7
|
+
|
8
|
+
it { expect(described_class.new(order: order).call.sync).to eq order.payments }
|
9
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::ShipmentsQuery do
|
6
|
+
let(:order) { create :order }
|
7
|
+
let(:shipment) { create(:shipment) }
|
8
|
+
|
9
|
+
context 'when order has shipments' do
|
10
|
+
before { order.shipments << shipment }
|
11
|
+
|
12
|
+
it { expect(described_class.new(order: order).call.sync).to eq [shipment] }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when order does not have shipments' do
|
16
|
+
it { expect(described_class.new(order: order).call.sync).to be_empty }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Order::ShippingAddressQuery do
|
6
|
+
let(:order) { create :order, ship_address: shipping_address }
|
7
|
+
|
8
|
+
let(:shipping_address) { create :ship_address }
|
9
|
+
|
10
|
+
it { expect(described_class.new(order: order).call.sync).to eq shipping_address }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Product::MasterVariantQuery do
|
6
|
+
let(:product) { create(:product) }
|
7
|
+
|
8
|
+
let!(:variants) { create_list(:variant, 2, product: product) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(product: product).call.sync).to eq(product.master) }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Product::OptionTypesQuery do
|
6
|
+
let(:product) { create(:product) }
|
7
|
+
|
8
|
+
let!(:option_types) { create_list(:option_type, 2, products: [product]) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(product: product).call.sync).to match_array(option_types) }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Product::ProductPropertiesQuery do
|
6
|
+
let(:product) { create(:product) }
|
7
|
+
|
8
|
+
let!(:product_properties) { create_list(:product_property, 2, product: product) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(product: product).call.sync).to match_array(product_properties) }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Product::VariantsQuery do
|
6
|
+
let(:product) { create(:product) }
|
7
|
+
|
8
|
+
let!(:variants) { create_list(:variant, 2, product: product) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(product: product).call.sync).to match_array(variants) }
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::ProductBySlugQuery do
|
6
|
+
subject { described_class.new.call(slug: slug) }
|
7
|
+
|
8
|
+
let!(:products) { create_list(:product, 2) }
|
9
|
+
let(:product) { products.last }
|
10
|
+
let(:slug) { product.slug }
|
11
|
+
|
12
|
+
it { is_expected.to eq(product) }
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::ProductProperty::PropertyQuery do
|
6
|
+
let(:property) { create(:property) }
|
7
|
+
|
8
|
+
let!(:product_property) { create(:product_property, property: property) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(product_property: product_property).call.sync).to eq(property) }
|
11
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::ProductsQuery do
|
6
|
+
subject do
|
7
|
+
described_class.new(user: user, pricing_options: pricing_options).call(query: query)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:user) { create :user }
|
11
|
+
let(:pricing_options) { Spree::Config.pricing_options_class.new }
|
12
|
+
let(:query) { {} }
|
13
|
+
|
14
|
+
context 'when products do not exist' do
|
15
|
+
it { is_expected.to be_empty }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when products exist' do
|
19
|
+
let(:solidus_t_shirt) { create(:product, name: 'Solidus T-Shirt', id: 1, price: 19.99) }
|
20
|
+
let(:ruby_mug) { create(:product, name: 'Ruby Mug', id: 2, price: 9.99) }
|
21
|
+
let(:solidus_mug) { create(:product, name: 'Solidus Mug ', id: 3, price: 9.99) }
|
22
|
+
let(:solidus_tote) { create(:product, name: 'Solidus Tote', id: 4, price: 15.99) }
|
23
|
+
let!(:all_products) { [solidus_t_shirt, ruby_mug, solidus_mug, solidus_tote] }
|
24
|
+
|
25
|
+
context 'when no query is passed' do
|
26
|
+
it { is_expected.to match_array(all_products) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when a query is passed' do
|
30
|
+
let(:taxonomy) { create(:taxonomy, name: 'Categories') }
|
31
|
+
let(:t_shirts_taxon) { create(:taxon, name: 'T-Shirts', taxonomy: taxonomy, products: [solidus_t_shirt]) }
|
32
|
+
let(:mugs_taxon) { create(:taxon, name: 'Mugs', taxonomy: taxonomy, products: [ruby_mug, solidus_mug]) }
|
33
|
+
let(:totes_taxon) { create(:taxon, name: 'Totes', taxonomy: taxonomy, products: [solidus_tote]) }
|
34
|
+
|
35
|
+
let(:search) { { price_range_any: ["Under $10.00", "$15.00 - $18.00"] } }
|
36
|
+
let(:query) { { taxon: totes_taxon, keywords: "Solidus", search: search } }
|
37
|
+
|
38
|
+
it { is_expected.to match_array([solidus_tote]) }
|
39
|
+
|
40
|
+
context 'that contains page and/or per_page params' do
|
41
|
+
let(:query) { { keywords: "Solidus", page: 2, per_page: 2 } }
|
42
|
+
|
43
|
+
it 'ignores the page and per_page params' do
|
44
|
+
expect(subject).to match_array([solidus_t_shirt, solidus_mug, solidus_tote])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Shipment::ShippingRatesQuery do
|
6
|
+
let(:shipment) { create(:shipment, shipping_rates: []) }
|
7
|
+
let(:shipping_rates) { shipment.shipping_rates }
|
8
|
+
|
9
|
+
context 'when shipment has shipping_rates' do
|
10
|
+
it { expect(described_class.new(shipment: shipment).call.sync).to eq shipping_rates }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when shipment does not have shipping_rates' do
|
14
|
+
before { shipment.shipping_rates.destroy_all }
|
15
|
+
|
16
|
+
it { expect(described_class.new(shipment: shipment).call.sync).to be_empty }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Taxon::ChildrenQuery do
|
6
|
+
let(:taxon) { create(:taxon) }
|
7
|
+
|
8
|
+
let!(:children) { create_list(:taxon, 2, parent: taxon) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(taxon: taxon).call.sync).to match_array(children) }
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Taxon::ParentTaxonQuery do
|
6
|
+
let(:parent_taxon) { create(:taxon) }
|
7
|
+
let(:taxon) { create(:taxon, parent: parent_taxon) }
|
8
|
+
|
9
|
+
it { expect(described_class.new(taxon: taxon).call.sync).to eq(parent_taxon) }
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::TaxonomiesQuery do
|
6
|
+
subject { described_class.new.call }
|
7
|
+
|
8
|
+
let!(:taxonomies) { create_list(:taxonomy, 2) }
|
9
|
+
|
10
|
+
it { is_expected.to match_array(taxonomies) }
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Taxonomy::RootTaxonQuery do
|
6
|
+
let(:taxonomy) { create(:taxonomy) }
|
7
|
+
let(:root_taxon) { taxonomy.root }
|
8
|
+
|
9
|
+
it { expect(described_class.new(taxonomy: taxonomy).call.sync).to eq(root_taxon) }
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Taxonomy::TaxonsQuery do
|
6
|
+
let(:taxons) { build_list(:taxon, 2) }
|
7
|
+
|
8
|
+
let(:taxonomy) { create(:taxonomy, taxons: taxons) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(taxonomy: taxonomy).call.sync).to match_array(taxons) }
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Variant::DefaultPriceQuery do
|
6
|
+
let(:variant) { create(:variant) }
|
7
|
+
|
8
|
+
it { expect(described_class.new(variant: variant).call.sync).to eq(variant.default_price) }
|
9
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Variant::ImagesQuery do
|
6
|
+
let(:variant) { create(:variant) }
|
7
|
+
|
8
|
+
let!(:images) { create_list(:image, 2, viewable: variant ) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(variant: variant).call.sync).to match_array(images) }
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Variant::OptionValuesQuery do
|
6
|
+
let(:variant) { create(:base_variant) }
|
7
|
+
|
8
|
+
let!(:option_values) { create_list(:option_value, 2, variants: [variant]) }
|
9
|
+
|
10
|
+
it { expect(described_class.new(variant: variant).call.sync).to match_array(option_values) }
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Queries::Variant::PricesQuery do
|
6
|
+
let(:variant) { create(:variant) }
|
7
|
+
|
8
|
+
let(:prices) { create_list(:price, 2, variant: variant) }
|
9
|
+
|
10
|
+
let!(:variant_prices) { [variant.default_price] + prices }
|
11
|
+
|
12
|
+
it { expect(described_class.new(variant: variant).call.sync).to match_array(variant_prices) }
|
13
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusGraphqlApi::Schema do
|
6
|
+
it 'current schema is identical to expected schema' do
|
7
|
+
expected_schema = File.read("#{SolidusGraphqlApi::Engine.root}/spec/support/expected_schema.graphql")
|
8
|
+
current_schema = SolidusGraphqlApi::Schema.to_definition
|
9
|
+
|
10
|
+
result = GraphQL::SchemaComparator.compare(current_schema, expected_schema)
|
11
|
+
|
12
|
+
expect(result.identical?).to be_truthy, result.changes.map(&:message).join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.id_from_object' do
|
16
|
+
subject { described_class.id_from_object(object, nil, nil) }
|
17
|
+
|
18
|
+
context 'when object responds to :id' do
|
19
|
+
let(:object) { build(:country, id: 1) }
|
20
|
+
|
21
|
+
after { subject }
|
22
|
+
|
23
|
+
it { expect(GraphQL::Schema::UniqueWithinType).to receive(:encode).with('Spree::Country', 1) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when object does not respond to :id' do
|
27
|
+
let(:object) { nil }
|
28
|
+
|
29
|
+
it { expect { subject }.to raise_error(NoMethodError) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.object_from_id' do
|
34
|
+
subject { described_class.object_from_id('ID', nil) }
|
35
|
+
|
36
|
+
let!(:object) { create(:country) }
|
37
|
+
let(:klass) { 'Spree::Country' }
|
38
|
+
let(:id) { object.id }
|
39
|
+
|
40
|
+
before do
|
41
|
+
allow(GraphQL::Schema::UniqueWithinType).to receive(:decode).and_return([klass, id])
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the class and the id exist' do
|
45
|
+
it { is_expected.to eq object }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when the class does not exist' do
|
49
|
+
let(:klass) { 'NotExistingClass' }
|
50
|
+
|
51
|
+
it { expect { subject }.to raise_error(NameError) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when the id does not exist' do
|
55
|
+
let(:id) { Spree::Country.maximum(:id).next }
|
56
|
+
|
57
|
+
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '.resolve_type' do
|
62
|
+
subject { described_class.resolve_type(nil, object, nil) }
|
63
|
+
|
64
|
+
context 'when graphql type exists' do
|
65
|
+
let(:object) { build(:country) }
|
66
|
+
|
67
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
68
|
+
class SolidusGraphqlApi::Types::Country < SolidusGraphqlApi::Types::Base::RelayNode; end
|
69
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
70
|
+
|
71
|
+
it { is_expected.to eq SolidusGraphqlApi::Types::Country }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when graphql type does not exist' do
|
75
|
+
let(:object) { double(:not_existing) }
|
76
|
+
|
77
|
+
it { expect { subject }.to raise_error(NameError) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|