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,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/solidus_graphql_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'solidus_graphql_api'
|
7
|
+
spec.version = SolidusGraphqlApi::VERSION
|
8
|
+
spec.authors = ['Christian Rimondi', 'Alessio Rocco', 'Rainer Dema']
|
9
|
+
spec.email = 'contact@solidus.io'
|
10
|
+
|
11
|
+
spec.summary = 'Solidus GraphQL API'
|
12
|
+
spec.description = 'GraphQL comes to Solidus'
|
13
|
+
spec.homepage = 'https://github.com/solidusio-contrib/solidus_graphql_api'
|
14
|
+
spec.license = 'BSD-3-Clause'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_graphql_api'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_graphql_api/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
25
|
+
|
26
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
27
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency 'batch-loader', '>= 1.4.1', '< 1.6.0'
|
33
|
+
spec.add_dependency 'graphql', '>= 1.10', '< 1.12'
|
34
|
+
spec.add_dependency 'solidus_core', ['>= 2.5', '< 3']
|
35
|
+
spec.add_dependency 'solidus_support', '~> 0.5'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'graphql-schema_comparator', '~> 1.0.0'
|
38
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
39
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
40
|
+
spec.add_development_dependency 'solidus_dev_support', '~> 1.5.0'
|
41
|
+
spec.add_development_dependency 'timecop', '~> 0.9.1'
|
42
|
+
spec.add_development_dependency 'with_model', '~> 2.1.2'
|
43
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :add_to_cart, mutation: :add_to_cart do
|
6
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
7
|
+
let(:guest_token) { nil }
|
8
|
+
let(:mutation_context) {
|
9
|
+
Hash[
|
10
|
+
current_ability: current_ability,
|
11
|
+
current_order: current_order,
|
12
|
+
order_token: guest_token
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:variant) { create(:variant) }
|
17
|
+
let(:variant_id) {
|
18
|
+
SolidusGraphqlApi::Schema.id_from_object(variant, nil, nil)
|
19
|
+
}
|
20
|
+
let(:quantity) { 10 }
|
21
|
+
let(:mutation_variables) {
|
22
|
+
Hash[
|
23
|
+
input: {
|
24
|
+
variantId: variant_id,
|
25
|
+
quantity: quantity
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
|
30
|
+
shared_examples "responds with an unauthorized error" do
|
31
|
+
it { expect(subject[:data][:addToCart]).to be_nil }
|
32
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when current order isn't present" do
|
36
|
+
let(:current_order) { nil }
|
37
|
+
|
38
|
+
include_examples "responds with an unauthorized error"
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when current order is completed" do
|
42
|
+
let(:current_order) { create(:completed_order_with_totals) }
|
43
|
+
|
44
|
+
include_examples "responds with an unauthorized error"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when current order isn't completed" do
|
48
|
+
let(:current_order) { create(:order, state: 'payment') }
|
49
|
+
let(:user_errors) { subject[:data][:addToCart][:errors] }
|
50
|
+
|
51
|
+
context 'and the current ability is unauthorized' do
|
52
|
+
include_examples "responds with an unauthorized error"
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'and the current ability is authorized' do
|
56
|
+
let(:guest_token) { current_order.guest_token }
|
57
|
+
let(:response_order) { subject[:data][:addToCart][:order] }
|
58
|
+
|
59
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
60
|
+
it { expect(response_order[:state]).to eq('address') }
|
61
|
+
it { expect(response_order[:lineItems][:nodes].first[:quantity]).to eq(10) }
|
62
|
+
it { expect(response_order[:lineItems][:nodes].first[:variant][:id]).to eq(variant.id) }
|
63
|
+
it { expect(user_errors).to be_empty }
|
64
|
+
it { is_expected.to_not have_key(:errors) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :add_addresses_to_checkout, mutation: :add_addresses_to_checkout do
|
6
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
7
|
+
let(:guest_token) { nil }
|
8
|
+
let(:mutation_context) {
|
9
|
+
Hash[
|
10
|
+
current_ability: current_ability,
|
11
|
+
current_order: current_order,
|
12
|
+
order_token: guest_token
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:country_id) { SolidusGraphqlApi::Schema.id_from_object(create(:country), nil, nil) }
|
17
|
+
let(:address) {
|
18
|
+
address = build_stubbed(:address).slice(:address1, :city, :phone, :zipcode)
|
19
|
+
address[:countryId] = country_id
|
20
|
+
address.transform_keys! { |key| key.camelize(:lower) }
|
21
|
+
}
|
22
|
+
let(:billing_address_firstname) { 'John' }
|
23
|
+
let(:shipping_address_firstname) { 'Jane' }
|
24
|
+
let(:mutation_variables) {
|
25
|
+
Hash[
|
26
|
+
input: {
|
27
|
+
billingAddress: address.merge(firstname: billing_address_firstname),
|
28
|
+
shippingAddress: address.merge(firstname: shipping_address_firstname)
|
29
|
+
}
|
30
|
+
].tap do |variables|
|
31
|
+
variables[:input][:shipToBillingAddress] = ship_to_billing_address if defined?(ship_to_billing_address)
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
shared_examples "responds with an unauthorized error" do
|
36
|
+
it { expect(subject[:data][:addAddressesToCheckout]).to be_nil }
|
37
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when current order isn't present" do
|
41
|
+
let(:current_order) { nil }
|
42
|
+
|
43
|
+
include_examples "responds with an unauthorized error"
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when current order is completed" do
|
47
|
+
let(:current_order) { create(:completed_order_with_totals) }
|
48
|
+
|
49
|
+
include_examples "responds with an unauthorized error"
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when current order isn't completed" do
|
53
|
+
let(:current_order) { create(:order_with_line_items) }
|
54
|
+
let(:user_errors) { subject[:data][:addAddressesToCheckout][:errors] }
|
55
|
+
|
56
|
+
context 'and the current ability is unauthorized' do
|
57
|
+
include_examples "responds with an unauthorized error"
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'and the current ability is authorized' do
|
61
|
+
let(:guest_token) { current_order.guest_token }
|
62
|
+
let(:response_order) { subject[:data][:addAddressesToCheckout][:order] }
|
63
|
+
|
64
|
+
context 'with wrong arguments' do
|
65
|
+
let(:billing_address_firstname) { '' }
|
66
|
+
|
67
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
68
|
+
|
69
|
+
if Gem::Requirement.new('>= 2.11.0.alpha').satisfied_by?(Spree.solidus_gem_version)
|
70
|
+
it { expect(user_errors.first[:path]).to eq(["input", "order", "billAddress", "name"]) }
|
71
|
+
else
|
72
|
+
it { expect(user_errors.first[:path]).to eq(["input", "order", "billAddress", "firstname"]) }
|
73
|
+
end
|
74
|
+
|
75
|
+
it { expect(user_errors.first[:message]).to eq("can't be blank") }
|
76
|
+
it { is_expected.to_not have_key(:errors) }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with correct arguments' do
|
80
|
+
context 'when shipToBillingAddress argument' do
|
81
|
+
describe 'is true' do
|
82
|
+
let(:ship_to_billing_address) { true }
|
83
|
+
|
84
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
85
|
+
it { expect(response_order[:state]).to eq('address') }
|
86
|
+
it { expect(response_order[:billingAddress][:firstname]).to eq(billing_address_firstname) }
|
87
|
+
it { expect(response_order[:shippingAddress][:firstname]).to eq(billing_address_firstname) }
|
88
|
+
it { expect(user_errors).to be_empty }
|
89
|
+
it { is_expected.to_not have_key(:errors) }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'is false' do
|
93
|
+
let(:ship_to_billing_address) { false }
|
94
|
+
|
95
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
96
|
+
it { expect(response_order[:state]).to eq('address') }
|
97
|
+
it { expect(response_order[:billingAddress][:firstname]).to eq(billing_address_firstname) }
|
98
|
+
it { expect(response_order[:shippingAddress][:firstname]).to eq(shipping_address_firstname) }
|
99
|
+
it { expect(user_errors).to be_empty }
|
100
|
+
it { is_expected.to_not have_key(:errors) }
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'is not present' do
|
104
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
105
|
+
it { expect(response_order[:state]).to eq('address') }
|
106
|
+
it { expect(response_order[:billingAddress][:firstname]).to eq(billing_address_firstname) }
|
107
|
+
it { expect(response_order[:shippingAddress][:firstname]).to eq(shipping_address_firstname) }
|
108
|
+
it { expect(user_errors).to be_empty }
|
109
|
+
it { is_expected.to_not have_key(:errors) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :add_payment_to_checkout, mutation: :add_payment_to_checkout do
|
6
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
7
|
+
let(:guest_token) { nil }
|
8
|
+
let(:mutation_context) {
|
9
|
+
Hash[
|
10
|
+
current_ability: current_ability,
|
11
|
+
current_order: current_order,
|
12
|
+
order_token: guest_token
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:payment_method_id) { "U3ByZWU6OlBheW1lbnRNZXRob2QtMTAwMg==" }
|
17
|
+
let(:amount) { 10 }
|
18
|
+
let(:source) { Hash[] }
|
19
|
+
let(:mutation_variables) {
|
20
|
+
Hash[
|
21
|
+
input: {
|
22
|
+
paymentMethodId: payment_method_id,
|
23
|
+
amount: amount,
|
24
|
+
source: source
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
|
29
|
+
shared_examples "responds with an unauthorized error" do
|
30
|
+
it { expect(subject[:data][:selectShippingRate]).to be_nil }
|
31
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when current order isn't present" do
|
35
|
+
let(:current_order) { nil }
|
36
|
+
|
37
|
+
include_examples "responds with an unauthorized error"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when current order is completed" do
|
41
|
+
let(:current_order) { create(:order_with_line_items) }
|
42
|
+
|
43
|
+
include_examples "responds with an unauthorized error"
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when current order isn't completed" do
|
47
|
+
let(:current_order) { create(:order_with_line_items) }
|
48
|
+
let(:user_errors) { subject[:data][:addPaymentToCheckout][:errors] }
|
49
|
+
let!(:payment_method) { create(:check_payment_method) }
|
50
|
+
|
51
|
+
context 'and the current ability is unauthorized' do
|
52
|
+
include_examples "responds with an unauthorized error"
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'and the current ability is authorized' do
|
56
|
+
let(:guest_token) { current_order.guest_token }
|
57
|
+
let(:response_order) { subject[:data][:addPaymentToCheckout][:order] }
|
58
|
+
|
59
|
+
context "when the given payment method id is wrong" do
|
60
|
+
it { expect(subject[:data][:addPaymentToCheckout]).to be_nil }
|
61
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:'activerecord.exceptions.not_found') }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when there are errors during payment method selection" do
|
65
|
+
let(:payment_method_id) { SolidusGraphqlApi::Schema.id_from_object(payment_method, nil, nil) }
|
66
|
+
|
67
|
+
before do
|
68
|
+
order_updater = instance_double('Spree::OrderUpdateAttributes', apply: false)
|
69
|
+
allow(Spree::OrderUpdateAttributes).to receive(:new).and_return(order_updater)
|
70
|
+
end
|
71
|
+
|
72
|
+
it { expect(subject[:data][:addPaymentToCheckout]).to have_key(:errors) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the given payment method id is correct" do
|
76
|
+
let(:payment_method_id) { SolidusGraphqlApi::Schema.id_from_object(payment_method, nil, nil) }
|
77
|
+
|
78
|
+
it "add a payment source to the order" do
|
79
|
+
aggregate_failures do
|
80
|
+
expect(response_order[:number]).to eq(current_order.number)
|
81
|
+
expect(user_errors).to be_empty
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :advance_checkout, mutation: :advance_checkout do
|
6
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
7
|
+
let(:guest_token) { nil }
|
8
|
+
let(:mutation_context) {
|
9
|
+
Hash[
|
10
|
+
current_ability: current_ability,
|
11
|
+
current_order: current_order,
|
12
|
+
order_token: guest_token
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:mutation_variables) { Hash[input: {}] }
|
17
|
+
|
18
|
+
shared_examples "responds with an unauthorized error" do
|
19
|
+
it { expect(subject[:data][:advanceCheckout]).to be_nil }
|
20
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when current order isn't present" do
|
24
|
+
let(:current_order) { nil }
|
25
|
+
|
26
|
+
include_examples "responds with an unauthorized error"
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when current order is valid" do
|
30
|
+
let(:current_order) { create(:order_with_line_items) }
|
31
|
+
let(:user_errors) { subject[:data][:advanceCheckout][:errors] }
|
32
|
+
|
33
|
+
context 'and the current ability is unauthorized' do
|
34
|
+
include_examples "responds with an unauthorized error"
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'and the current ability is authorized' do
|
38
|
+
let(:guest_token) { current_order.guest_token }
|
39
|
+
let(:response_order) { subject[:data][:advanceCheckout][:order] }
|
40
|
+
let(:confirm_state) { 'confirm' }
|
41
|
+
let(:address_state) { 'address' }
|
42
|
+
|
43
|
+
shared_examples "responds with the current order in confirm state" do
|
44
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
45
|
+
it { expect(response_order[:email]).to eq(current_order.email) }
|
46
|
+
it { expect(response_order[:state]).to eq(confirm_state) }
|
47
|
+
it { expect(user_errors.first[:path]).to eq(["input", "order", "state"]) }
|
48
|
+
it { expect(user_errors.first[:message]).to eq("cannot transition via \"next\"") }
|
49
|
+
it { is_expected.to_not have_key(:errors) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when current order state' do
|
53
|
+
describe 'is cart' do
|
54
|
+
include_examples "responds with the current order in confirm state"
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'is address' do
|
58
|
+
before { current_order.update(state: address_state) }
|
59
|
+
|
60
|
+
include_examples "responds with the current order in confirm state"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "and the given current order state cannot advance" do
|
65
|
+
before { current_order.update(state: confirm_state) }
|
66
|
+
|
67
|
+
include_examples "responds with the current order in confirm state"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :apply_coupon_code, mutation: :apply_coupon_code do
|
6
|
+
let(:current_ability) { Spree::Ability.new(nil) }
|
7
|
+
let(:guest_token) { nil }
|
8
|
+
let(:mutation_context) {
|
9
|
+
Hash[
|
10
|
+
current_ability: current_ability,
|
11
|
+
current_order: current_order,
|
12
|
+
order_token: guest_token
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:coupon_code) { 'coupon_code' }
|
17
|
+
let(:mutation_variables) {
|
18
|
+
Hash[
|
19
|
+
input: {
|
20
|
+
couponCode: coupon_code
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
shared_examples "responds with an unauthorized error" do
|
26
|
+
it { expect(subject[:data][:selectShippingRate]).to be_nil }
|
27
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when current order isn't present" do
|
31
|
+
let(:current_order) { nil }
|
32
|
+
|
33
|
+
include_examples "responds with an unauthorized error"
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when current order is completed" do
|
37
|
+
let(:current_order) { create(:completed_order_with_totals) }
|
38
|
+
|
39
|
+
include_examples "responds with an unauthorized error"
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when current order isn't completed" do
|
43
|
+
let(:current_order) { create(:order_with_line_items) }
|
44
|
+
let(:user_errors) { subject[:data][:applyCouponCode][:errors] }
|
45
|
+
|
46
|
+
context 'and the current ability is unauthorized' do
|
47
|
+
include_examples "responds with an unauthorized error"
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'and the current ability is authorized' do
|
51
|
+
let(:guest_token) { current_order.guest_token }
|
52
|
+
let(:response_order) { subject[:data][:applyCouponCode][:order] }
|
53
|
+
|
54
|
+
context "and the given coupon code is applicable" do
|
55
|
+
let(:flat_rate_discount) { 10.0 }
|
56
|
+
|
57
|
+
before { create(:promotion, :with_line_item_adjustment, adjustment_rate: flat_rate_discount, code: coupon_code) }
|
58
|
+
|
59
|
+
it { expect(response_order[:adjustmentTotal]).to eq((-flat_rate_discount).to_s) }
|
60
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
61
|
+
it { expect(response_order[:email]).to eq(current_order.email) }
|
62
|
+
it { expect(user_errors).to be_empty }
|
63
|
+
it { is_expected.to_not have_key(:errors) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context "and the given coupon code doesn't exist" do
|
67
|
+
it { expect(response_order[:adjustmentTotal].to_d).to be_zero }
|
68
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
69
|
+
it { expect(response_order[:email]).to eq(current_order.email) }
|
70
|
+
it { expect(user_errors.first[:path]).to eq(["input", "order", "couponCode"]) }
|
71
|
+
it { expect(user_errors.first[:message]).to eq("The coupon code you entered doesn't exist. Please try again.") }
|
72
|
+
it { is_expected.to_not have_key(:errors) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|