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,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :save_in_address_book, mutation: :save_in_address_book do
|
6
|
+
let(:default) { false }
|
7
|
+
let(:country_states_required) { false }
|
8
|
+
let(:address) { create(:address, firstname: "Jane", country: create(:country, states_required: country_states_required)) }
|
9
|
+
let(:address_attributes) {
|
10
|
+
{
|
11
|
+
firstname: address.firstname,
|
12
|
+
address1: address.address1,
|
13
|
+
city: address.city,
|
14
|
+
countryId: SolidusGraphqlApi::Schema.id_from_object(address.country, nil, nil),
|
15
|
+
phone: address.phone,
|
16
|
+
zipcode: address.zipcode,
|
17
|
+
}
|
18
|
+
}
|
19
|
+
let(:mutation_context) { Hash[current_ability: Spree::Ability.new(current_user), current_user: current_user] }
|
20
|
+
let(:mutation_variables) {
|
21
|
+
{
|
22
|
+
input: {
|
23
|
+
address: address_attributes,
|
24
|
+
default: default
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
context "when current user isn't present" do
|
30
|
+
let(:current_user) { nil }
|
31
|
+
|
32
|
+
it { expect(subject[:data][:saveInAddressBook]).to be_nil }
|
33
|
+
it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when current user is present" do
|
37
|
+
let(:current_user) { create(:user) }
|
38
|
+
let(:default_address) { subject[:data][:saveInAddressBook][:user][:defaultAddress] }
|
39
|
+
let(:user_addresses) { subject[:data][:saveInAddressBook][:user][:addresses][:nodes] }
|
40
|
+
let(:user_errors) { subject[:data][:saveInAddressBook][:errors] }
|
41
|
+
|
42
|
+
context "when user doesn't have addresses" do
|
43
|
+
context "and given attributes are correct" do
|
44
|
+
it { expect(default_address[:firstname]).to eq(address[:firstname]) }
|
45
|
+
it { expect(user_addresses.count).to eq 1 }
|
46
|
+
it { expect(user_addresses.first[:firstname]).to eq(address[:firstname]) }
|
47
|
+
it { expect(user_errors).to be_empty }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "and given attributes are incorrect" do
|
51
|
+
let(:country_states_required) { true }
|
52
|
+
|
53
|
+
it { expect(default_address).to be_nil }
|
54
|
+
it { expect(user_addresses.count).to eq 0 }
|
55
|
+
it { expect(user_errors.first[:path]).to eq ["input", "address", "state"] }
|
56
|
+
it { expect(user_errors.first[:message]).to eq "can't be blank" }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when user have addresses" do
|
61
|
+
let(:current_user) { create(:user_with_addresses) }
|
62
|
+
|
63
|
+
context "and given attributes are correct" do
|
64
|
+
it { expect(default_address).to_not be_nil }
|
65
|
+
it { expect(user_addresses.count).to eq 3 }
|
66
|
+
it { expect(user_addresses.map{ |address| address[:firstname] }).to include(address[:firstname]) }
|
67
|
+
it { expect(user_errors).to be_empty }
|
68
|
+
|
69
|
+
context 'when default false' do
|
70
|
+
it { expect(default_address[:firstname]).to_not eq(address[:firstname]) }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when default true' do
|
74
|
+
let(:default) { true }
|
75
|
+
|
76
|
+
it { expect(default_address[:firstname]).to eq(address[:firstname]) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "and given attributes are incorrect" do
|
81
|
+
let(:country_states_required) { true }
|
82
|
+
|
83
|
+
it { expect(default_address).to_not be_nil }
|
84
|
+
it { expect(user_addresses.count).to eq 2 }
|
85
|
+
it { expect(user_errors.first[:path]).to eq ["input", "address", "state"] }
|
86
|
+
it { expect(user_errors.first[:message]).to eq "can't be blank" }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :set_order_email, mutation: :set_order_email 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(:email) { 'test@example.com' }
|
17
|
+
let(:mutation_variables) {
|
18
|
+
Hash[
|
19
|
+
input: {
|
20
|
+
email: email
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
shared_examples "responds with an unauthorized error" do
|
26
|
+
it { expect(subject[:data][:setOrderEmail]).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, state: 'cart') }
|
44
|
+
let(:user_errors) { subject[:data][:setOrderEmail][: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][:setOrderEmail][:order] }
|
53
|
+
|
54
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
55
|
+
it { expect(response_order[:state]).to eq('cart') }
|
56
|
+
it { expect(response_order[:email]).to eq(email) }
|
57
|
+
it { expect(user_errors).to be_empty }
|
58
|
+
it { is_expected.to_not have_key(:errors) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_mutation :update_cart_quantity, mutation: :update_cart_quantity 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(:line_item) { current_order.line_items.first }
|
17
|
+
let(:line_item_id) {
|
18
|
+
SolidusGraphqlApi::Schema.id_from_object(line_item, nil, nil)
|
19
|
+
}
|
20
|
+
let(:quantity) { 10 }
|
21
|
+
let(:mutation_variables) {
|
22
|
+
Hash[
|
23
|
+
input: {
|
24
|
+
lineItemId: line_item_id,
|
25
|
+
quantity: quantity
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
|
30
|
+
shared_examples "responds with an unauthorized error" do
|
31
|
+
it { expect(subject[:data][:updateCartQuantity]).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
|
+
let(:line_item_id) { 'not_existent' }
|
38
|
+
|
39
|
+
include_examples "responds with an unauthorized error"
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when current order is completed" do
|
43
|
+
let(:current_order) { create(:completed_order_with_totals) }
|
44
|
+
|
45
|
+
include_examples "responds with an unauthorized error"
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when current order isn't completed" do
|
49
|
+
let(:current_order) { create(:order_with_line_items, state: 'delivery') }
|
50
|
+
let(:user_errors) { subject[:data][:updateCartQuantity][:errors] }
|
51
|
+
|
52
|
+
context 'and the current ability is unauthorized' do
|
53
|
+
include_examples "responds with an unauthorized error"
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'and the current ability is authorized' do
|
57
|
+
let(:guest_token) { current_order.guest_token }
|
58
|
+
let(:response_order) { subject[:data][:updateCartQuantity][:order] }
|
59
|
+
|
60
|
+
it { expect(response_order[:number]).to eq(current_order.number) }
|
61
|
+
it { expect(response_order[:state]).to eq('address') }
|
62
|
+
it { expect(response_order[:lineItems][:nodes].first[:id]).to eq(line_item.id) }
|
63
|
+
it { expect(response_order[:lineItems][:nodes].first[:quantity]).to eq(10) }
|
64
|
+
it { expect(user_errors).to be_empty }
|
65
|
+
it { is_expected.to_not have_key(:errors) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :completed_orders do
|
6
|
+
connection_field :completed_orders, query: :completed_orders, freeze_date: true do
|
7
|
+
let(:current_user) { create :user, email: 'email1@example.com' }
|
8
|
+
let(:query_context) { { current_user: current_user } }
|
9
|
+
|
10
|
+
context 'when there are not any completed orders' do
|
11
|
+
it { expect(subject.dig(:data, :completedOrders, :nodes)).to eq [] }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when there are some completed orders' do
|
15
|
+
let(:order_1) do
|
16
|
+
create(
|
17
|
+
:completed_order_with_pending_payment,
|
18
|
+
id: 1,
|
19
|
+
user: current_user,
|
20
|
+
guest_token: 'fake guest token 1',
|
21
|
+
number: 'fake order number 1'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
let(:order_2) do
|
25
|
+
create(
|
26
|
+
:completed_order_with_pending_payment,
|
27
|
+
id: 2,
|
28
|
+
user: current_user,
|
29
|
+
guest_token: 'fake guest token 2',
|
30
|
+
number: 'fake order number 2'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
let!(:completed_orders) { [order_1, order_2] }
|
34
|
+
|
35
|
+
it { is_expected.to match_response('completed_orders') }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'billing and shipping address fields' do
|
39
|
+
let(:ship_address_1_country) { create :country, id: 1 }
|
40
|
+
let(:ship_address_1_state) { create :state, id: 1, country: ship_address_1_country }
|
41
|
+
let(:bill_address_1_country) { create :country, id: 2 }
|
42
|
+
let(:bill_address_1_state) { create :state, id: 2, country: bill_address_1_country }
|
43
|
+
let(:ship_address_2_country) { create :country, id: 3 }
|
44
|
+
let(:ship_address_2_state) { create :state, id: 3, country: ship_address_2_country }
|
45
|
+
let(:bill_address_2_country) { create :country, id: 4 }
|
46
|
+
let(:bill_address_2_state) { create :state, id: 4, country: bill_address_2_country }
|
47
|
+
let(:ship_address_1) do
|
48
|
+
create(
|
49
|
+
:address,
|
50
|
+
id: 1,
|
51
|
+
zipcode: '10001',
|
52
|
+
address1: 'A Different Road',
|
53
|
+
country: ship_address_1_country,
|
54
|
+
state: ship_address_1_state
|
55
|
+
)
|
56
|
+
end
|
57
|
+
let(:bill_address_1) do
|
58
|
+
create(
|
59
|
+
:address,
|
60
|
+
id: 2,
|
61
|
+
zipcode: '10002',
|
62
|
+
address1: 'PO Box 1337',
|
63
|
+
country: bill_address_1_country,
|
64
|
+
state: bill_address_1_state
|
65
|
+
)
|
66
|
+
end
|
67
|
+
let(:ship_address_2) do
|
68
|
+
create(
|
69
|
+
:address,
|
70
|
+
id: 3,
|
71
|
+
zipcode: '10003',
|
72
|
+
address1: 'A Different Road',
|
73
|
+
country: ship_address_2_country,
|
74
|
+
state: ship_address_2_state
|
75
|
+
)
|
76
|
+
end
|
77
|
+
let(:bill_address_2) do
|
78
|
+
create(
|
79
|
+
:address,
|
80
|
+
id: 4,
|
81
|
+
zipcode: '10004',
|
82
|
+
address1: 'PO Box 1337',
|
83
|
+
country: bill_address_2_country,
|
84
|
+
state: bill_address_2_state
|
85
|
+
)
|
86
|
+
end
|
87
|
+
let(:order_1) do
|
88
|
+
create(
|
89
|
+
:completed_order_with_pending_payment,
|
90
|
+
id: 1,
|
91
|
+
user: current_user,
|
92
|
+
ship_address: ship_address_1,
|
93
|
+
bill_address: bill_address_1
|
94
|
+
)
|
95
|
+
end
|
96
|
+
let(:order_2) do
|
97
|
+
create(
|
98
|
+
:completed_order_with_pending_payment,
|
99
|
+
id: 2,
|
100
|
+
user: current_user,
|
101
|
+
ship_address: ship_address_2,
|
102
|
+
bill_address: bill_address_2
|
103
|
+
)
|
104
|
+
end
|
105
|
+
let!(:completed_orders) { [order_1, order_2] }
|
106
|
+
|
107
|
+
connection_field :shipping_address, query: 'completed_orders/shipping_address' do
|
108
|
+
it { is_expected.to match_response('completed_orders/shipping_address') }
|
109
|
+
end
|
110
|
+
|
111
|
+
connection_field :billing_address, query: 'completed_orders/billing_address' do
|
112
|
+
it { is_expected.to match_response('completed_orders/billing_address') }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
connection_field :line_items, query: 'completed_orders/line_items' do
|
117
|
+
let!(:order) do
|
118
|
+
create :completed_order_with_pending_payment, id: 1, user: current_user, line_items_count: 2
|
119
|
+
end
|
120
|
+
|
121
|
+
it { is_expected.to match_response('completed_orders/line_items').with_args(line_items: order.line_items) }
|
122
|
+
end
|
123
|
+
|
124
|
+
connection_field :available_payment_methods, query: 'completed_orders/available_payment_methods' do
|
125
|
+
let!(:order) do
|
126
|
+
create :completed_order_with_pending_payment, id: 1, user: current_user
|
127
|
+
end
|
128
|
+
|
129
|
+
it { is_expected.to match_response('completed_orders/available_payment_methods').with_args(available_payment_methods: order.available_payment_methods) }
|
130
|
+
end
|
131
|
+
|
132
|
+
connection_field :payments, query: 'completed_orders/payments' do
|
133
|
+
let!(:order) { create :completed_order_with_pending_payment, id: 1, user: current_user }
|
134
|
+
|
135
|
+
it { is_expected.to match_response('completed_orders/payments').with_args(payments: order.payments) }
|
136
|
+
end
|
137
|
+
|
138
|
+
connection_field :adjustments, query: 'completed_orders/adjustments' do
|
139
|
+
let(:promotion) { create :promotion_with_order_adjustment, code: 'solidus' }
|
140
|
+
let(:promotion_code) { promotion.codes.first }
|
141
|
+
|
142
|
+
let(:tax_rate) { create :tax_rate }
|
143
|
+
let!(:tax_adjustment) { create :adjustment, source: tax_rate, order: order }
|
144
|
+
|
145
|
+
let!(:order) { create :completed_order_with_pending_payment, id: 1, user: current_user }
|
146
|
+
|
147
|
+
before do
|
148
|
+
promotion.actions.first.perform(
|
149
|
+
order: order,
|
150
|
+
promotion: promotion,
|
151
|
+
promotion_code: promotion_code
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
it { is_expected.to match_response('completed_orders/adjustments').with_args(adjustments: order.adjustments) }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :countries, query: :countries, freeze_date: true do
|
6
|
+
connection_field :countries do
|
7
|
+
context 'when countries does not exists' do
|
8
|
+
it { expect(subject.dig(:data, :countries, :nodes)).to eq [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when countries exists' do
|
12
|
+
let!(:us_country) { create(:country, :with_states, id: 1) }
|
13
|
+
let!(:it_country) { create(:country, id: 2, iso: 'IT') }
|
14
|
+
|
15
|
+
it { is_expected.to match_response(:countries) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :currentOrder, query: :current_order, freeze_date: true do
|
6
|
+
let!(:order) { create :order_with_line_items, id: 1, number: 'fake number' }
|
7
|
+
|
8
|
+
let(:query_context) { { current_order: order } }
|
9
|
+
let(:shipment_number) { order.shipments.first.number }
|
10
|
+
let(:variant_sku) { order.line_items.first.variant.sku }
|
11
|
+
|
12
|
+
field :currentOrder do
|
13
|
+
it { is_expected.to match_response(:current_order).with_args(shipment_number: shipment_number, variant_sku: variant_sku) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :currentStore, query: :current_store, freeze_date: true do
|
6
|
+
let!(:store) { create(:store, :with_defaults) }
|
7
|
+
|
8
|
+
before { Spree::Config.available_currencies = ::Money::Currency.first(2) }
|
9
|
+
|
10
|
+
let(:query_context) { Hash[current_store: store] }
|
11
|
+
|
12
|
+
field :currentStore do
|
13
|
+
it { is_expected.to match_response(:current_store) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe_query :current_user, query: :current_user, freeze_date: true do
|
6
|
+
let(:user) {
|
7
|
+
create(:user,
|
8
|
+
id: 1,
|
9
|
+
email: 'email@example.com',
|
10
|
+
spree_api_key: '123',
|
11
|
+
ship_address: ship_address,
|
12
|
+
bill_address: bill_address)
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:ship_address) { create(:ship_address, id: 1, zipcode: 10_001) }
|
16
|
+
let(:bill_address) { create(:bill_address, id: 2, zipcode: 10_002) }
|
17
|
+
let(:credit_card) {
|
18
|
+
create(:credit_card,
|
19
|
+
user: user,
|
20
|
+
cc_type: 'visa',
|
21
|
+
address: ship_address,
|
22
|
+
payment_method: create(:payment_method, id: 1))
|
23
|
+
}
|
24
|
+
|
25
|
+
before do
|
26
|
+
wallet_payment_source = user.wallet.add credit_card
|
27
|
+
wallet_payment_source.update!(default: true)
|
28
|
+
end
|
29
|
+
|
30
|
+
field :currentUser do
|
31
|
+
context 'when context does not have current user' do
|
32
|
+
it { expect(subject.dig(:data, :currentUser)).to be_nil }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when context have current user' do
|
36
|
+
let!(:query_context) { Hash[current_user: user] }
|
37
|
+
|
38
|
+
let(:args) { { wallet: user.wallet } }
|
39
|
+
|
40
|
+
it { is_expected.to match_response(:current_user).with_args(args) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|