solidus_graphql_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +93 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +20 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +62 -0
  8. data/CHANGELOG.md +0 -0
  9. data/CONTRIBUTING.md +57 -0
  10. data/Gemfile +33 -0
  11. data/LICENSE +26 -0
  12. data/LICENSE.md +26 -0
  13. data/README.md +245 -0
  14. data/Rakefile +43 -0
  15. data/app/controllers/spree/graphql_controller.rb +49 -0
  16. data/bin/console +17 -0
  17. data/bin/rails +9 -0
  18. data/bin/rails-engine +16 -0
  19. data/bin/rails-sandbox +18 -0
  20. data/bin/rake +8 -0
  21. data/bin/sandbox +84 -0
  22. data/bin/setup +8 -0
  23. data/config/locales/en.yml +6 -0
  24. data/config/routes.rb +5 -0
  25. data/lib/generators/solidus_graphql_api/install/install_generator.rb +8 -0
  26. data/lib/solidus_graphql_api.rb +11 -0
  27. data/lib/solidus_graphql_api/batch_loader.rb +114 -0
  28. data/lib/solidus_graphql_api/batch_loader/belongs_to.rb +30 -0
  29. data/lib/solidus_graphql_api/batch_loader/has_many.rb +24 -0
  30. data/lib/solidus_graphql_api/batch_loader/has_many_through.rb +42 -0
  31. data/lib/solidus_graphql_api/batch_loader/has_one.rb +22 -0
  32. data/lib/solidus_graphql_api/configuration.rb +19 -0
  33. data/lib/solidus_graphql_api/context.rb +76 -0
  34. data/lib/solidus_graphql_api/engine.rb +25 -0
  35. data/lib/solidus_graphql_api/factories.rb +11 -0
  36. data/lib/solidus_graphql_api/factories/address_factory.rb +8 -0
  37. data/lib/solidus_graphql_api/factories/country_factory.rb +12 -0
  38. data/lib/solidus_graphql_api/factories/store_factory.rb +16 -0
  39. data/lib/solidus_graphql_api/factories/taxonomy_factory.rb +26 -0
  40. data/lib/solidus_graphql_api/mutations/.keep +0 -0
  41. data/lib/solidus_graphql_api/mutations/base_mutation.rb +45 -0
  42. data/lib/solidus_graphql_api/mutations/checkout/add_addresses_to_checkout.rb +41 -0
  43. data/lib/solidus_graphql_api/mutations/checkout/add_payment_to_checkout.rb +45 -0
  44. data/lib/solidus_graphql_api/mutations/checkout/add_to_cart.rb +30 -0
  45. data/lib/solidus_graphql_api/mutations/checkout/advance_checkout.rb +27 -0
  46. data/lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb +32 -0
  47. data/lib/solidus_graphql_api/mutations/checkout/complete_checkout.rb +31 -0
  48. data/lib/solidus_graphql_api/mutations/checkout/create_order.rb +27 -0
  49. data/lib/solidus_graphql_api/mutations/checkout/empty_cart.rb +29 -0
  50. data/lib/solidus_graphql_api/mutations/checkout/next_checkout_state.rb +27 -0
  51. data/lib/solidus_graphql_api/mutations/checkout/remove_from_cart.rb +33 -0
  52. data/lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb +40 -0
  53. data/lib/solidus_graphql_api/mutations/checkout/set_order_email.rb +29 -0
  54. data/lib/solidus_graphql_api/mutations/checkout/update_cart_quantity.rb +41 -0
  55. data/lib/solidus_graphql_api/mutations/user/mark_default_address.rb +31 -0
  56. data/lib/solidus_graphql_api/mutations/user/remove_from_address_book.rb +25 -0
  57. data/lib/solidus_graphql_api/mutations/user/save_in_address_book.rb +30 -0
  58. data/lib/solidus_graphql_api/queries/address/country_query.rb +19 -0
  59. data/lib/solidus_graphql_api/queries/address/state_query.rb +19 -0
  60. data/lib/solidus_graphql_api/queries/completed_orders_query.rb +19 -0
  61. data/lib/solidus_graphql_api/queries/countries_query.rb +11 -0
  62. data/lib/solidus_graphql_api/queries/country/states_query.rb +19 -0
  63. data/lib/solidus_graphql_api/queries/line_item/variant_query.rb +19 -0
  64. data/lib/solidus_graphql_api/queries/option_type/option_values_query.rb +19 -0
  65. data/lib/solidus_graphql_api/queries/order/adjustments_query.rb +19 -0
  66. data/lib/solidus_graphql_api/queries/order/billing_address_query.rb +19 -0
  67. data/lib/solidus_graphql_api/queries/order/line_items_query.rb +19 -0
  68. data/lib/solidus_graphql_api/queries/order/payments_query.rb +19 -0
  69. data/lib/solidus_graphql_api/queries/order/shipments_query.rb +19 -0
  70. data/lib/solidus_graphql_api/queries/order/shipping_address_query.rb +19 -0
  71. data/lib/solidus_graphql_api/queries/product/master_variant_query.rb +19 -0
  72. data/lib/solidus_graphql_api/queries/product/option_types_query.rb +19 -0
  73. data/lib/solidus_graphql_api/queries/product/product_properties_query.rb +19 -0
  74. data/lib/solidus_graphql_api/queries/product/variants_query.rb +19 -0
  75. data/lib/solidus_graphql_api/queries/product_by_slug_query.rb +11 -0
  76. data/lib/solidus_graphql_api/queries/product_property/property_query.rb +19 -0
  77. data/lib/solidus_graphql_api/queries/products_query.rb +29 -0
  78. data/lib/solidus_graphql_api/queries/shipment/shipping_rates_query.rb +19 -0
  79. data/lib/solidus_graphql_api/queries/taxon/children_query.rb +19 -0
  80. data/lib/solidus_graphql_api/queries/taxon/parent_taxon_query.rb +19 -0
  81. data/lib/solidus_graphql_api/queries/taxonomies_query.rb +11 -0
  82. data/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query.rb +19 -0
  83. data/lib/solidus_graphql_api/queries/taxonomy/taxons_query.rb +19 -0
  84. data/lib/solidus_graphql_api/queries/variant/default_price_query.rb +19 -0
  85. data/lib/solidus_graphql_api/queries/variant/images_query.rb +19 -0
  86. data/lib/solidus_graphql_api/queries/variant/option_values_query.rb +19 -0
  87. data/lib/solidus_graphql_api/queries/variant/prices_query.rb +19 -0
  88. data/lib/solidus_graphql_api/schema.rb +40 -0
  89. data/lib/solidus_graphql_api/types/.keep +0 -0
  90. data/lib/solidus_graphql_api/types/address.rb +32 -0
  91. data/lib/solidus_graphql_api/types/base/argument.rb +10 -0
  92. data/lib/solidus_graphql_api/types/base/enum.rb +10 -0
  93. data/lib/solidus_graphql_api/types/base/field.rb +13 -0
  94. data/lib/solidus_graphql_api/types/base/input_object.rb +10 -0
  95. data/lib/solidus_graphql_api/types/base/interface.rb +11 -0
  96. data/lib/solidus_graphql_api/types/base/object.rb +25 -0
  97. data/lib/solidus_graphql_api/types/base/relay_node.rb +13 -0
  98. data/lib/solidus_graphql_api/types/base/scalar.rb +10 -0
  99. data/lib/solidus_graphql_api/types/base/union.rb +10 -0
  100. data/lib/solidus_graphql_api/types/country.rb +23 -0
  101. data/lib/solidus_graphql_api/types/credit_card.rb +18 -0
  102. data/lib/solidus_graphql_api/types/currency.rb +14 -0
  103. data/lib/solidus_graphql_api/types/image.rb +27 -0
  104. data/lib/solidus_graphql_api/types/input_objects/address_input.rb +24 -0
  105. data/lib/solidus_graphql_api/types/input_objects/products_query_input.rb +15 -0
  106. data/lib/solidus_graphql_api/types/interfaces/adjustment.rb +32 -0
  107. data/lib/solidus_graphql_api/types/interfaces/payment_source.rb +19 -0
  108. data/lib/solidus_graphql_api/types/json.rb +63 -0
  109. data/lib/solidus_graphql_api/types/line_item.rb +26 -0
  110. data/lib/solidus_graphql_api/types/manifest_item.rb +12 -0
  111. data/lib/solidus_graphql_api/types/mutation.rb +24 -0
  112. data/lib/solidus_graphql_api/types/option_type.rb +22 -0
  113. data/lib/solidus_graphql_api/types/option_value.rb +15 -0
  114. data/lib/solidus_graphql_api/types/order.rb +63 -0
  115. data/lib/solidus_graphql_api/types/payment.rb +15 -0
  116. data/lib/solidus_graphql_api/types/payment_method.rb +15 -0
  117. data/lib/solidus_graphql_api/types/price.rb +21 -0
  118. data/lib/solidus_graphql_api/types/product.rb +38 -0
  119. data/lib/solidus_graphql_api/types/product_property.rb +19 -0
  120. data/lib/solidus_graphql_api/types/promotion_adjustment.rb +17 -0
  121. data/lib/solidus_graphql_api/types/property.rb +14 -0
  122. data/lib/solidus_graphql_api/types/query.rb +84 -0
  123. data/lib/solidus_graphql_api/types/shipment.rb +23 -0
  124. data/lib/solidus_graphql_api/types/shipping_rate.rb +15 -0
  125. data/lib/solidus_graphql_api/types/state.rb +14 -0
  126. data/lib/solidus_graphql_api/types/store.rb +27 -0
  127. data/lib/solidus_graphql_api/types/tax_adjustment.rb +11 -0
  128. data/lib/solidus_graphql_api/types/taxon.rb +33 -0
  129. data/lib/solidus_graphql_api/types/taxonomy.rb +23 -0
  130. data/lib/solidus_graphql_api/types/user.rb +23 -0
  131. data/lib/solidus_graphql_api/types/user_error.rb +12 -0
  132. data/lib/solidus_graphql_api/types/variant.rb +39 -0
  133. data/lib/solidus_graphql_api/types/wallet_payment_source.rb +14 -0
  134. data/lib/solidus_graphql_api/version.rb +5 -0
  135. data/schema.graphql +2070 -0
  136. data/solidus_graphql_api.gemspec +43 -0
  137. data/spec/integration/mutations/add_to_cart_spec.rb +67 -0
  138. data/spec/integration/mutations/checkout/add_addresses_to_checkout_spec.rb +115 -0
  139. data/spec/integration/mutations/checkout/add_payment_to_checkout_spec.rb +87 -0
  140. data/spec/integration/mutations/checkout/advance_checkout_spec.rb +71 -0
  141. data/spec/integration/mutations/checkout/apply_coupon_code_spec.rb +76 -0
  142. data/spec/integration/mutations/checkout/complete_checkout_spec.rb +56 -0
  143. data/spec/integration/mutations/checkout/next_checkout_state_spec.rb +69 -0
  144. data/spec/integration/mutations/checkout/select_shipping_rate_spec.rb +89 -0
  145. data/spec/integration/mutations/create_order_spec.rb +55 -0
  146. data/spec/integration/mutations/empty_cart_spec.rb +58 -0
  147. data/spec/integration/mutations/mark_default_address_spec.rb +33 -0
  148. data/spec/integration/mutations/remove_from_address_book_spec.rb +48 -0
  149. data/spec/integration/mutations/remove_from_cart_spec.rb +65 -0
  150. data/spec/integration/mutations/save_in_address_book_spec.rb +90 -0
  151. data/spec/integration/mutations/set_order_email_spec.rb +61 -0
  152. data/spec/integration/mutations/update_cart_quantity_spec.rb +68 -0
  153. data/spec/integration/queries/completed_orders_spec.rb +158 -0
  154. data/spec/integration/queries/countries_spec.rb +18 -0
  155. data/spec/integration/queries/current_order_spec.rb +15 -0
  156. data/spec/integration/queries/current_store_spec.rb +15 -0
  157. data/spec/integration/queries/current_user_spec.rb +43 -0
  158. data/spec/integration/queries/product_by_slug_spec.rb +42 -0
  159. data/spec/integration/queries/products_spec.rb +40 -0
  160. data/spec/integration/queries/taxonomies_spec.rb +22 -0
  161. data/spec/lib/solidus_graphql_api/batch_loader/belongs_to_spec.rb +67 -0
  162. data/spec/lib/solidus_graphql_api/batch_loader/has_many_spec.rb +38 -0
  163. data/spec/lib/solidus_graphql_api/batch_loader/has_many_through_spec.rb +47 -0
  164. data/spec/lib/solidus_graphql_api/batch_loader/has_one_spec.rb +38 -0
  165. data/spec/lib/solidus_graphql_api/context_spec.rb +236 -0
  166. data/spec/lib/solidus_graphql_api/queries/address/country_query_spec.rb +13 -0
  167. data/spec/lib/solidus_graphql_api/queries/address/state_query_spec.rb +13 -0
  168. data/spec/lib/solidus_graphql_api/queries/completed_orders_query_spec.rb +12 -0
  169. data/spec/lib/solidus_graphql_api/queries/countries_query_spec.rb +11 -0
  170. data/spec/lib/solidus_graphql_api/queries/country/states_query_spec.rb +11 -0
  171. data/spec/lib/solidus_graphql_api/queries/line_item/variant_query_spec.rb +9 -0
  172. data/spec/lib/solidus_graphql_api/queries/option_type/option_values_query_spec.rb +11 -0
  173. data/spec/lib/solidus_graphql_api/queries/order/adjustments_query_spec.rb +10 -0
  174. data/spec/lib/solidus_graphql_api/queries/order/billing_address_query_spec.rb +11 -0
  175. data/spec/lib/solidus_graphql_api/queries/order/line_items_query_spec.rb +9 -0
  176. data/spec/lib/solidus_graphql_api/queries/order/payments_query_spec.rb +9 -0
  177. data/spec/lib/solidus_graphql_api/queries/order/shipments_query_spec.rb +18 -0
  178. data/spec/lib/solidus_graphql_api/queries/order/shipping_address_query_spec.rb +11 -0
  179. data/spec/lib/solidus_graphql_api/queries/product/master_variant_query_spec.rb +11 -0
  180. data/spec/lib/solidus_graphql_api/queries/product/option_types_query_spec.rb +11 -0
  181. data/spec/lib/solidus_graphql_api/queries/product/product_properties_query_spec.rb +11 -0
  182. data/spec/lib/solidus_graphql_api/queries/product/variants_query_spec.rb +11 -0
  183. data/spec/lib/solidus_graphql_api/queries/product_by_slug_query_spec.rb +13 -0
  184. data/spec/lib/solidus_graphql_api/queries/product_property/property_query_spec.rb +11 -0
  185. data/spec/lib/solidus_graphql_api/queries/products_query_spec.rb +49 -0
  186. data/spec/lib/solidus_graphql_api/queries/shipment/shipping_rates_query_spec.rb +18 -0
  187. data/spec/lib/solidus_graphql_api/queries/taxon/children_query_spec.rb +11 -0
  188. data/spec/lib/solidus_graphql_api/queries/taxon/parent_taxon_query_spec.rb +10 -0
  189. data/spec/lib/solidus_graphql_api/queries/taxonomies_query_spec.rb +11 -0
  190. data/spec/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query_spec.rb +10 -0
  191. data/spec/lib/solidus_graphql_api/queries/taxonomy/taxons_query_spec.rb +11 -0
  192. data/spec/lib/solidus_graphql_api/queries/variant/default_price_query_spec.rb +9 -0
  193. data/spec/lib/solidus_graphql_api/queries/variant/images_query_spec.rb +11 -0
  194. data/spec/lib/solidus_graphql_api/queries/variant/option_values_query_spec.rb +11 -0
  195. data/spec/lib/solidus_graphql_api/queries/variant/prices_query_spec.rb +13 -0
  196. data/spec/lib/solidus_graphql_api/schema_spec.rb +80 -0
  197. data/spec/lib/solidus_graphql_api/types/base/object_spec.rb +29 -0
  198. data/spec/lib/solidus_graphql_api/types/json_spec.rb +115 -0
  199. data/spec/lib/solidus_graphql_api/types/option_type_spec.rb +7 -0
  200. data/spec/lib/solidus_graphql_api/types/product_property_spec.rb +22 -0
  201. data/spec/lib/solidus_graphql_api/types/product_spec.rb +56 -0
  202. data/spec/lib/solidus_graphql_api/types/query_spec.rb +33 -0
  203. data/spec/lib/solidus_graphql_api/types/variant_spec.rb +58 -0
  204. data/spec/requests/spree/graphql_controller_spec.rb +17 -0
  205. data/spec/spec_helper.rb +62 -0
  206. data/spec/support/expected_schema.graphql +2070 -0
  207. data/spec/support/graphql/mutations/add_addresses_to_checkout.gql +19 -0
  208. data/spec/support/graphql/mutations/add_payment_to_checkout.gql +13 -0
  209. data/spec/support/graphql/mutations/add_to_cart.gql +21 -0
  210. data/spec/support/graphql/mutations/advance_checkout.gql +13 -0
  211. data/spec/support/graphql/mutations/apply_coupon_code.gql +13 -0
  212. data/spec/support/graphql/mutations/complete_checkout.gql +13 -0
  213. data/spec/support/graphql/mutations/create_order.gql +11 -0
  214. data/spec/support/graphql/mutations/empty_cart.gql +17 -0
  215. data/spec/support/graphql/mutations/mark_default_address.gql +9 -0
  216. data/spec/support/graphql/mutations/next_checkout_state.gql +13 -0
  217. data/spec/support/graphql/mutations/remove_from_address_book.gql +14 -0
  218. data/spec/support/graphql/mutations/remove_from_cart.gql +17 -0
  219. data/spec/support/graphql/mutations/save_in_address_book.gql +57 -0
  220. data/spec/support/graphql/mutations/select_shipping_rate.gql +23 -0
  221. data/spec/support/graphql/mutations/set_order_email.gql +13 -0
  222. data/spec/support/graphql/mutations/update_cart_quantity.gql +18 -0
  223. data/spec/support/graphql/queries/completed_orders.gql +29 -0
  224. data/spec/support/graphql/queries/completed_orders/adjustments.gql +24 -0
  225. data/spec/support/graphql/queries/completed_orders/available_payment_methods.gql +15 -0
  226. data/spec/support/graphql/queries/completed_orders/billing_address.gql +40 -0
  227. data/spec/support/graphql/queries/completed_orders/line_items.gql +23 -0
  228. data/spec/support/graphql/queries/completed_orders/payments.gql +23 -0
  229. data/spec/support/graphql/queries/completed_orders/shipping_address.gql +40 -0
  230. data/spec/support/graphql/queries/countries.gql +24 -0
  231. data/spec/support/graphql/queries/current_order.gql +32 -0
  232. data/spec/support/graphql/queries/current_store.gql +24 -0
  233. data/spec/support/graphql/queries/current_user.gql +197 -0
  234. data/spec/support/graphql/queries/product_by_slug.gql +106 -0
  235. data/spec/support/graphql/queries/products.gql +7 -0
  236. data/spec/support/graphql/queries/taxonomies.gql +81 -0
  237. data/spec/support/graphql/responses/completed_orders.json.erb +58 -0
  238. data/spec/support/graphql/responses/completed_orders/adjustments.json.erb +34 -0
  239. data/spec/support/graphql/responses/completed_orders/available_payment_methods.json.erb +29 -0
  240. data/spec/support/graphql/responses/completed_orders/billing_address.json.erb +78 -0
  241. data/spec/support/graphql/responses/completed_orders/line_items.json.erb +43 -0
  242. data/spec/support/graphql/responses/completed_orders/payments.json.erb +27 -0
  243. data/spec/support/graphql/responses/completed_orders/shipping_address.json.erb +78 -0
  244. data/spec/support/graphql/responses/countries.json.erb +51 -0
  245. data/spec/support/graphql/responses/current_order.json.erb +36 -0
  246. data/spec/support/graphql/responses/current_store.json.erb +34 -0
  247. data/spec/support/graphql/responses/current_user.json.erb +232 -0
  248. data/spec/support/graphql/responses/product_by_slug.json.erb +123 -0
  249. data/spec/support/graphql/responses/taxonomies.json.erb +145 -0
  250. data/spec/support/helpers/graphql.rb +43 -0
  251. data/spec/support/matchers/graphql.rb +35 -0
  252. data/spec/support/shared_contexts/graphql_query_subject.rb +21 -0
  253. metadata +572 -0
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :complete_checkout, mutation: :complete_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][:completeCheckout]).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 isn't ready to be complete" do
30
+ let(:current_order) { create(:order_with_line_items) }
31
+
32
+ include_examples "responds with an unauthorized error"
33
+ end
34
+
35
+ context "when current order is ready to be complete" do
36
+ let(:current_order) { create(:order_ready_to_complete) }
37
+ let(:user_errors) { subject[:data][:completeCheckout][:errors] }
38
+
39
+ context 'and the current ability is unauthorized' do
40
+ include_examples "responds with an unauthorized error"
41
+ end
42
+
43
+ context 'and the current ability is authorized' do
44
+ let(:guest_token) { current_order.guest_token }
45
+ let(:response_order) { subject[:data][:completeCheckout][:order] }
46
+
47
+ context 'and the given current order state can advance' do
48
+ it { expect(response_order[:number]).to eq(current_order.number) }
49
+ it { expect(response_order[:email]).to eq(current_order.email) }
50
+ it { expect(response_order[:state]).to eq('complete') }
51
+ it { expect(user_errors).to be_empty }
52
+ it { is_expected.to_not have_key(:errors) }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :next_checkout_state, mutation: :next_checkout_state 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][:nextCheckoutState]).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 completed" do
30
+ let(:current_order) { create(:completed_order_with_totals) }
31
+
32
+ include_examples "responds with an unauthorized error"
33
+ end
34
+
35
+ context "when current order isn't completed" do
36
+ let(:current_order) { create(:order_with_line_items) }
37
+ let(:user_errors) { subject[:data][:nextCheckoutState][:errors] }
38
+
39
+ context 'and the current ability is unauthorized' do
40
+ include_examples "responds with an unauthorized error"
41
+ end
42
+
43
+ context 'and the current ability is authorized' do
44
+ let(:guest_token) { current_order.guest_token }
45
+ let(:response_order) { subject[:data][:nextCheckoutState][:order] }
46
+
47
+ context 'and the given current order state can advance' do
48
+ it { expect(response_order[:number]).to eq(current_order.number) }
49
+ it { expect(response_order[:email]).to eq(current_order.email) }
50
+ it { expect(response_order[:state]).to eq('address') }
51
+ it { expect(user_errors).to be_empty }
52
+ it { is_expected.to_not have_key(:errors) }
53
+ end
54
+
55
+ context "and the given current order state cannot advance" do
56
+ let(:confirm_state) { 'confirm' }
57
+
58
+ before { current_order.update(state: confirm_state) }
59
+
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(response_order[:state]).to eq(confirm_state) }
63
+ it { expect(user_errors.first[:path]).to eq(["input", "order", "state"]) }
64
+ it { expect(user_errors.first[:message]).to eq("cannot transition via \"next\"") }
65
+ it { is_expected.to_not have_key(:errors) }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :select_shipping_rate, mutation: :select_shipping_rate 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(:shipping_rate_id) { 'U3ByZWU6OlNoaXBwaW5nUmF0ZS0xMDAw' }
17
+ let(:mutation_variables) {
18
+ Hash[
19
+ input: {
20
+ shippingRateId: shipping_rate_id
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(:shipping_rate) { create(:shipping_rate, cost: 20) }
45
+ let(:user_errors) { subject[:data][:selectShippingRate][:errors] }
46
+
47
+ before do
48
+ current_order.shipments.first.shipping_rates << shipping_rate
49
+ end
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][:selectShippingRate][:order] }
58
+
59
+ context "when the given shipping rate id is wrong" do
60
+ it { expect(subject[:data][:selectShippingRate]).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 shipping rate selection" do
65
+ let(:selected_shipping_rate_id) { SolidusGraphqlApi::Schema.id_from_object(shipping_rate, nil, nil) }
66
+ let(:shipping_rate_id) { selected_shipping_rate_id }
67
+
68
+ before do
69
+ order_updater = instance_double('Spree::OrderUpdateAttributes', apply: false)
70
+ allow(Spree::OrderUpdateAttributes).to receive(:new).and_return(order_updater)
71
+ end
72
+
73
+ it { expect(subject[:data][:selectShippingRate]).to have_key(:errors) }
74
+ end
75
+
76
+ context "when the given shipping rate id is correct" do
77
+ let(:selected_shipping_rate_id) { SolidusGraphqlApi::Schema.id_from_object(shipping_rate, nil, nil) }
78
+ let(:shipping_rate_id) { selected_shipping_rate_id }
79
+
80
+ it "selects the correct shipping rate" do
81
+ shipping_rates = response_order[:shipments][:nodes].first[:shippingRates][:nodes]
82
+ selected_shipping_rate = shipping_rates.find { |shipping_rate| shipping_rate[:selected] }
83
+
84
+ expect( selected_shipping_rate[:id]).to eq(shipping_rate.id)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :create_order, mutation: :create_order do
6
+ let(:current_user) { create(:user) }
7
+ let(:current_ability) { Spree::Ability.new(nil) }
8
+ let(:current_store) { create(:store) }
9
+ let(:mutation_context) {
10
+ Hash[
11
+ current_user: current_user,
12
+ current_ability: current_ability,
13
+ current_store: current_store
14
+ ]
15
+ }
16
+
17
+ let(:mutation_variables) {
18
+ Hash[
19
+ input: {}
20
+ ]
21
+ }
22
+
23
+ context 'when the current ability is unauthorized' do
24
+ before do
25
+ current_ability.cannot :create, Spree::Order
26
+ end
27
+
28
+ it { expect(subject[:data][:createOrder]).to be_nil }
29
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
30
+ end
31
+
32
+ context 'when the current ability is authorized' do
33
+ let(:user_errors) { subject[:data][:createOrder][:errors] }
34
+ let(:response_order) { subject[:data][:createOrder][:order] }
35
+
36
+ context 'and the user is authenticated' do
37
+ let(:last_incomplete_order) { current_user.last_incomplete_spree_order(store: current_store) }
38
+
39
+ it { expect(response_order[:number]).to eq(last_incomplete_order.number) }
40
+ it { expect(response_order[:state]).to eq('cart') }
41
+ it { expect(user_errors).to be_empty }
42
+ it { is_expected.to_not have_key(:errors) }
43
+ end
44
+
45
+ context 'and the user is guest' do
46
+ let(:current_user) { nil }
47
+ let(:last_incomplete_order) { Spree::Order.incomplete.where(store: current_store).last }
48
+
49
+ it { expect(response_order[:number]).to eq(last_incomplete_order.number) }
50
+ it { expect(response_order[:state]).to eq('cart') }
51
+ it { expect(user_errors).to be_empty }
52
+ it { is_expected.to_not have_key(:errors) }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :empty_cart, mutation: :empty_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(:mutation_variables) {
17
+ Hash[
18
+ input: {}
19
+ ]
20
+ }
21
+
22
+ shared_examples "responds with an unauthorized error" do
23
+ it { expect(subject[:data][:emptyCart]).to be_nil }
24
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
25
+ end
26
+
27
+ context "when current order isn't present" do
28
+ let(:current_order) { nil }
29
+
30
+ include_examples "responds with an unauthorized error"
31
+ end
32
+
33
+ context "when current order is completed" do
34
+ let(:current_order) { create(:completed_order_with_totals) }
35
+
36
+ include_examples "responds with an unauthorized error"
37
+ end
38
+
39
+ context "when current order isn't completed" do
40
+ let(:current_order) { create(:order_with_line_items, state: 'address') }
41
+ let(:user_errors) { subject[:data][:emptyCart][:errors] }
42
+
43
+ context 'and the current ability is unauthorized' do
44
+ include_examples "responds with an unauthorized error"
45
+ end
46
+
47
+ context 'and the current ability is authorized' do
48
+ let(:guest_token) { current_order.guest_token }
49
+ let(:response_order) { subject[:data][:emptyCart][:order] }
50
+
51
+ it { expect(response_order[:number]).to eq(current_order.number) }
52
+ it { expect(response_order[:state]).to eq('cart') }
53
+ it { expect(response_order[:lineItems][:nodes]).to be_empty }
54
+ it { expect(user_errors).to be_empty }
55
+ it { is_expected.to_not have_key(:errors) }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :mark_default_address, mutation: :mark_default_address do
6
+ let(:mutation_context) { Hash[current_ability: Spree::Ability.new(current_user), current_user: current_user] }
7
+ let(:mutation_variables) { Hash[input: { addressId: SolidusGraphqlApi::Schema.id_from_object(address, nil, nil) }] }
8
+
9
+ let(:current_user) { create(:user_with_addresses) }
10
+ let(:address) { create(:address) }
11
+
12
+ context "when current user isn't present" do
13
+ let(:current_user) { nil }
14
+
15
+ it { expect(subject[:data][:markDefaultAddress]).to be_nil }
16
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
17
+ end
18
+
19
+ context "when current user is present" do
20
+ context "and the given address id is wrong" do
21
+ it { expect(subject[:data][:markDefaultAddress]).to be_nil }
22
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:'activerecord.exceptions.not_found') }
23
+ end
24
+
25
+ context "and the given address id is correct" do
26
+ before { current_user.addresses << address }
27
+
28
+ let(:default_address) { subject[:data][:markDefaultAddress][:user][:defaultAddress] }
29
+
30
+ it { expect(default_address[:id]).to eq address.id }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :remove_from_address_book, mutation: :remove_from_address_book do
6
+ let(:mutation_context) { Hash[current_ability: Spree::Ability.new(current_user), current_user: current_user] }
7
+ let(:mutation_variables) { Hash[input: { addressId: SolidusGraphqlApi::Schema.id_from_object(address, nil, nil) }] }
8
+
9
+ let(:address) { create(:address) }
10
+ let(:current_user) { create(:user_with_addresses) }
11
+
12
+ context "when current user isn't present" do
13
+ let(:current_user) { nil }
14
+
15
+ it { expect(subject[:data][:removeFromAddressBook]).to be_nil }
16
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
17
+ end
18
+
19
+ context "when current user is present" do
20
+ context "and the given address id is wrong" do
21
+ it { expect(subject[:data][:removeFromAddressBook]).to be_nil }
22
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
23
+ end
24
+
25
+ context "and the given address id is correct" do
26
+ before { current_user.addresses << address }
27
+
28
+ let(:user_addresses) { subject[:data][:removeFromAddressBook][:user][:addresses][:nodes] }
29
+
30
+ it { expect(user_addresses.count).to eq 2 }
31
+ it { expect(user_addresses.map{ |address| address[:id] }).to_not include(address.id) }
32
+
33
+ describe 'default address' do
34
+ let(:default_address) { subject[:data][:removeFromAddressBook][:user][:defaultAddress] }
35
+
36
+ context "when address is the default" do
37
+ before { current_user.mark_default_address(address.id) }
38
+
39
+ it { expect(default_address).to be_nil }
40
+ end
41
+
42
+ context "when address isn't the default" do
43
+ it { expect(default_address[:id]).to_not eq address.id }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe_mutation :remove_from_cart, mutation: :remove_from_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(: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(:mutation_variables) {
21
+ Hash[
22
+ input: {
23
+ lineItemId: line_item_id
24
+ }
25
+ ]
26
+ }
27
+
28
+ shared_examples "responds with an unauthorized error" do
29
+ it { expect(subject[:data][:removeFromCart]).to be_nil }
30
+ it { expect(subject[:errors].first[:message]).to eq I18n.t(:"unauthorized.default") }
31
+ end
32
+
33
+ context "when current order isn't present" do
34
+ let(:current_order) { nil }
35
+ let(:line_item_id) { 'not_existent' }
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(:completed_order_with_totals) }
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, state: 'address') }
48
+ let(:user_errors) { subject[:data][:removeFromCart][:errors] }
49
+
50
+ context 'and the current ability is unauthorized' do
51
+ include_examples "responds with an unauthorized error"
52
+ end
53
+
54
+ context 'and the current ability is authorized' do
55
+ let(:guest_token) { current_order.guest_token }
56
+ let(:response_order) { subject[:data][:removeFromCart][:order] }
57
+
58
+ it { expect(response_order[:number]).to eq(current_order.number) }
59
+ it { expect(response_order[:state]).to eq('cart') }
60
+ it { expect(response_order[:lineItems][:nodes]).to be_empty }
61
+ it { expect(user_errors).to be_empty }
62
+ it { is_expected.to_not have_key(:errors) }
63
+ end
64
+ end
65
+ end