Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Extract Legacy API v2 into it's own repository
Damian Legawiec5ea5b9b9d0b9
diff --git a/legacy_api_v2/Gemfile b/legacy_api_v2/Gemfiledeleted file mode 100644index bcb6bab621..0000000000--- a/legacy_api_v2/Gemfile+++ /dev/null@@ -1,5 +0,0 @@-eval_gemfile('../common_spree_dependencies.rb')--gem 'spree', path: '../'--gemspecdiff --git a/legacy_api_v2/README.md b/legacy_api_v2/README.mddeleted file mode 100644index db267ddcd6..0000000000--- a/legacy_api_v2/README.md+++ /dev/null@@ -1,52 +0,0 @@-# Spree Legacy API v2--> **⚠️ DEPRECATED**: This gem provides the legacy API v2 endpoints for Spree Commerce. It is deprecated and will be removed in a future version. Please migrate to **API v3**.--## Overview--This gem contains the legacy Storefront API v2 and Platform API v2 endpoints that were previously part of `spree_api`. These APIs are now deprecated in favor of the new API v3, which uses Alba serializers and provides a cleaner, more maintainable codebase.--## Installation--Add this line to your application's Gemfile:--```ruby-gem 'spree_legacy_api_v2'-```--And run the following command:--```bash-bundle exec rake spree_legacy_api_v2:install-```--This will install the database migrations and run them.--## Migration Guide--### Storefront API--The new Store API v3 provides similar functionality with improved consistency:--| Legacy v2 Endpoint | New v3 Endpoint |-|-------------------|-----------------|-| `GET /api/v2/storefront/products` | `GET /api/v3/store/products` |-| `GET /api/v2/storefront/cart` | `GET /api/v3/store/orders/:id` |-| `POST /api/v2/storefront/cart/add_item` | `POST /api/v3/store/orders/:id/line_items` |-| `GET /api/v2/storefront/account` | `GET /api/v3/store/customers/me` |--### Key Differences--1. **Serialization**: API v3 uses Alba serializers (faster, simpler) instead of JSONAPI::Serializer-2. **Response Format**: API v3 returns simple JSON objects instead of JSONAPI format-3. **Authentication**: Both APIs support the same authentication mechanisms-4. **TypeScript Types**: API v3 automatically generates TypeScript types via Typelizer--## Deprecation Timeline--- **Current**: API v2 is deprecated but fully functional-- **Next Major Release**: API v2 will be removed--## License--Spree is released under the [AGPL-3.0-or-later](https://www.gnu.org/licenses/agpl-3.0.html) and [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause) licenses.diff --git a/legacy_api_v2/Rakefile b/legacy_api_v2/Rakefiledeleted file mode 100644index 594140c02f..0000000000--- a/legacy_api_v2/Rakefile+++ /dev/null@@ -1,15 +0,0 @@-require 'rubygems'-require 'rake'-require 'rake/testtask'-require 'rspec/core/rake_task'-require 'spree/testing_support/common_rake'--RSpec::Core::RakeTask.new--task default: :spec--desc "Generates a dummy app for testing"-task :test_app do- ENV['LIB_NAME'] = 'spree/legacy_api_v2'- Rake::Task['common:test_app'].invoke-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/caching.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/caching.rbdeleted file mode 100644index ae16dccd7a..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/caching.rb+++ /dev/null@@ -1,40 +0,0 @@-module Spree- module Api- module V2- module Caching- extend ActiveSupport::Concern-- def collection_cache_key(collection)- params.delete(:page) if params[:page] == 1-- cache_key_parts = [- collection.cache_key_with_version,- resource_includes,- sparse_fields,- serializer_params_cache_key,- params[:sort]&.strip,- params[:page]&.to_s&.strip,- params[:per_page]&.to_s&.strip,- ]- cache_key_parts += additional_cache_key_parts if defined?(additional_cache_key_parts)- cache_key_parts = cache_key_parts.flatten.join('-')-- Digest::MD5.hexdigest(cache_key_parts)- end-- def collection_cache_opts- {- namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],- expires_in: Spree::Api::Config[:api_v2_collection_cache_ttl],- }- end-- def serializer_params_cache_key- serializer_params.values.map do |param|- param.try(:cache_key) || param.try(:flatten).try(:join, '-') || param.try(:to_s)- end.compact.join('-')- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rbdeleted file mode 100644index 1bf9e1ed29..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module Api- module V2- module CouponCodesHelper- def select_coupon_codes- params[:coupon_code].present? ? [params[:coupon_code]] : check_coupon_codes- end-- def check_coupon_codes- spree_current_order.promotions.coupons.map(&:code)- end-- def select_error(coupon_codes)- result = coupon_handler.new(spree_current_order).remove(coupon_codes.first)- result.error- end-- def select_errors(coupon_codes)- results = []- coupon_codes.each do |coupon_code|- results << coupon_handler.new(spree_current_order).remove(coupon_code)- end-- results.select(&:error)- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/number_resource.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/number_resource.rbdeleted file mode 100644index 945195abd9..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/number_resource.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module NumberResource- def resource- @resource ||= scope.find_by(number: params[:id]) || scope.find(params[:id])- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rbdeleted file mode 100644index e6b02ff929..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb+++ /dev/null@@ -1,37 +0,0 @@-module Spree- module Api- module V2- module Platform- module NestedSetRepositionConcern- def reposition- spree_authorize! :update, resource if spree_current_user.present?-- @new_parent = scope.find(permitted_resource_params[:new_parent_id])- new_index = permitted_resource_params[:new_position_idx].to_i-- if resource.move_to_child_with_index(@new_parent, new_index)- # If successful reposition call the custom method for handling success.- successful_reposition_actions- elsif resource.errors.any?- # If there are errors output them to the response- render_error_payload(resource.errors.full_messages.to_sentence)- else- # If the user drops the re-positioned item in the same location it came from- # we just render the serialized payload, nothing has changed, we don't need to- # render any errors, or fire any custom success methods.- render_serialized_payload { serialize_resource(resource) }- end- end-- private-- def successful_reposition_actions- # Call a separate method for a successful reposition so this can be easily overridden- # if a more complex set of events need to occur after a successful reposition.- render_serialized_payload { serialize_resource(resource) }- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rbdeleted file mode 100644index c8d4925021..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- module PromotionCalculatorParams- private-- def calculator_params- [:preferred_flat_percent, :preferred_amount, :preferred_first_item, :preferred_additional_item,- :preferred_max_items, :preferred_percent, :preferred_minimal_amount, :preferred_normal_amount,- :preferred_discount_amount, :preferred_currency, :preferred_base_amount, :preferred_base_percent, { preferred_tiers: {} }]- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rbdeleted file mode 100644index aa60af94af..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module Api- module V2- module Platform- module PromotionRuleParams- private-- def rule_params- [:preferred_match_policy, :preferred_country_id, :preferred_amount_min, :preferred_operator_min, :preferred_amount_max,- :preferred_operator_max, { taxon_ids: [], user_ids: [], product_ids: [], preferred_eligible_values: {} }]- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/product_list_includes.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/product_list_includes.rbdeleted file mode 100644index ad287b3bbf..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/product_list_includes.rb+++ /dev/null@@ -1,21 +0,0 @@-module Spree- module Api- module V2- # These includes are not picked automatically by ar_lazy_preload gem so we need to specify them manually.- module ProductListIncludes- def product_list_includes- {- option_types: [],- product_properties: [],- metafields: [],- variant_images: [],- tags: [],- taxons: [:taxonomy],- master: [:prices, :images, { stock_items: :stock_location }, metafields: [], option_values: []],- variants: [:prices, :images, { stock_items: :stock_location }, metafields: [], option_values: []]- }- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rbdeleted file mode 100644index 7dc4f2ae7b..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb+++ /dev/null@@ -1,18 +0,0 @@-module Spree- module Api- module V2- module Storefront- module MetadataControllerConcern- protected-- def ensure_valid_metadata- if params[:public_metadata].present? && !params[:public_metadata].is_a?(ActionController::Parameters) ||- params[:private_metadata].present? && !params[:private_metadata].is_a?(ActionController::Parameters)- render_error_payload(I18n.t(:invalid_params, scope: 'spree.api.v2.metadata'))- end- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb b/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/order_concern.rbdeleted file mode 100644index ba35a98e66..0000000000--- a/legacy_api_v2/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb+++ /dev/null@@ -1,49 +0,0 @@-module Spree- module Api- module V2- module Storefront- module OrderConcern- private-- def render_order(result)- if result.success?- render_serialized_payload { serialized_current_order }- else- render_error_payload(result.error&.value || result.value)- end- end-- def ensure_order- raise ActiveRecord::RecordNotFound if spree_current_order.nil?- end-- def order_token- request.headers['X-Spree-Order-Token'] || params[:order_token]- end-- def spree_current_order- @spree_current_order ||= find_spree_current_order- end-- def find_spree_current_order- Spree.api.storefront_current_order_finder.new.execute(- store: current_store,- user: spree_current_user,- token: order_token,- currency: current_currency- )- end-- def serialized_current_order- serialize_resource(spree_current_order)- end-- def serialize_order(order)- Spree::Deprecation.warn('OrderConcern#serialize_order is deprecated and will be removed in Spree 5.5. Please use `serialize_resource` method')- serialize_resource(order)- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/admin/oauth_applications_controller.rb b/legacy_api_v2/app/controllers/spree/admin/oauth_applications_controller.rbdeleted file mode 100644index aac419e7f7..0000000000--- a/legacy_api_v2/app/controllers/spree/admin/oauth_applications_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Admin- class OauthApplicationsController < ResourceController- include Spree::Admin::SettingsConcern-- before_action :set_default_scopes, only: [:new, :edit]-- private-- def create_turbo_stream_enabled?- true- end-- def set_default_scopes- @object.scopes = 'admin' if @object.scopes.blank?- end-- def permitted_resource_params- params.require(:oauth_application).permit(:name, :scopes)- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/base_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/base_controller.rbdeleted file mode 100644index e88c05a1e3..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/base_controller.rb+++ /dev/null@@ -1,233 +0,0 @@-module Spree- module Api- module V2- class BaseController < ActionController::API- include ActiveStorage::SetCurrent- include CanCan::ControllerAdditions- include Spree::Core::ControllerHelpers::StrongParameters- include Spree::Core::ControllerHelpers::Store- include Spree::Core::ControllerHelpers::Locale- include Spree::Core::ControllerHelpers::Currency-- rescue_from ActiveRecord::RecordNotFound, with: :record_not_found- rescue_from CanCan::AccessDenied, with: :access_denied- rescue_from Doorkeeper::Errors::DoorkeeperError, with: :access_denied_401- rescue_from Spree::Core::GatewayError, with: :gateway_error- rescue_from ActionController::ParameterMissing, with: :error_during_processing- if defined?(JSONAPI::Serializer::UnsupportedIncludeError)- rescue_from JSONAPI::Serializer::UnsupportedIncludeError, with: :error_during_processing- end- rescue_from ArgumentError, with: :error_during_processing- rescue_from ActionDispatch::Http::Parameters::ParseError, with: :error_during_processing-- # Returns the content type for the API- # @return [String] The content type, eg 'application/vnd.api+json'- def content_type- Spree::Api::Config[:api_v2_content_type]- end-- protected-- def serialize_collection(collection)- collection_serializer.new(- collection,- collection_options(collection).merge(params: serializer_params)- ).serializable_hash- end-- def serialize_resource(resource)- resource_serializer.new(- resource,- params: serializer_params,- include: resource_includes,- fields: sparse_fields- ).serializable_hash- end-- # Returns a paginated collection- # @return [Array] The paginated collection- def paginated_collection- @paginated_collection ||= collection_paginator.new(sorted_collection, params).call- end-- # Returns the collection paginator- # @return [Class] The collection paginator class, default is Spree::Shared::Paginate- def collection_paginator- Spree.api.storefront_collection_paginator- end-- # Renders a serialized payload with the given status code- # @param status [Integer] HTTP status code to return, eg 200, 201, 204- # @yield [Hash] The serialized data to render- def render_serialized_payload(status = 200)- render json: yield, status: status, content_type: content_type- end-- # Renders a serialized error payload with the given status code- # @param status [Integer] HTTP status code to return- # @yield [Hash] The serialized data to render- def render_error_payload(error, status = 422)- json = if error.is_a?(ActiveModel::Errors)- { error: error.full_messages.to_sentence, errors: error.messages }- elsif error.is_a?(Struct)- { error: error.to_s, errors: error.to_h }- else- { error: error }- end-- render json: json, status: status, content_type: content_type- end-- # Renders a serialized result payload with the given status code- # @param result [Object] The result to render- # @param ok_status [Integer] HTTP status code to return if the result is successful, eg 200, 201, 204- def render_result(result, ok_status = 200)- if result.success?- render_serialized_payload(ok_status) { serialize_resource(result.value) }- else- render_error_payload(result.error)- end- end-- # Returns the current Spree user- # @return [Spree.user_class] The current Spree user- def spree_current_user- return nil unless doorkeeper_token- return @spree_current_user if defined?(@spree_current_user)-- @spree_current_user ||= ActiveRecord::Base.connected_to(role: :writing) do- doorkeeper_authorize!- doorkeeper_token.resource_owner- end- end-- alias try_spree_current_user spree_current_user # for compatibility with spree_legacy_frontend-- # Authorizes the current Spree user for the given action and subject- # @param action [Symbol] The action to authorize- # @param subject [Object] The subject to authorize- # @param args [Array] Additional arguments to pass to the authorize! method- # @return [void]- def spree_authorize!(action, subject, *args)- authorize!(action, subject, *args)- end-- # Raises an AccessDenied error if the current Spree user is nil- # @raise [CanCan::AccessDenied] If the current Spree user is nil- def require_spree_current_user- raise CanCan::AccessDenied if spree_current_user.nil?- end-- # Needs to be overridden so that we use Spree's Ability rather than anyone else's.- def current_ability- @current_ability ||= Spree.ability_class.new(spree_current_user, ability_options)- end-- # this method can be extended in extensions or developer applications- # @return [Hash] The ability options- def ability_options- { store: current_store }- end-- # Returns the requested includes- # @return [Array] The requested includes- def request_includes- # if API user wants to receive only the bare-minimum- # the API will return only the main resource without any included- if params[:include]&.blank?- []- elsif params[:include].present?- params[:include].split(',')- end- end-- # Returns the resource includes, useful to avoid N+1 queries- # @return [Array] The resource includes, eg [:images, :variants]- def resource_includes- (request_includes || default_resource_includes).map(&:intern)- end-- # overwrite this method in your controllers to set JSON API default include value- # https://jsonapi.org/format/#fetching-includes- # eg.:- # %w[images variants]- # ['variant.images', 'line_items']- def default_resource_includes- []- end-- # Returns the JSON API sparse fields- # @return [Hash] The sparse fields, eg { product: [:name, :description] }- def sparse_fields- return unless params[:fields]&.respond_to?(:each)-- fields = {}- params[:fields].- select { |_, v| v.is_a?(String) }.- each { |type, values| fields[type.intern] = values.split(',').map(&:intern) }- fields.presence- end-- # Returns the serializer global params- # all of these params are passed down to the serializer- # @return [Hash] The serializer params- def serializer_params- {- currency: current_currency,- locale: current_locale,- price_options: current_price_options,- store: current_store,- user: spree_current_user,- image_transformation: params[:image_transformation],- taxon_image_transformation: params[:taxon_image_transformation]- }- end-- # Renders a 404 error payload- # @param exception [Exception] The exception to render- # @return [void]- def record_not_found(exception)- Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')-- render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)- end-- # Renders a 403 error payload- # @param exception [Exception] The exception to render- # @return [void]- def access_denied(exception)- Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')-- render_error_payload(exception.message, 403)- end-- # Renders a 401 error payload- # @param exception [Exception] The exception to render- # @return [void]- def access_denied_401(exception)- render_error_payload(exception.message, 401)- end-- # Renders a 500 error payload when a payment gateway error occurs- # @param exception [Exception] The exception to render- # @return [void]- def gateway_error(exception)- Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')-- render_error_payload(exception.message)- end-- # Renders a 400 error payload when an error occurs during parameter parsing- # @param exception [Exception] The exception to render- # @return [void]- def error_during_processing(exception)- Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')-- message = exception.respond_to?(:original_message) ? exception.original_message : exception.message-- render_error_payload(message, 400)- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/data_feeds/google_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/data_feeds/google_controller.rbdeleted file mode 100644index 4a1e8ccb03..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/data_feeds/google_controller.rb+++ /dev/null@@ -1,24 +0,0 @@-module Spree- module Api- module V2- module DataFeeds- class GoogleController < ::Spree::Api::V2::BaseController- def rss_feed- send_data data_feeds_google_rss_service.value[:file], filename: 'products.rss', type: 'text/xml'- end-- private-- def settings- @settings ||= Spree::DataFeed::Google.find_by!(store: current_store, slug: params[:slug], active: true)- end-- def data_feeds_google_rss_service- Spree.data_feeds_google_rss_service.new.call(settings)- end- end- end- end- end-end-diff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/addresses_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/addresses_controller.rbdeleted file mode 100644index 625c032e17..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/addresses_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class AddressesController < ResourceController- private-- def model_class- Spree::Address- end-- def scope_includes- [:country, :state, :user]- end-- def resource_serializer- Spree.api.platform_address_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/adjustments_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/adjustments_controller.rbdeleted file mode 100644index 6ab0358043..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/adjustments_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class AdjustmentsController < ResourceController- private-- def model_class- Spree::Adjustment- end-- def scope_includes- [:order, :adjustable]- end-- def resource_serializer- Spree.api.platform_adjustment_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/classifications_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/classifications_controller.rbdeleted file mode 100644index d2cf87db8a..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/classifications_controller.rb+++ /dev/null@@ -1,26 +0,0 @@-module Spree- module Api- module V2- module Platform- class ClassificationsController < ResourceController- private-- def model_class- Spree::Classification- end-- def scope_includes- [- taxon: [],- product: [:variants_including_master, :master, { variants: [:prices] }]- ]- end-- def resource_serializer- Spree.api.platform_classification_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/countries_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/countries_controller.rbdeleted file mode 100644index 17f1278422..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/countries_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class CountriesController < ResourceController- private-- def model_class- Spree::Country- end-- def scope_includes- [:states, :zones]- end-- def resource_serializer- Spree.api.platform_country_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/data_feeds_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/data_feeds_controller.rbdeleted file mode 100644index d17afee92e..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/data_feeds_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class DataFeedsController < ResourceController- private-- def model_class- Spree::DataFeed- end-- def resource_serializer- Spree.api.platform_data_feed_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/digital_links_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/digital_links_controller.rbdeleted file mode 100644index a1793059fc..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/digital_links_controller.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module Api- module V2- module Platform- class DigitalLinksController < ResourceController- def reset- spree_authorize! :update, resource if spree_current_user.present?-- if resource.reset!- render_serialized_payload { serialize_resource(resource) }- else- render_error_payload(resource.errors)- end- end-- private-- def model_class- Spree::DigitalLink- end-- def resource_serializer- Spree.api.platform_digital_link_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/digitals_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/digitals_controller.rbdeleted file mode 100644index 7ade57332b..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/digitals_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class DigitalsController < ResourceController- private-- def model_class- Spree::Digital- end-- def spree_permitted_attributes- super + [:attachment]- end-- def resource_serializer- Spree.api.platform_digital_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/gift_cards_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/gift_cards_controller.rbdeleted file mode 100644index 46d1c36724..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/gift_cards_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class GiftCardsController < ResourceController- private-- def model_class- Spree::GiftCard- end-- def permitted_resource_params- params.require(:gift_card).permit(permitted_gift_card_attributes)- end-- def resource_serializer- Spree.api.platform_gift_card_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/line_items_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/line_items_controller.rbdeleted file mode 100644index 0ce50fc275..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/line_items_controller.rb+++ /dev/null@@ -1,63 +0,0 @@-module Spree- module Api- module V2- module Platform- class LineItemsController < ResourceController- def create- order = current_store.orders.find(permitted_resource_params[:order_id])-- result = create_service.call(order: order, line_item_attributes: permitted_resource_params)-- if result.success?- render_serialized_payload(201) { serialize_resource(result.value) }- else- render_error_payload(result.error)- end- end-- def update- result = update_service.call(line_item: resource, line_item_attributes: permitted_resource_params)-- if result.success?- render_serialized_payload { serialize_resource(result.value) }- else- render_error_payload(resource.errors)- end- end-- def destroy- result = destroy_service.call(line_item: resource)-- if result.success?- head 204- else- render_error_payload(result.error)- end- end-- private-- def model_class- Spree::LineItem- end-- def create_service- Spree.api.platform_line_item_create_service- end-- def update_service- Spree.api.platform_line_item_update_service- end-- def destroy_service- Spree.api.platform_line_item_destroy_service- end-- def resource_serializer- Spree.api.platform_line_item_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/option_types_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/option_types_controller.rbdeleted file mode 100644index 0ce847c157..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/option_types_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class OptionTypesController < ResourceController- private-- def model_class- Spree::OptionType- end-- def resource_serializer- Spree.api.platform_option_type_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/option_values_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/option_values_controller.rbdeleted file mode 100644index 56f7b6d2ec..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/option_values_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class OptionValuesController < ResourceController- private-- def model_class- Spree::OptionValue- end-- def scope_includes- [:option_type]- end-- def resource_serializer- Spree.api.platform_option_value_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/orders_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/orders_controller.rbdeleted file mode 100644index d308c217ff..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/orders_controller.rb+++ /dev/null@@ -1,167 +0,0 @@-module Spree- module Api- module V2- module Platform- class OrdersController < ResourceController- include CouponCodesHelper- include NumberResource-- def create- resource = current_store.orders.new(permitted_resource_params)-- if resource.save- render_serialized_payload(201) { serialize_resource(resource) }- else- render_error_payload(resource.errors)- end- end-- def update- result = update_service.call(- order: resource,- params: params,- permitted_attributes: spree_permitted_attributes,- request_env: request.headers.env- )-- render_result(result)- end-- def next- result = next_service.call(order: resource)-- render_result(result)- end-- def advance- result = advance_service.call(order: resource)-- render_result(result)- end-- def complete- result = complete_service.call(order: resource)-- render_result(result)- end-- def empty- result = empty_service.call(order: resource)-- render_result(result)- end-- def cancel- result = cancel_service.call(order: resource, canceler: spree_current_user)-- render_result(result)- end-- def approve- result = approve_service.call(order: resource, approver: spree_current_user)-- render_result(result)- end-- def destroy- result = destroy_service.call(order: resource)-- if result.success?- head 204- else- render_error_payload(result.error)- end- end-- def apply_coupon_code- resource.coupon_code = params[:coupon_code]- result = coupon_handler.new(resource).apply-- if result.error.blank?- render_serialized_payload { serialize_resource(resource.reload) }- else- render_error_payload(result.error)- end- end-- def use_store_credit- result = use_store_credit_service.call(- order: resource,- amount: params[:amount].try(:to_f)- )-- render_result(result)- end-- private-- def model_class- Spree::Order- end-- def allowed_sort_attributes- super.push(:available_on, :make_active_at, :total, :payment_total, :item_total, :shipment_total,- :adjustment_total, :promo_total, :included_tax_total, :additional_tax_total,- :item_count, :tax_total, :completed_at)- end-- def update_service- Spree.api.platform_order_update_service- end-- def next_service- Spree.api.platform_order_next_service- end-- def advance_service- Spree.api.platform_order_advance_service- end-- def use_store_credit_service- Spree.api.platform_order_use_store_credit_service- end-- def complete_service- Spree.api.platform_order_complete_service- end-- def empty_service- Spree.api.platform_order_empty_service- end-- def destroy_service- Spree.api.platform_order_destroy_service- end-- def approve_service- Spree.api.platform_order_approve_service- end-- def cancel_service- Spree.api.platform_order_cancel_service- end-- def coupon_handler- Spree.api.platform_coupon_handler- end-- def spree_permitted_attributes- super + [- bill_address_attributes: Spree::Address.json_api_permitted_attributes,- ship_address_attributes: Spree::Address.json_api_permitted_attributes,- line_items_attributes: Spree::LineItem.json_api_permitted_attributes,- payments_attributes: Spree::Payment.json_api_permitted_attributes + [- source_attributes: Spree::CreditCard.json_api_permitted_attributes- ],- shipments_attributes: Spree::Shipment.json_api_permitted_attributes- ]- end-- def resource_serializer- Spree.api.platform_order_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/payment_methods_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/payment_methods_controller.rbdeleted file mode 100644index 996e93f625..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/payment_methods_controller.rb+++ /dev/null@@ -1,31 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentMethodsController < ResourceController- private-- def model_class- Spree::PaymentMethod- end-- def spree_permitted_attributes- preferred_attributes = []-- if action_name == 'update'- resource.defined_preferences.each do |preference|- preferred_attributes << "preferred_#{preference}".to_sym- end- end-- super + preferred_attributes- end-- def resource_serializer- Spree.api.platform_payment_method_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/payments_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/payments_controller.rbdeleted file mode 100644index df655b3671..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/payments_controller.rb+++ /dev/null@@ -1,21 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentsController < ResourceController- include NumberResource-- private-- def model_class- Spree::Payment- end-- def resource_serializer- Spree.api.platform_payment_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/products_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/products_controller.rbdeleted file mode 100644index e8ba103c4e..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/products_controller.rb+++ /dev/null@@ -1,41 +0,0 @@-module Spree- module Api- module V2- module Platform- class ProductsController < ResourceController- include ::Spree::Api::V2::ProductListIncludes-- private-- def model_class- Spree::Product- end-- def scope_includes- product_list_includes- end-- def spree_permitted_attributes- super.push(:price)- end-- def allowed_sort_attributes- super.push(:available_on, :make_active_at)- end-- def sorted_collection- collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call- end-- def collection_sorter- Spree.api.platform_products_sorter- end-- def resource_serializer- Spree.api.platform_product_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_actions_controller.rbdeleted file mode 100644index 9fcc902a19..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb+++ /dev/null@@ -1,34 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionActionsController < ResourceController- include ::Spree::Api::V2::Platform::PromotionCalculatorParams-- private-- def model_class- Spree::PromotionAction- end-- def scope_includes- [:promotion]- end-- def spree_permitted_attributes- conditional_params = action_name == 'update' ? [:id] : []-- super + [{- promotion_action_line_items_attributes: Spree::PromotionActionLineItem.json_api_permitted_attributes.concat(conditional_params),- calculator_attributes: Spree::Calculator.json_api_permitted_attributes.concat(conditional_params, calculator_params)- }]- end-- def resource_serializer- Spree.api.platform_promotion_action_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_categories_controller.rbdeleted file mode 100644index 562f2ac5f3..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionCategoriesController < ResourceController- private-- def model_class- Spree::PromotionCategory- end-- def scope_includes- [:promotions]- end-- def resource_serializer- Spree.api.platform_promotion_category_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_rules_controller.rbdeleted file mode 100644index 278bc83d31..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionRulesController < ResourceController- include ::Spree::Api::V2::Platform::PromotionRuleParams-- private-- def model_class- Spree::PromotionRule- end-- def scope_includes- [:promotion]- end-- def spree_permitted_attributes- super + rule_params- end-- def resource_serializer- Spree.api.platform_promotion_rule_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotions_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/promotions_controller.rbdeleted file mode 100644index 8c0851a762..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/promotions_controller.rb+++ /dev/null@@ -1,35 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionsController < ResourceController- include ::Spree::Api::V2::Platform::PromotionRuleParams- include ::Spree::Api::V2::Platform::PromotionCalculatorParams-- private-- def model_class- Spree::Promotion- end-- def scope_includes- [:promotion_category, :promotion_rules, :promotion_actions]- end-- def spree_permitted_attributes- conditional_params = action_name == 'update' ? [:id] : []-- super + [{ promotion_actions_attributes: Spree::PromotionAction.json_api_permitted_attributes.concat(conditional_params) + [{- promotion_action_line_items_attributes: Spree::PromotionActionLineItem.json_api_permitted_attributes.concat(conditional_params),- calculator_attributes: Spree::Calculator.json_api_permitted_attributes.concat(conditional_params, calculator_params)- }], promotion_rules_attributes: Spree::PromotionRule.json_api_permitted_attributes.concat(conditional_params, rule_params) }]- end-- def resource_serializer- Spree.api.platform_promotion_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/resource_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/resource_controller.rbdeleted file mode 100644index b9c2e2b359..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/resource_controller.rb+++ /dev/null@@ -1,154 +0,0 @@-module Spree- module Api- module V2- module Platform- class ResourceController < ::Spree::Api::V2::ResourceController- # doorkeeper scopes usage: https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes- before_action :validate_token_client- before_action -> { doorkeeper_authorize! :read, :admin }- before_action -> { doorkeeper_authorize! :write, :admin }, if: :write_request?-- # optional authorization if using a user token instead of app token- before_action :authorize_spree_user-- # index and show actions are defined in Spree::Api::V2::ResourceController-- def create- resource = model_class.new(permitted_resource_params)- ensure_current_store(resource)-- if resource.save- render_serialized_payload(201) { serialize_resource(resource) }- else- render_error_payload(resource.errors)- end- end-- def update- resource.assign_attributes(permitted_resource_params)- ensure_current_store(resource)-- if resource.save- render_serialized_payload { serialize_resource(resource) }- else- render_error_payload(resource.errors)- end- end-- def destroy- if resource.destroy- head 204- else- render_error_payload(resource.errors)- end- end-- protected-- def resource_serializer- serializer_base_name = model_class.to_s.sub('Spree::', '')- "Spree::Api::V2::Platform::#{serializer_base_name}Serializer".constantize- end-- def collection_serializer- resource_serializer- end-- # overwriting to utilize ransack gem for filtering- # https://github.com/activerecord-hackery/ransack#search-matchers- def collection- @collection ||= scope.ransack(params[:filter]).result- end-- # overwriting to skip cancancan check if API is consumed by an application- def scope- return super if spree_current_user.present?-- super(skip_cancancan: true)- end-- # We're overwriting this method because the original one calls `dookreeper_authorize`- # which breaks our application authorizations defined on top of this controller- def spree_current_user- return nil unless doorkeeper_token- return nil if doorkeeper_token.resource_owner_id.nil?- return @spree_current_user if @spree_current_user-- @spree_current_user ||= doorkeeper_token.resource_owner- end-- def access_denied(exception)- access_denied_401(exception)- end-- def validate_token_client- return if doorkeeper_token.nil?-- raise Doorkeeper::Errors::DoorkeeperError if doorkeeper_token.application.nil?- end-- # if using a user oAuth token we need to check CanCanCan abilities- # defined in https://github.com/spree/spree/blob/main/core/app/models/spree/ability.rb- def authorize_spree_user- return if spree_current_user.nil?-- case action_name- when 'create'- spree_authorize! :create, model_class- when 'destroy'- spree_authorize! :destroy, resource- when 'index'- spree_authorize! :read, model_class- when 'show'- spree_authorize! :read, resource- else- spree_authorize! :update, resource- end- end-- def model_param_name- model_class.to_s.demodulize.underscore- end-- def spree_permitted_attributes- store_ids = if model_class.method_defined?(:stores)- [{ store_ids: [] }]- else- []- end-- model_class.json_api_permitted_attributes + store_ids + metadata_params + metafields_params- end-- def metadata_params- if model_class.include?(Metadata)- [{ public_metadata: {}, private_metadata: {} }]- else- []- end- end-- def metafields_params- if Spree::MetafieldDefinition.available_resources.map(&:name).include?(model_class.name) && model_class.method_defined?(:metafields)- [{ metafields_attributes: Spree::PermittedAttributes.metafield_attributes }]- else- []- end- end-- def permitted_resource_params- params.require(model_param_name).permit(spree_permitted_attributes)- end-- def allowed_sort_attributes- (super << spree_permitted_attributes).uniq.compact- end-- def write_request?- %w[put patch post delete].include?(request.request_method.downcase)- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/roles_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/roles_controller.rbdeleted file mode 100644index 13e42016e4..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/roles_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class RolesController < ResourceController- private-- def model_class- Spree::Role- end-- def resource_serializer- Spree.api.platform_role_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipments_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/shipments_controller.rbdeleted file mode 100644index 99a47b7b82..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipments_controller.rb+++ /dev/null@@ -1,147 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShipmentsController < ResourceController- include NumberResource-- before_action :load_variant, only: %i[transfer_to_location transfer_to_shipment]-- SHIPMENT_STATES = %w[ready ship cancel resume pend]-- def create- # FIXME: support saving metadata- result = create_service.call(- store: current_store,- shipment_attributes: params.require(:shipment).permit(- :order_id, :stock_location_id, :variant_id, :quantity- )- )- render_result(result, 201)- end-- def update- result = update_service.call(shipment: resource, shipment_attributes: permitted_resource_params)- render_result(result)- end-- SHIPMENT_STATES.each do |state|- define_method state do- result = change_state_service.call(shipment: resource, state: state)- render_result(result)- end- end-- def add_item- result = add_item_service.call(- shipment: resource,- variant_id: params.dig(:shipment, :variant_id),- quantity: params.dig(:shipment, :quantity)- )- render_result(result)- end-- def remove_item- result = remove_item_service.call(- shipment: resource,- variant_id: params.dig(:shipment, :variant_id),- quantity: params.dig(:shipment, :quantity)- )-- if result.success?- if result.value == :shipment_deleted- head 204- else- render_serialized_payload { serialize_resource(result.value) }- end- else- render_error_payload(result.error)- end- end-- def transfer_to_location- stock_location = Spree::StockLocation.find(params.dig(:shipment, :stock_location_id))- quantity = params.dig(:shipment, :quantity)&.to_i || 1-- unless quantity > 0- render_error_payload("#{I18n.t('spree.api.shipment_transfer_errors_occurred')} \n #{I18n.t('spree.api.negative_quantity')}")- return- end-- transfer = resource.transfer_to_location(@variant, quantity, stock_location)- if transfer.valid? && transfer.run!- render json: { message: I18n.t('spree.api.shipment_transfer_success') }, status: 201- else- render_error_payload(transfer.errors)- end- end-- def transfer_to_shipment- target_shipment = Spree::Shipment.find_by!(number: params.dig(:shipment, :target_shipment_number))- quantity = params.dig(:shipment, :quantity)&.to_i || 1-- error =- if quantity < 0 && target_shipment == resource- "#{I18n.t('spree.api.negative_quantity')}, \n#{I18n.t('spree.api.wrong_shipment_target')}"- elsif target_shipment == resource- I18n.t('spree.api.wrong_shipment_target')- elsif quantity < 0- I18n.t('spree.api.negative_quantity')- end-- if error- render_error_payload("#{I18n.t('spree.api.shipment_transfer_errors_occurred')} \n#{error}")- else- transfer = resource.transfer_to_shipment(@variant, quantity, target_shipment)- if transfer.valid? && transfer.run!- render json: { message: I18n.t('spree.api.shipment_transfer_success') }, status: 201- else- render_error_payload(transfer.errors)- end- end- end-- private-- def model_class- Spree::Shipment- end-- def load_variant- @variant = current_store.variants.find_by(id: params.dig(:shipment, :variant_id))- end-- def spree_permitted_attributes- Spree::Shipment.json_api_permitted_attributes + [- :selected_shipping_rate_id- ]- end-- def create_service- Spree.api.platform_shipment_create_service- end-- def update_service- Spree.api.platform_shipment_update_service- end-- def change_state_service- Spree.api.platform_shipment_change_state_service- end-- def add_item_service- Spree.api.platform_shipment_add_item_service- end-- def remove_item_service- Spree.api.platform_shipment_remove_item_service- end-- def resource_serializer- Spree.api.platform_shipment_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_categories_controller.rbdeleted file mode 100644index aafdca42ae..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShippingCategoriesController < ResourceController- private-- def model_class- Spree::ShippingCategory- end-- def resource_serializer- Spree.api.platform_shipping_category_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_methods_controller.rbdeleted file mode 100644index 29ab32c499..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb+++ /dev/null@@ -1,28 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShippingMethodsController < ResourceController- private-- def model_class- Spree::ShippingMethod- end-- def spree_permitted_attributes- super + [- {- shipping_category_ids: [],- calculator_attributes: {}- }- ]- end-- def resource_serializer- Spree.api.platform_shipping_method_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/states_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/states_controller.rbdeleted file mode 100644index 85642a49d5..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/states_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class StatesController < ResourceController- private-- def model_class- Spree::State- end-- def scope_includes- [:country]- end-- def resource_serializer- Spree.api.platform_state_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_items_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_items_controller.rbdeleted file mode 100644index 2a719f2714..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_items_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockItemsController < ResourceController- private-- def model_class- Spree::StockItem- end-- def scope_includes- [:variant, :stock_location]- end-- def resource_serializer- Spree.api.platform_stock_item_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_locations_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_locations_controller.rbdeleted file mode 100644index 790f4fe172..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/stock_locations_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockLocationsController < ResourceController- private-- def model_class- Spree::StockLocation- end-- def scope_includes- [:country]- end-- def resource_serializer- Spree.api.platform_stock_location_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rbdeleted file mode 100644index c2af60e9e5..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditCategoriesController < ResourceController- private-- def model_class- Spree::StoreCreditCategory- end-- def resource_serializer- Spree.api.platform_store_credit_category_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_types_controller.rbdeleted file mode 100644index 97433fcb8c..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditTypesController < ResourceController- private-- def model_class- Spree::StoreCreditType- end-- def resource_serializer- Spree.api.platform_store_credit_type_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credits_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credits_controller.rbdeleted file mode 100644index bfdf1eb7d1..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/store_credits_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditsController < ResourceController- private-- def model_class- Spree::StoreCredit- end-- def scope_includes- [:user, :created_by, :category, :credit_type]- end-- def resource_serializer- Spree.api.platform_store_credit_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_categories_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_categories_controller.rbdeleted file mode 100644index 58a91389b1..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_categories_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxCategoriesController < ResourceController- private-- def model_class- Spree::TaxCategory- end-- def scope_includes- [:tax_rates]- end-- def resource_serializer- Spree.api.platform_tax_category_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_rates_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_rates_controller.rbdeleted file mode 100644index 1da1226a80..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/tax_rates_controller.rb+++ /dev/null@@ -1,27 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxRatesController < ResourceController- private-- def model_class- Spree::TaxRate- end-- def scope_includes- [:zone, :tax_category]- end-- def spree_permitted_attributes- super + [calculator_attributes: Spree::Calculator.json_api_permitted_attributes]- end-- def resource_serializer- Spree.api.platform_tax_rate_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/taxonomies_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/taxonomies_controller.rbdeleted file mode 100644index 028093eec2..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/taxonomies_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxonomiesController < ResourceController- private-- def model_class- Spree::Taxonomy- end-- def scope_includes- [:taxons, :root]- end-- def resource_serializer- Spree.api.platform_taxonomy_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/taxons_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/taxons_controller.rbdeleted file mode 100644index 3a2c328aa3..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/taxons_controller.rb+++ /dev/null@@ -1,59 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxonsController < ResourceController- include ::Spree::Api::V2::Platform::NestedSetRepositionConcern-- private-- def successful_reposition_actions- reload_taxon_and_set_new_permalink(resource)- update_permalinks_on_child_taxons-- render_serialized_payload { serialize_resource(resource) }- end-- def reload_taxon_and_set_new_permalink(taxon)- taxon.reload- taxon.set_permalink- taxon.save!- end-- def update_permalinks_on_child_taxons- resource.descendants.each do |taxon|- reload_taxon_and_set_new_permalink(taxon)- end- end-- def model_class- Spree::Taxon- end-- def scope_includes- node_includes = %i[icon parent taxonomy]-- {- parent: node_includes,- children: node_includes,- taxonomy: [root: node_includes],- icon: [attachment_attachment: :blob]- }- end-- def serializer_params- super.merge(include_products: action_name == 'show')- end-- def spree_permitted_attributes- super + [:new_parent_id, :new_position_idx]- end-- def resource_serializer- Spree.api.platform_taxon_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/users_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/users_controller.rbdeleted file mode 100644index bfaeab213a..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/users_controller.rb+++ /dev/null@@ -1,37 +0,0 @@-module Spree- module Api- module V2- module Platform- class UsersController < ResourceController- private-- def model_class- Spree.user_class- end-- def resource_serializer- Spree.api.platform_user_serializer- end-- def scope_includes- [:ship_address, :bill_address]- end-- # we need to define this here as developers can configure their own `user_class`- def model_param_name- 'user'- end-- def spree_permitted_attributes- super + [:password, :password_confirmation]- end-- # we need to override this method to avoid trying to create user role when creating a user- def ensure_current_store(_resource)- # do nothing- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/variants_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/variants_controller.rbdeleted file mode 100644index 6a1863fa31..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/variants_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class VariantsController < ResourceController- private-- def model_class- Spree::Variant- end-- def spree_permitted_attributes- super + [:option_value_ids, :price, :currency]- end-- def resource_serializer- Spree.api.platform_variant_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/wished_items_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/wished_items_controller.rbdeleted file mode 100644index 5a11ac9c12..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/wished_items_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class WishedItemsController < ResourceController- private-- def scope_includes- [:variant]- end-- def model_class- Spree::WishedItem- end-- def resource_serializer- Spree.api.platform_wished_item_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/wishlists_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/wishlists_controller.rbdeleted file mode 100644index 34a92a4f60..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/wishlists_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class WishlistsController < ResourceController- private-- def model_class- Spree::Wishlist- end-- def scope_includes- [:wished_items]- end-- def resource_serializer- Spree.api.platform_wishlist_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/platform/zones_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/platform/zones_controller.rbdeleted file mode 100644index c01b9b58d4..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/platform/zones_controller.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module Api- module V2- module Platform- class ZonesController < ResourceController- private-- def model_class- Spree::Zone- end-- def scope_includes- [:zone_members]- end-- def resource_serializer- Spree.api.platform_zone_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/resource_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/resource_controller.rbdeleted file mode 100644index 598afc4cf2..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/resource_controller.rb+++ /dev/null@@ -1,79 +0,0 @@-module Spree- module Api- module V2- class ResourceController < ::Spree::Api::V2::BaseController- include Spree::Api::V2::CollectionOptionsHelpers- include Spree::Api::V2::Caching-- def index- render_serialized_payload do- Rails.cache.fetch(collection_cache_key(paginated_collection), collection_cache_opts) do- serialize_collection(paginated_collection)- end- end- end-- def show- render_serialized_payload { serialize_resource(resource) }- end-- protected-- def sorted_collection- @sorted_collection ||= collection_sorter.new(collection, params, allowed_sort_attributes).call- end-- def allowed_sort_attributes- default_sort_attributes- end-- def default_sort_attributes- [:id, :name, :slug, :number, :position, :updated_at, :created_at, :deleted_at]- end-- def scope(skip_cancancan: false)- base_scope = model_class.for_store(current_store)- base_scope = base_scope.accessible_by(current_ability, :show) unless skip_cancancan- base_scope = base_scope.includes(scope_includes) if scope_includes.any? && action_name == 'index'- model_class.include?(TranslatableResource) ? base_scope.i18n : base_scope- end-- def scope_includes- []- end-- def resource- @resource ||= if defined?(resource_finder)- resource_finder.new(scope: scope, params: finder_params).execute- else- scope.find(params[:id])- end- end-- def collection- @collection ||= begin- result = if defined?(collection_finder)- collection_finder.new(scope: scope, params: finder_params).execute- else- scope- end- result.preload_associations_lazily- end- end-- def finder_params- params.merge(- store: current_store,- locale: current_locale,- currency: current_currency,- user: spree_current_user- )- end-- def collection_sorter- Spree.api.storefront_collection_sorter- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/addresses_controller.rbdeleted file mode 100644index 0b09883460..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb+++ /dev/null@@ -1,77 +0,0 @@-module Spree- module Api- module V2- module Storefront- module Account- class AddressesController < ::Spree::Api::V2::ResourceController- include Spree::BaseHelper-- before_action :require_spree_current_user-- def create- spree_authorize! :create, model_class-- result = create_service.call(user: spree_current_user, address_params: address_params)- render_result(result)- end-- def update- spree_authorize! :update, resource-- result = update_service.call(address: resource, address_params: address_params)- render_result(result)- end-- def destroy- spree_authorize! :destroy, resource-- if resource.destroy- head 204- else- render_error_payload(resource.errors)- end- end-- private-- def collection- collection_finder.new(scope: scope, params: finder_params).execute- end-- def scope- super.where(user: spree_current_user, country: available_countries).not_deleted- end-- def model_class- Spree::Address- end-- def collection_finder- Spree.api.storefront_address_finder- end-- def collection_serializer- Spree.api.storefront_address_serializer- end-- def resource_serializer- Spree.api.storefront_address_serializer- end-- def create_service- Spree.api.storefront_address_create_service- end-- def update_service- Spree.api.storefront_address_update_service- end-- def address_params- params.require(:address).permit(permitted_address_attributes)- end- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rbdeleted file mode 100644index 159678cd3f..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb+++ /dev/null@@ -1,52 +0,0 @@-module Spree- module Api- module V2- module Storefront- module Account- class CreditCardsController < ::Spree::Api::V2::ResourceController- before_action :require_spree_current_user-- def destroy- spree_authorize! :destroy, resource, resource-- destroy_service.call(card: resource)- end-- private-- def resource- params[:id].eql?('default') ? scope.default.first! : scope.find(params[:id])- end-- def model_class- Spree::CreditCard- end-- def scope- super.not_expired.not_removed.where(- user: spree_current_user,- payment_method: current_store.payment_methods.available_on_front_end- )- end-- def collection_serializer- Spree.api.storefront_credit_card_serializer- end-- def collection_finder- Spree.api.storefront_credit_card_finder- end-- def resource_serializer- Spree.api.storefront_credit_card_serializer- end-- def destroy_service- Spree.api.storefront_credit_cards_destroy_service- end- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/orders_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/orders_controller.rbdeleted file mode 100644index 27609c73a8..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account/orders_controller.rb+++ /dev/null@@ -1,50 +0,0 @@-module Spree- module Api- module V2- module Storefront- module Account- class OrdersController < ::Spree::Api::V2::ResourceController- before_action :require_spree_current_user-- private-- def collection- collection_finder.new(user: spree_current_user, store: current_store).execute- end-- def resource- resource = resource_finder.new(user: spree_current_user, number: params[:id], store: current_store).execute.take- raise ActiveRecord::RecordNotFound if resource.nil?-- resource- end-- def allowed_sort_attributes- super << :completed_at- end-- def collection_serializer- Spree.api.storefront_order_serializer- end-- def resource_serializer- Spree.api.storefront_order_serializer- end-- def collection_finder- Spree.api.storefront_completed_order_finder- end-- def resource_finder- Spree.api.storefront_completed_order_finder- end-- def model_class- Spree::Order- end- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/account_controller.rbdeleted file mode 100644index 9225b2a94e..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/account_controller.rb+++ /dev/null@@ -1,52 +0,0 @@-module Spree- module Api- module V2- module Storefront- class AccountController < ::Spree::Api::V2::ResourceController- before_action :require_spree_current_user, except: :create-- def create- result = create_service.call(user_params: user_create_params)- render_result(result)- end-- def update- spree_authorize! :update, spree_current_user- result = update_service.call(user: spree_current_user, user_params: user_update_params)- render_result(result)- end-- private-- def resource- spree_current_user- end-- def resource_serializer- Spree.api.storefront_user_serializer- end-- def model_class- Spree.user_class- end-- def create_service- Spree.api.storefront_account_create_service- end-- def update_service- Spree.api.storefront_account_update_service- end-- def user_create_params- user_update_params.except(:bill_address_id, :ship_address_id)- end-- def user_update_params- params.require(:user).permit(permitted_user_attributes)- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/cart_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/cart_controller.rbdeleted file mode 100644index 008b5c1c79..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/cart_controller.rb+++ /dev/null@@ -1,246 +0,0 @@-module Spree- module Api- module V2- module Storefront- class CartController < ::Spree::Api::V2::BaseController- include OrderConcern- include CouponCodesHelper- include Spree::Api::V2::Storefront::MetadataControllerConcern-- before_action :ensure_valid_metadata, only: %i[create add_item]- before_action :ensure_order, except: %i[create associate]- before_action :load_variant, only: :add_item- before_action :require_spree_current_user, only: :associate-- def create- spree_authorize! :create, Spree::Order-- create_cart_params = {- user: spree_current_user,- store: current_store,- currency: current_currency,- public_metadata: add_item_params[:public_metadata],- private_metadata: add_item_params[:private_metadata],- }-- order = spree_current_order if spree_current_order.present?- order ||= create_service.call(create_cart_params).value-- render_serialized_payload(201) { serialize_resource(order) }- end-- def add_item- spree_authorize! :update, spree_current_order, order_token- spree_authorize! :show, @variant-- result = add_item_service.call(- order: spree_current_order,- variant: @variant,- quantity: add_item_params[:quantity],- public_metadata: add_item_params[:public_metadata],- private_metadata: add_item_params[:private_metadata],- options: add_item_params[:options]- )-- render_order(result)- end-- def remove_line_item- spree_authorize! :update, spree_current_order, order_token-- remove_line_item_service.call(- order: spree_current_order,- line_item: line_item- )-- render_serialized_payload { serialized_current_order }- end-- def empty- spree_authorize! :update, spree_current_order, order_token-- result = empty_cart_service.call(order: spree_current_order)-- if result.success?- render_serialized_payload { serialized_current_order }- else- render_error_payload(result.error)- end- end-- def destroy- spree_authorize! :update, spree_current_order, order_token-- result = destroy_cart_service.call(order: spree_current_order)-- if result.success?- head 204- else- render_error_payload(result.error)- end- end-- def set_quantity- return render_error_item_quantity unless params[:quantity].to_i > 0-- spree_authorize! :update, spree_current_order, order_token-- result = set_item_quantity_service.call(order: spree_current_order, line_item: line_item, quantity: params[:quantity])-- render_order(result)- end-- def show- spree_authorize! :show, spree_current_order, order_token-- render_serialized_payload { serialized_current_order }- end-- def apply_coupon_code- spree_authorize! :update, spree_current_order, order_token-- spree_current_order.coupon_code = params[:coupon_code]- result = coupon_handler.new(spree_current_order).apply-- if result.error.blank?- spree_current_order.reload- render_serialized_payload { serialized_current_order }- else- render_error_payload(result.error)- end- end-- def remove_coupon_code- spree_authorize! :update, spree_current_order, order_token-- coupon_codes = select_coupon_codes-- return render_error_payload(I18n.t('spree.api.v2.cart.no_coupon_code')) if coupon_codes.empty?-- result_errors = coupon_codes.count > 1 ? select_errors(coupon_codes) : select_error(coupon_codes)-- if result_errors.blank?- spree_current_order.reload- render_serialized_payload { serialized_current_order }- else- render_error_payload(result_errors)- end- end-- def estimate_shipping_rates- spree_authorize! :show, spree_current_order, order_token-- result = estimate_shipping_rates_service.call(order: spree_current_order, country_iso: params[:country_iso])-- if result.error.blank?- render_serialized_payload { serialize_estimated_shipping_rates(result.value) }- else- render_error_payload(result.error)- end- end-- def associate- guest_order_token = params[:guest_order_token]- guest_order = ::Spree.api.storefront_current_order_finder.new.execute(- store: current_store,- user: nil,- token: guest_order_token,- currency: current_currency- )-- spree_authorize! :update, guest_order, guest_order_token-- result = associate_service.call(guest_order: guest_order, user: spree_current_user)-- if result.success?- render_serialized_payload { serialize_resource(guest_order) }- else- render_error_payload(result.error)- end- end-- def change_currency- spree_authorize! :update, spree_current_order, order_token-- result = change_currency_service.call(order: spree_current_order, new_currency: params[:new_currency])-- render_order(result)- end-- private-- def resource_serializer- Spree.api.storefront_cart_serializer- end-- def create_service- Spree.api.storefront_cart_create_service- end-- def add_item_service- Spree.api.storefront_cart_add_item_service- end-- def empty_cart_service- Spree.api.storefront_cart_empty_service- end-- def destroy_cart_service- Spree.api.storefront_cart_destroy_service- end-- def set_item_quantity_service- Spree.api.storefront_cart_set_item_quantity_service- end-- def remove_line_item_service- Spree.api.storefront_cart_remove_line_item_service- end-- def coupon_handler- Spree.api.storefront_coupon_handler- end-- def estimate_shipping_rates_service- Spree.api.storefront_cart_estimate_shipping_rates_service- end-- def associate_service- Spree.api.storefront_cart_associate_service- end-- def change_currency_service- Spree.api.storefront_cart_change_currency_service- end-- def line_item- @line_item ||= spree_current_order.line_items.find(params[:line_item_id])- end-- def load_variant- @variant = current_store.variants.find(add_item_params[:variant_id])- end-- def render_error_item_quantity- render json: { error: I18n.t(:wrong_quantity, scope: 'spree.api.v2.cart') }, status: 422- end-- def estimate_shipping_rates_serializer- Spree.api.storefront_estimated_shipment_serializer- end-- def serialize_estimated_shipping_rates(shipping_rates)- estimate_shipping_rates_serializer.new(- shipping_rates,- params: serializer_params- ).serializable_hash- end-- def add_item_params- params.permit(:quantity, :variant_id, public_metadata: {}, private_metadata: {}, options: {})- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/checkout_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/checkout_controller.rbdeleted file mode 100644index d94e830479..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/checkout_controller.rb+++ /dev/null@@ -1,183 +0,0 @@-module Spree- module Api- module V2- module Storefront- class CheckoutController < ::Spree::Api::V2::BaseController- include Spree::Api::V2::Storefront::OrderConcern- before_action :ensure_order-- def next- spree_authorize! :update, spree_current_order, order_token-- result = next_service.call(order: spree_current_order)-- render_order(result)- end-- def advance- spree_authorize! :update, spree_current_order, order_token-- check_if_quick_checkout-- result = advance_service.call(order: spree_current_order, state: params[:state], shipping_method_id: params[:shipping_method_id])-- render_order(result)- end-- def complete- spree_authorize! :update, spree_current_order, order_token-- result = complete_service.call(order: spree_current_order)-- render_order(result)- end-- def update- spree_authorize! :update, spree_current_order, order_token-- result = update_service.call(- order: spree_current_order,- params: params,- # defined in https://github.com/spree/spree/blob/main/core/lib/spree/core/controller_helpers/strong_parameters.rb#L19- permitted_attributes: permitted_checkout_attributes,- request_env: request.headers.env- )-- render_order(result)- end-- def create_payment- result = create_payment_service.call(order: spree_current_order, params: params)-- if result.success?- render_serialized_payload(201) { serialize_resource(spree_current_order.reload) }- else- render_error_payload(result.error)- end- end-- def select_shipping_method- result = select_shipping_method_service.call(order: spree_current_order, params: params)-- render_order(result)- end-- def add_store_credit- spree_authorize! :update, spree_current_order, order_token-- result = add_store_credit_service.call(- order: spree_current_order,- amount: params[:amount].try(:to_f)- )-- render_order(result)- end-- def remove_store_credit- spree_authorize! :update, spree_current_order, order_token-- result = remove_store_credit_service.call(order: spree_current_order)- render_order(result)- end-- def shipping_rates- result = shipping_rates_service.call(order: spree_current_order)-- if result.success?- render_serialized_payload { serialize_shipping_rates(result.value) }- else- render_error_payload(result.error)- end- end-- def payment_methods- render_serialized_payload { serialize_payment_methods(spree_current_order.collect_frontend_payment_methods) }- end-- def validate_order_for_payment- messages = []-- if spree_current_order.present?- validated_order, messages = Spree::Cart::RemoveOutOfStockItems.call(order: spree_current_order).value- messages << Spree.t(:cart_state_changed) if !validated_order.payment? && params[:skip_state].blank?- end-- if messages.any?- render_serialized_payload(422) do- serialized_current_order.deep_merge({ meta: { messages: messages } })- end- else- render_serialized_payload { serialized_current_order }- end- end-- private-- def resource_serializer- Spree.api.storefront_cart_serializer- end-- def next_service- Spree.api.storefront_checkout_next_service- end-- def advance_service- Spree.api.storefront_checkout_advance_service- end-- def add_store_credit_service- Spree.api.storefront_checkout_add_store_credit_service- end-- def remove_store_credit_service- Spree.api.storefront_checkout_remove_store_credit_service- end-- def complete_service- Spree.api.storefront_checkout_complete_service- end-- def update_service- Spree.api.storefront_checkout_update_service- end-- def payment_methods_serializer- Spree.api.storefront_payment_method_serializer- end-- def shipping_rates_service- Spree.api.storefront_checkout_get_shipping_rates_service- end-- def shipping_rates_serializer- Spree.api.storefront_shipment_serializer- end-- def create_payment_service- Spree.api.storefront_payment_create_service- end-- def select_shipping_method_service- Spree.api.storefront_checkout_select_shipping_method_service- end-- def serialize_payment_methods(payment_methods)- payment_methods_serializer.new(payment_methods, params: serializer_params).serializable_hash- end-- def serialize_shipping_rates(shipments)- shipping_rates_serializer.new(- shipments,- params: serializer_params,- include: [:shipping_rates, :stock_location, :line_items]- ).serializable_hash- end-- def check_if_quick_checkout- spree_current_order.ship_address&.quick_checkout = params[:quick_checkout] if params[:quick_checkout]- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/countries_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/countries_controller.rbdeleted file mode 100644index 7b7b4b0146..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/countries_controller.rb+++ /dev/null@@ -1,57 +0,0 @@-module Spree- module Api- module V2- module Storefront- class CountriesController < ::Spree::Api::V2::ResourceController- before_action :set_default_per_page-- private-- def serialize_collection(collection)- collection_serializer.new(- collection,- collection_options(collection).merge(params: collection_serializer_params)- ).serializable_hash- end-- def serializer_params- super.merge(include_states: true)- end-- def collection_serializer_params- serializer_params.merge(include_states: false)- end-- def resource- return current_store.default_country if params[:iso] == 'default'-- scope.find_by(iso: params[:iso]&.upcase) ||- scope.find_by(id: params[:iso]&.upcase) ||- scope.find_by(iso3: params[:iso]&.upcase)- end-- def resource_serializer- Spree.api.storefront_country_serializer- end-- def collection_serializer- Spree.api.storefront_country_serializer- end-- def collection_finder- Spree.api.storefront_country_finder- end-- def model_class- Spree::Country- end-- # by default we want to return all countries on a single page- def set_default_per_page- params[:per_page] ||= Spree::Country.count- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/digitals_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/digitals_controller.rbdeleted file mode 100644index 773ebec8de..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/digitals_controller.rb+++ /dev/null@@ -1,58 +0,0 @@-module Spree- module Api- module V2- module Storefront- class DigitalsController < ::Spree::Api::V2::ResourceController- def download- if attachment.present?- if digital_link.authorize!- if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService)- # The asset is hosted on disk, use send_file.-- send_file(- ActiveStorage::Blob.service.path_for(attachment.key),- filename: attachment.filename.to_s,- type: attachment.content_type.to_s,- status: :ok- ) and return-- else- # The asset is hosted on a 3rd party service, use an expiring url with disposition: 'attachment'.-- redirect_to attachment.url(- expires_in: current_store.digital_asset_link_expire_time.seconds,- disposition: 'attachment',- host: digital_attachment_host- ) and return-- end- end- else- Rails.logger.error I18n.t('spree.api.v2.digitals.missing_file')- end-- render json: { error: I18n.t('spree.api.v2.digitals.unauthorized') }, status: 403- end-- private-- def model_class- Spree::Digital- end-- def digital_link- @digital_link ||= DigitalLink.find_by!(token: params[:token])- end-- def attachment- @attachment ||= digital_link.digital.try(:attachment) if digital_link.present?- end-- def digital_attachment_host- current_store.formatted_url- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/order_status_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/order_status_controller.rbdeleted file mode 100644index c6331cb97a..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/order_status_controller.rb+++ /dev/null@@ -1,34 +0,0 @@-module Spree- module Api- module V2- module Storefront- class OrderStatusController < ::Spree::Api::V2::ResourceController- include Spree::Api::V2::Storefront::OrderConcern-- before_action :ensure_order_token-- private-- def resource- resource = resource_finder.new(number: params[:number], token: order_token, store: current_store).execute.take- raise ActiveRecord::RecordNotFound if resource.nil?-- resource- end-- def resource_finder- Spree.api.storefront_completed_order_finder- end-- def resource_serializer- Spree.api.storefront_cart_serializer- end-- def ensure_order_token- raise ActiveRecord::RecordNotFound unless order_token.present?- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/policies_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/policies_controller.rbdeleted file mode 100644index 59f50f274f..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/policies_controller.rb+++ /dev/null@@ -1,31 +0,0 @@-module Spree- module Api- module V2- module Storefront- class PoliciesController < ::Spree::Api::V2::ResourceController- private-- def collection_serializer- Spree.api.storefront_policy_serializer- end-- def resource_serializer- Spree.api.storefront_policy_serializer- end-- def resource- @resource ||= find_with_fallback_default_locale { scope.find_by(slug: params[:id]) } || scope.find(params[:id])- end-- def model_class- Spree::Policy- end-- def scope_includes- [:rich_text_translations]- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/post_categories_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/post_categories_controller.rbdeleted file mode 100644index 7504b216ae..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/post_categories_controller.rb+++ /dev/null@@ -1,35 +0,0 @@-module Spree- module Api- module V2- module Storefront- class PostCategoriesController < ::Spree::Api::V2::ResourceController- protected-- def collection- @collection ||= scope- end-- def resource- @resource ||= find_with_fallback_default_locale { scope.friendly.find(params[:id]) } || scope.friendly.find(params[:id])- end-- def collection_serializer- Spree::V2::Storefront::PostCategorySerializer- end-- def resource_serializer- Spree::V2::Storefront::PostCategorySerializer- end-- def model_class- Spree::PostCategory- end-- def serializer_params- super.merge(include_posts: action_name == 'show')- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/posts_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/posts_controller.rbdeleted file mode 100644index d7502f62d6..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/posts_controller.rb+++ /dev/null@@ -1,51 +0,0 @@-module Spree- module Api- module V2- module Storefront- class PostsController < ::Spree::Api::V2::ResourceController- protected-- def sorted_collection- collection_sorter.new(collection, params, allowed_sort_attributes).call- end-- def collection- @collection ||= collection_finder.new(scope: scope, params: finder_params).execute- end-- def resource- @resource ||= find_with_fallback_default_locale { scope.friendly.find(params[:id]) } || scope.friendly.find(params[:id])- end-- def collection_finder- Spree.api.storefront_posts_finder- end-- def collection_sorter- Spree.api.storefront_posts_sorter- end-- def collection_serializer- Spree::V2::Storefront::PostSerializer- end-- def resource_serializer- Spree::V2::Storefront::PostSerializer- end-- def model_class- Spree::Post- end-- def scope- super.published.includes(:post_category, image_attachment: :blob)- end-- def allowed_sort_attributes- super << :published_at << :title- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/products_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/products_controller.rbdeleted file mode 100644index 8ecc3f7649..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/products_controller.rb+++ /dev/null@@ -1,66 +0,0 @@-module Spree- module Api- module V2- module Storefront- class ProductsController < ::Spree::Api::V2::ResourceController- include ::Spree::Api::V2::ProductListIncludes-- protected-- def sorted_collection- collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call- end-- def collection- @collection ||= collection_finder.new(scope: scope, params: finder_params).execute- end-- def resource- # using FriendlyId so old slugs still work- @resource ||= find_with_fallback_default_locale { scope.includes(variants: variant_includes, master: variant_includes).friendly.find(params[:id]) } || scope.includes(variants: variant_includes, master: variant_includes).friendly.find(params[:id])- end-- def variant_includes- [:images, :prices, { stock_items: :stock_location }]- end-- def collection_sorter- Spree.api.storefront_products_sorter- end-- def collection_finder- Spree.api.storefront_products_finder- end-- def collection_serializer- Spree.api.storefront_product_serializer- end-- def resource_serializer- Spree.api.storefront_product_serializer- end-- def model_class- Spree::Product- end-- def scope_includes- product_list_includes- end-- def allowed_sort_attributes- super << :available_on- end-- def collection_meta(collection)- super(collection).merge(filters: filters_meta)- end-- def filters_meta- Spree::Api::Products::FiltersPresenter.new(current_store, current_currency, params).to_h- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/stores_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/stores_controller.rbdeleted file mode 100644index 6729fcb5c5..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/stores_controller.rb+++ /dev/null@@ -1,27 +0,0 @@-module Spree- module Api- module V2- module Storefront- class StoresController < ::Spree::Api::V2::ResourceController- def current- render_serialized_payload { serialize_resource(current_store) }- end-- private-- def model_class- Spree::Store- end-- def resource- @resource ||= scope.find_by!(code: params[:code])- end-- def resource_serializer- Spree.api.storefront_store_serializer- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/taxons_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/taxons_controller.rbdeleted file mode 100644index 621d917463..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/taxons_controller.rb+++ /dev/null@@ -1,51 +0,0 @@-module Spree- module Api- module V2- module Storefront- class TaxonsController < ::Spree::Api::V2::ResourceController- private-- def collection_serializer- Spree.api.storefront_taxon_serializer- end-- def resource_serializer- Spree.api.storefront_taxon_serializer- end-- def collection_finder- Spree.api.storefront_taxon_finder- end-- def paginated_collection- @paginated_collection ||= collection_paginator.new(collection, params).call- end-- def resource- @resource ||= find_with_fallback_default_locale { scope.find_by(permalink: params[:id]) } || scope.find(params[:id])- end-- def model_class- Spree::Taxon- end-- def scope_includes- node_includes = %i[icon parent taxonomy translations]-- {- parent: node_includes,- children: node_includes,- taxonomy: [root: node_includes],- icon: [attachment_attachment: :blob],- translations: []- }- end-- def serializer_params- super.merge(include_products: action_name == 'show')- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/variants_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/variants_controller.rbdeleted file mode 100644index e5514145ce..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/variants_controller.rb+++ /dev/null@@ -1,41 +0,0 @@-module Spree- module Api- module V2- module Storefront- class VariantsController < ::Spree::Api::V2::ResourceController- private-- def model_class- Spree::Variant- end-- def scope- product_scope = Spree::Product.for_store(current_store)- product_scope = product_scope.accessible_by(current_ability, :show)- product_scope = product_scope.i18n if model_class.include?(TranslatableResource)-- product = product_scope.friendly.find(params[:id])- product.variants_including_master- end-- def collection_finder- Spree.api.storefront_variant_finder- end-- def collection_serializer- Spree.api.storefront_variant_serializer- end-- def scope_includes- variant_includes = {- prices: [],- option_values: :option_type,- }- variant_includes[:images] = [] if params[:include]&.match(/images/)- variant_includes- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/controllers/spree/api/v2/storefront/wishlists_controller.rb b/legacy_api_v2/app/controllers/spree/api/v2/storefront/wishlists_controller.rbdeleted file mode 100644index 869fab54fa..0000000000--- a/legacy_api_v2/app/controllers/spree/api/v2/storefront/wishlists_controller.rb+++ /dev/null@@ -1,214 +0,0 @@-module Spree- module Api- module V2- module Storefront- class WishlistsController < ::Spree::Api::V2::ResourceController- before_action :require_spree_current_user, except: [:show]- before_action :ensure_valid_quantity, only: [:add_item, :set_item_quantity]-- def show- spree_authorize! :show, resource- super- end-- def create- spree_authorize! :create, Spree::Wishlist-- @wishlist = spree_current_user.wishlists.new(wishlist_attributes)-- ensure_current_store(@wishlist)-- @wishlist.save-- if @wishlist.persisted?- render_serialized_payload(201) { serialize_resource(@wishlist) }- else- render_error_payload(@wishlist.errors.full_messages.to_sentence)- end- end-- def update- authorize! :update, resource-- resource.update wishlist_attributes-- if resource.errors.empty?- render_serialized_payload { serialize_resource(resource) }- else- render_error_payload(resource.errors.full_messages.to_sentence)- end- end-- def destroy- authorize! :destroy, resource-- if resource.destroy- head 204- else- render_error_payload(I18n.t('spree.api.v2.wishlist.errors.the_wishlist_could_not_be_destroyed'))- end- end-- def default- spree_authorize! :create, Spree::Wishlist-- @default_wishlist = spree_current_user.default_wishlist_for_store(current_store)-- render_serialized_payload { serialize_resource(@default_wishlist) }- end-- def add_item- spree_authorize! :create, Spree::WishedItem-- if resource.wished_items.present? && resource.wished_items.detect { |wv| wv.variant_id.to_s == params[:variant_id].to_s }.present?- @wished_item = resource.wished_items.detect { |wi| wi.variant_id.to_s == params[:variant_id].to_s }- @wished_item.quantity = params[:quantity]- else- @wished_item = Spree::WishedItem.new(params.permit(:quantity, :variant_id))- @wished_item.wishlist = resource- @wished_item.save- end-- resource.reload-- if @wished_item.persisted?- render_serialized_payload { serialize_wished_item(@wished_item) }- else- render_error_payload(resource.errors.full_messages.to_sentence)- end- end-- def set_item_quantity- spree_authorize! :update, wished_item-- wished_item.update(params.permit(:quantity))-- if wished_item.errors.empty?- render_serialized_payload { serialize_wished_item(wished_item) }- else- render_error_payload(resource.errors.full_messages.to_sentence)- end- end-- def remove_item- spree_authorize! :destroy, wished_item-- if wished_item.destroy- render_serialized_payload { serialize_wished_item(wished_item) }- else- render_error_payload(resource.errors.full_messages.to_sentence)- end- end-- def add_items- spree_authorize! :create, Spree::WishedItem-- @wished_items = resource.wished_items- ApplicationRecord.transaction do- wished_items_attributes.each do |wished_item_attributes|- wished_item = @wished_items.find_by(variant_id: wished_item_attributes[:variant_id])-- if wished_item- wished_item.update!(quantity: wished_item_attributes[:quantity] || 1)- else- Spree::WishedItem.create!(wished_item_attributes.merge(wishlist: resource))- end- end- end-- resource.reload- render_serialized_payload { serialize_resource(resource) }- rescue ActiveRecord::RecordInvalid => e- render json: { error: e.record.errors.full_messages.to_sentence }, status: 422- end-- def remove_items- spree_authorize! :destroy, Spree::WishedItem-- ApplicationRecord.transaction do- resource.wished_items.where(id: wished_items_ids).each(&:destroy!)- end-- resource.reload- render_serialized_payload { serialize_resource(resource) }- rescue ActiveRecord::RecordNotDestroyed => e- render json: { error: e.record.errors.full_messages.to_sentence }, status: 422- end-- private-- def scope(skip_cancancan: true)- if action_name == 'show'- super- else- super.where(user: spree_current_user)- end- end-- def resource- @resource ||= scope.find_by(token: params[:id])- end-- def model_class- Spree::Wishlist- end-- def resource_serializer- ::Spree::V2::Storefront::WishlistSerializer- end-- def collection_serializer- resource_serializer- end-- def wishlist_attributes- params.require(:wishlist).permit(permitted_wishlist_attributes)- end-- def wished_item_attributes- params.permit(permitted_wished_item_attributes)- end-- def wished_item- @wished_item ||= resource.wished_items.find(params[:item_id])- end-- def serialize_wished_item(wished_item)- ::Spree::V2::Storefront::WishedItemSerializer.new(- wished_item,- params: serializer_params,- include: resource_includes,- fields: sparse_fields- ).serializable_hash- end-- def serializer_params- super.merge(is_variant_included: params[:is_variant_included])- end-- def render_error_item_quantity- render json: { error: I18n.t('spree.api.v2.wishlist.wrong_quantity') }, status: 422- end-- def ensure_valid_quantity- return render_error_item_quantity if params[:quantity].present? && params[:quantity].to_i <= 0-- params[:quantity] = if params[:quantity].present?- params[:quantity].to_i- else- 1- end- end-- def wished_items_attributes- params.permit(wished_items: permitted_wished_item_attributes).require(:wished_items)- end-- def wished_items_ids- params.require(:wished_items_ids)- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/helpers/spree/api/v2/collection_options_helpers.rb b/legacy_api_v2/app/helpers/spree/api/v2/collection_options_helpers.rbdeleted file mode 100644index a39157739c..0000000000--- a/legacy_api_v2/app/helpers/spree/api/v2/collection_options_helpers.rb+++ /dev/null@@ -1,46 +0,0 @@-module Spree- module Api- module V2- module CollectionOptionsHelpers- def collection_links(collection)- {- self: request.original_url,- next: pagination_url(collection.next_page || collection.total_pages),- prev: pagination_url(collection.prev_page || 1),- last: pagination_url(collection.total_pages),- first: pagination_url(1)- }- end-- def collection_meta(collection)- {- count: collection.size,- total_count: collection.total_count,- total_pages: collection.total_pages- }- end-- # leaving this method in public scope so it's still possible to modify- # those params to support non-standard non-JSON API parameters- def collection_permitted_params- params.permit(:format, :page, :per_page, :sort, :include, :locale, fields: {}, filter: {})- end-- private-- def pagination_url(page)- url_for(collection_permitted_params.merge(page: page))- end-- def collection_options(collection)- {- links: collection_links(collection),- meta: collection_meta(collection),- include: resource_includes,- fields: sparse_fields- }- end- end- end- end-enddiff --git a/legacy_api_v2/app/helpers/spree/api/v2/display_money_helper.rb b/legacy_api_v2/app/helpers/spree/api/v2/display_money_helper.rbdeleted file mode 100644index 497da6b756..0000000000--- a/legacy_api_v2/app/helpers/spree/api/v2/display_money_helper.rb+++ /dev/null@@ -1,63 +0,0 @@-module Spree- module Api- module V2- module DisplayMoneyHelper- extend ActiveSupport::Concern-- class_methods do- def find_price(product_or_variant, currency, context_options = {})- variant = product_or_variant.is_a?(Spree::Product) ? product_or_variant.default_variant : product_or_variant-- if context_options.present?- context = build_pricing_context(variant, currency, context_options)- variant.price_for(context)- else- variant.price_in(currency)- end- end-- def price(product_or_variant, currency, context_options = {})- price = find_price(product_or_variant, currency, context_options)- return nil if price.new_record?-- price.amount- end-- def display_price(product_or_variant, currency, context_options = {})- price = find_price(product_or_variant, currency, context_options)- return nil if price.new_record?-- Spree::Money.new(price.amount, currency: currency).to_s- end-- def compare_at_price(product_or_variant, currency, context_options = {})- price = find_price(product_or_variant, currency, context_options)- return nil if price.new_record? || price.compare_at_amount.blank?-- price.compare_at_amount- end-- def display_compare_at_price(product_or_variant, currency, context_options = {})- price = find_price(product_or_variant, currency, context_options)- return nil if price.new_record? || price.compare_at_amount.blank?-- Spree::Money.new(price.compare_at_amount, currency: currency).to_s- end-- private-- def build_pricing_context(variant, currency, options)- Spree::Pricing::Context.new(- variant: variant,- currency: currency,- store: options[:store],- zone: options[:tax_zone] || options[:zone],- user: options[:user],- quantity: options[:quantity]- )- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb b/legacy_api_v2/app/helpers/spree/api/v2/store_media_serializer_images_concern.rbdeleted file mode 100644index 80da812016..0000000000--- a/legacy_api_v2/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb+++ /dev/null@@ -1,30 +0,0 @@-module Spree- module Api- module V2- module StoreMediaSerializerImagesConcern- extend ActiveSupport::Concern-- included do- def self.store_image_url_for(store, attribute_name)- attachment = store.send(attribute_name)- return unless attachment.attached?-- url_helpers.cdn_image_url(attachment)- end-- attribute :logo do |store|- store_image_url_for store, :logo- end-- attribute :mailer_logo do |store|- store_image_url_for store, :mailer_logo- end-- attribute :favicon_path do |store|- store_image_url_for store, :favicon_image- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/models/concerns/spree/user_api_authentication.rb b/legacy_api_v2/app/models/concerns/spree/user_api_authentication.rbdeleted file mode 100644index 600d5c107b..0000000000--- a/legacy_api_v2/app/models/concerns/spree/user_api_authentication.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module UserApiAuthentication- def generate_spree_api_key!- self.spree_api_key = generate_spree_api_key- save!- end-- def clear_spree_api_key!- self.spree_api_key = nil- save!- end-- private-- def generate_spree_api_key- SecureRandom.hex(24)- end- end-enddiff --git a/legacy_api_v2/app/models/concerns/spree/user_api_methods.rb b/legacy_api_v2/app/models/concerns/spree/user_api_methods.rbdeleted file mode 100644index 2f5f813d59..0000000000--- a/legacy_api_v2/app/models/concerns/spree/user_api_methods.rb+++ /dev/null@@ -1,7 +0,0 @@-module Spree- module UserApiMethods- extend ActiveSupport::Concern-- include Spree::UserApiAuthentication- end-enddiff --git a/legacy_api_v2/app/models/spree/oauth_access_grant.rb b/legacy_api_v2/app/models/spree/oauth_access_grant.rbdeleted file mode 100644index 7c98b5306d..0000000000--- a/legacy_api_v2/app/models/spree/oauth_access_grant.rb+++ /dev/null@@ -1,7 +0,0 @@-module Spree- class OauthAccessGrant < Spree.base_class- include ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessGrant-- self.table_name = 'spree_oauth_access_grants'- end-enddiff --git a/legacy_api_v2/app/models/spree/oauth_access_token.rb b/legacy_api_v2/app/models/spree/oauth_access_token.rbdeleted file mode 100644index 4370c254bf..0000000000--- a/legacy_api_v2/app/models/spree/oauth_access_token.rb+++ /dev/null@@ -1,7 +0,0 @@-module Spree- class OauthAccessToken < Spree.base_class- include ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessToken-- self.table_name = 'spree_oauth_access_tokens'- end-enddiff --git a/legacy_api_v2/app/models/spree/oauth_application.rb b/legacy_api_v2/app/models/spree/oauth_application.rbdeleted file mode 100644index 7775bd3938..0000000000--- a/legacy_api_v2/app/models/spree/oauth_application.rb+++ /dev/null@@ -1,22 +0,0 @@-module Spree- class OauthApplication < Spree.base_class- include ::Doorkeeper::Orm::ActiveRecord::Mixins::Application-- self.table_name = 'spree_oauth_applications'-- before_validation :set_blank_for_redirect_uri-- # returns the last someone used this application- #- # @return [DateTime]- def last_used_at- access_tokens.order(:created_at).last&.created_at- end-- private-- def set_blank_for_redirect_uri- self.redirect_uri = '' if redirect_uri.nil?- end- end-enddiff --git a/legacy_api_v2/app/paginators/spree/api/paginate.rb b/legacy_api_v2/app/paginators/spree/api/paginate.rbdeleted file mode 100644index 57cda4ff17..0000000000--- a/legacy_api_v2/app/paginators/spree/api/paginate.rb+++ /dev/null@@ -1,68 +0,0 @@-require 'pagy'--module Spree- module Api- class Paginate- include Pagy::Method-- def initialize(collection, params)- @collection = collection- @params = params-- per_page_limit = Spree::Api::Config[:api_v2_per_page_limit]- @per_page = if params[:per_page].to_i.between?(1, per_page_limit)- params[:per_page].to_i- else- 25- end- end-- def call- # Pass params as a hash-based request object for Pagy- # Pagy::Request accepts a hash with :params key- # Use to_unsafe_h for ActionController::Parameters, fallback to to_h for regular hashes- params_hash = @params.respond_to?(:to_unsafe_h) ? @params.to_unsafe_h : @params.to_h- request_hash = { params: params_hash }-- # Uses countish paginator which is faster as it avoids COUNT queries- pagy, records = pagy(:countish, @collection, limit: @per_page, request: request_hash)-- PagyCollection.new(records, pagy)- end- end-- # Wrapper providing Kaminari-compatible interface for CollectionOptionsHelpers- # Includes Enumerable so jsonapi-serializer detects it as a collection- class PagyCollection < SimpleDelegator- include Enumerable-- attr_reader :pagy-- def initialize(records, pagy)- super(records)- @pagy = pagy- end-- # Enumerable requires #each to be defined- def each(&block)- __getobj__.each(&block)- end-- def next_page- @pagy.next- end-- def prev_page- @pagy.previous- end-- def total_pages- @pagy.pages- end-- def total_count- @pagy.count- end- end- end-enddiff --git a/legacy_api_v2/app/presenters/spree/api/products/filters_presenter.rb b/legacy_api_v2/app/presenters/spree/api/products/filters_presenter.rbdeleted file mode 100644index 5541ceac27..0000000000--- a/legacy_api_v2/app/presenters/spree/api/products/filters_presenter.rb+++ /dev/null@@ -1,39 +0,0 @@-module Spree- module Api- module Products- class FiltersPresenter- def initialize(current_store, current_currency, params)- @products_for_filters = find_products_for_filters(current_store, current_currency, params)- end-- def to_h- option_values = Spree::OptionValues::FindAvailable.new(products_scope: products_for_filters).execute- option_values_presenters = Spree::Filters::OptionsPresenter.new(option_values_scope: option_values).to_a- product_properties = Spree::ProductProperties::FindAvailable.new(products_scope: products_for_filters).execute- product_properties_presenters = Spree::Filters::PropertiesPresenter.new(product_properties_scope: product_properties).to_a- {- option_types: option_values_presenters.map(&:to_h),- product_properties: product_properties_presenters.map(&:to_h)- }- end-- private-- attr_reader :products_for_filters-- def find_products_for_filters(current_store, current_currency, params)- current_taxons = find_current_taxons(current_store, params)- current_store.products.active(current_currency).in_taxons(current_taxons)- end-- def find_current_taxons(current_store, params)- taxons_param = params.dig(:filter, :taxons)- return nil if taxons_param.nil? || taxons_param.to_s.blank?-- taxon_ids = taxons_param.to_s.split(',')- current_store.taxons.where(id: taxon_ids)- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/concerns/spree/api/v2/image_transformation_concern.rb b/legacy_api_v2/app/serializers/concerns/spree/api/v2/image_transformation_concern.rbdeleted file mode 100644index ae5cd683cb..0000000000--- a/legacy_api_v2/app/serializers/concerns/spree/api/v2/image_transformation_concern.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module ImageTransformationConcern- extend ActiveSupport::Concern-- def self.included(base)- base.attribute :transformed_url do |image, params|- image.generate_url(size: params.dig(:image_transformation, :size))- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/concerns/spree/api/v2/public_metafields_concern.rb b/legacy_api_v2/app/serializers/concerns/spree/api/v2/public_metafields_concern.rbdeleted file mode 100644index b6916d429f..0000000000--- a/legacy_api_v2/app/serializers/concerns/spree/api/v2/public_metafields_concern.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module PublicMetafieldsConcern- extend ActiveSupport::Concern-- included do- has_many :metafields, serializer: Spree.api.storefront_metafield_serializer,- record_type: :metafield,- object_method_name: :public_metafields- end- end- end- end-end\ No newline at end of filediff --git a/legacy_api_v2/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb b/legacy_api_v2/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rbdeleted file mode 100644index d3ada95fdd..0000000000--- a/legacy_api_v2/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb+++ /dev/null@@ -1,42 +0,0 @@-module Spree- module Api- module V2- module ResourceSerializerConcern- extend ActiveSupport::Concern-- def self.included(base)- serializer_base_name = base.to_s.sub(/^Spree::Api::V2::Platform::/, '').sub(/Serializer$/, '')- model_klazz = "Spree::#{serializer_base_name}".constantize-- base.set_type model_klazz.json_api_type- # include standard attributes- base.attributes(*model_klazz.json_api_columns)- # include money attributes- display_getter_methods(model_klazz).each do |method_name|- base.attribute(method_name) do |object|- object.public_send(method_name).to_s- end- end-- metafield_enabled_resources = Spree::MetafieldDefinition.available_resources || []- if metafield_enabled_resources.map(&:name).include?(model_klazz.name) && model_klazz.method_defined?(:metafields)- base.has_many :metafields, serializer: Spree.api.platform_metafield_serializer,- record_type: :metafield,- object_method_name: :metafields- end- end-- def self.display_getter_methods(model_klazz)- model_klazz.new.methods.find_all do |method_name|- next if method_name.to_s.start_with?('display_on')- next unless method_name.to_s.start_with?('display_')- next if method_name.to_s.end_with?('=')- next if [Spree::Product, Spree::Variant].include?(model_klazz) && method_name == :display_amount-- method_name- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rb b/legacy_api_v2/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rbdeleted file mode 100644index e63787ae72..0000000000--- a/legacy_api_v2/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module TaxonImageTransformationConcern- extend ActiveSupport::Concern-- def self.included(base)- base.attribute :transformed_url do |image, params|- image.generate_url(size: params.dig(:taxon_image_transformation, :size))- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/base_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/base_serializer.rbdeleted file mode 100644index 7e04d8eb6b..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/base_serializer.rb+++ /dev/null@@ -1,43 +0,0 @@-module Spree- module Api- module V2- class BaseSerializer- include JSONAPI::Serializer-- # to learn more about caching, please refer to:- # https://github.com/jsonapi-serializer/jsonapi-serializer#caching- # https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching- cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: Spree::Api::Config[:api_v2_serializers_cache_ttl])-- def self.record_cache_options(options, fieldset, include_list, params)- opts = options.dup-- params_cache_key = params.map do |param|- value = param.last- next if param.nil? || value.nil?-- if value.respond_to?(:cache_key_with_version)- value.cache_key_with_version- elsif value.is_a?(Hash)- # covers the current_price_options cases:- # { price_options: { tax_zone: Spree::Zone... } } or- # { price_options: { tax_zone: nil } }- only_key = value.keys.first- value[only_key]&.cache_key_with_version- else- value.to_s.downcase- end- end.compact.reject(&:blank?).join('-')-- opts[:namespace] += "-#{params_cache_key}"-- super(opts, fieldset, include_list, params)- end-- def self.url_helpers- Rails.application.routes.url_helpers- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/address_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/address_serializer.rbdeleted file mode 100644index 068cfe8c28..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/address_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module Platform- class AddressSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :country, serializer: Spree.api.platform_country_serializer- belongs_to :state, serializer: Spree.api.platform_state_serializer- belongs_to :user, serializer: Spree.api.platform_user_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/adjustment_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/adjustment_serializer.rbdeleted file mode 100644index 999fc3e1ab..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/adjustment_serializer.rb+++ /dev/null@@ -1,20 +0,0 @@-module Spree- module Api- module V2- module Platform- class AdjustmentSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :adjustable, polymorphic: true- belongs_to :source, polymorphic: {- Spree::Promotion::Actions::FreeShipping => Spree.api.platform_promotion_action_serializer,- Spree::Promotion::Actions::CreateAdjustment => Spree.api.platform_promotion_action_serializer,- Spree::Promotion::Actions::CreateItemAdjustments => Spree.api.platform_promotion_action_serializer,- Spree::Promotion::Actions::CreateLineItems => Spree.api.platform_promotion_action_serializer- }- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/admin_user_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/admin_user_serializer.rbdeleted file mode 100644index 63bc74a7b4..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/admin_user_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class AdminUserSerializer < UserSerializer- set_type :admin_user- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/asset_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/asset_serializer.rbdeleted file mode 100644index e1f9b931ee..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/asset_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class AssetSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :viewable, polymorphic: true- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/base_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/base_serializer.rbdeleted file mode 100644index a6e22345f4..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/base_serializer.rb+++ /dev/null@@ -1,10 +0,0 @@-module Spree- module Api- module V2- module Platform- class BaseSerializer < ::Spree::Api::V2::BaseSerializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/calculator_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/calculator_serializer.rbdeleted file mode 100644index ef50a9e419..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/calculator_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class CalculatorSerializer < BaseSerializer- include ResourceSerializerConcern-- attributes :type-- attribute :preferences do |calculator|- calculator.preferences- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/classification_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/classification_serializer.rbdeleted file mode 100644index 6b7eed2d71..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/classification_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class ClassificationSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :product, serializer: Spree.api.platform_product_serializer- belongs_to :taxon, serializer: Spree.api.platform_taxon_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/country_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/country_serializer.rbdeleted file mode 100644index a14dffc198..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/country_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class CountrySerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :states, serializer: Spree.api.platform_state_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/credit_card_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/credit_card_serializer.rbdeleted file mode 100644index f506dc5155..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/credit_card_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class CreditCardSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :payment_method, serializer: Spree.api.platform_payment_method_serializer- belongs_to :user, serializer: Spree.api.platform_user_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/customer_return_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/customer_return_serializer.rbdeleted file mode 100644index 8fcbf3e7ce..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/customer_return_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class CustomerReturnSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :stock_location, serializer: Spree.api.platform_stock_location_serializer-- has_many :reimbursements, serializer: Spree.api.platform_reimbursement_serializer- has_many :return_items, serializer: Spree.api.platform_return_item_serializer- has_many :return_authorizations, serializer: Spree.api.platform_return_authorization_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/data_feed_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/data_feed_serializer.rbdeleted file mode 100644index f9404c5611..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/data_feed_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class DataFeedSerializer < BaseSerializer- set_type :data_feed-- attributes :name, :type, :slug, :active- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_link_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_link_serializer.rbdeleted file mode 100644index 906b3cf462..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_link_serializer.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module Api- module V2- module Platform- class DigitalLinkSerializer < BaseSerializer- set_type :digital_link-- attributes :token, :access_counter-- belongs_to :digital, serializer: Spree.api.platform_digital_serializer- belongs_to :line_item, serializer: Spree.api.platform_line_item_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_serializer.rbdeleted file mode 100644index 2eb43d8c67..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/digital_serializer.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module Api- module V2- module Platform- class DigitalSerializer < BaseSerializer- set_type :digital-- attribute :url do |digital|- url_helpers.polymorphic_url(digital.attachment, only_path: true)- end-- attribute :content_type do |digital|- digital.attachment.content_type.to_s- end-- attribute :filename do |digital|- digital.attachment.filename.to_s- end-- attribute :byte_size do |digital|- digital.attachment.byte_size.to_i- end-- belongs_to :variant, serializer: Spree.api.platform_variant_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/gift_card_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/gift_card_serializer.rbdeleted file mode 100644index 8d9c454811..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/gift_card_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class GiftCardSerializer < BaseSerializer- include ResourceSerializerConcern-- set_type :gift_card-- belongs_to :user, serializer: Spree.api.platform_user_serializer-- has_many :orders, serializer: Spree.api.platform_order_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/image_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/image_serializer.rbdeleted file mode 100644index 43f189cef2..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/image_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class ImageSerializer < BaseSerializer- include ::Spree::Api::V2::ImageTransformationConcern-- set_type :image-- attributes :styles, :position, :alt, :created_at, :updated_at, :original_url-- belongs_to :viewable, polymorphic: true- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rbdeleted file mode 100644index e72d66431c..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class InventoryUnitSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :variant, serializer: Spree.api.platform_variant_serializer- belongs_to :shipment, serializer: Spree.api.platform_shipment_serializer- has_many :return_items, serializer: Spree.api.platform_return_item_serializer- has_many :return_authorizations, serializer: Spree.api.platform_return_authorization_serializer- belongs_to :line_item, serializer: Spree.api.platform_line_item_serializer- belongs_to :original_return_item, serializer: Spree.api.platform_return_item_serializer, type: :return_item- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/line_item_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/line_item_serializer.rbdeleted file mode 100644index b2fd895dc4..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/line_item_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class LineItemSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :tax_category, serializer: Spree.api.platform_tax_category_serializer- belongs_to :variant, serializer: Spree.api.platform_variant_serializer-- has_many :adjustments, serializer: Spree.api.platform_adjustment_serializer- has_many :inventory_units, serializer: Spree.api.platform_inventory_unit_serializer- has_many :digital_links, serializer: Spree.api.platform_digital_link_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/log_entry_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/log_entry_serializer.rbdeleted file mode 100644index fe9d3dfe6a..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/log_entry_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class LogEntrySerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :source, polymorphic: true- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/metafield_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/metafield_serializer.rbdeleted file mode 100644index 790ba4b0ee..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/metafield_serializer.rb+++ /dev/null@@ -1,21 +0,0 @@-module Spree- module Api- module V2- module Platform- class MetafieldSerializer < BaseSerializer- set_type :metafield-- attributes :name, :type, :display_on-- attribute :key do |metafield|- metafield.full_key- end-- attribute :value do |metafield|- metafield.serialize_value- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/option_type_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/option_type_serializer.rbdeleted file mode 100644index 9f2e397f8c..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/option_type_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class OptionTypeSerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :option_values, serializer: Spree.api.platform_option_value_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/option_value_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/option_value_serializer.rbdeleted file mode 100644index bc1b083593..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/option_value_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class OptionValueSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :option_type, serializer: Spree.api.platform_option_type_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/order_promotion_serializer.rbdeleted file mode 100644index 421eb2b26b..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class OrderPromotionSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :promotion, serializer: Spree.api.platform_promotion_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/order_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/order_serializer.rbdeleted file mode 100644index 5cd09bceca..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/order_serializer.rb+++ /dev/null@@ -1,31 +0,0 @@-module Spree- module Api- module V2- module Platform- class OrderSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :user, serializer: Spree.api.platform_user_serializer- belongs_to :created_by, serializer: Spree.api.platform_admin_user_serializer- belongs_to :approver, serializer: Spree.api.platform_admin_user_serializer- belongs_to :canceler, serializer: Spree.api.platform_admin_user_serializer-- belongs_to :bill_address, serializer: Spree.api.platform_address_serializer- belongs_to :ship_address, serializer: Spree.api.platform_address_serializer-- has_many :line_items, serializer: Spree.api.platform_line_item_serializer- has_many :payments, serializer: Spree.api.platform_payment_serializer- has_many :shipments, serializer: Spree.api.platform_shipment_serializer-- has_many :state_changes, serializer: Spree.api.platform_state_change_serializer- has_many :return_authorizations, serializer: Spree.api.platform_return_authorization_serializer- has_many :reimbursements, serializer: Spree.api.platform_reimbursement_serializer- has_many :adjustments, serializer: Spree.api.platform_adjustment_serializer- has_many :all_adjustments, serializer: Spree.api.platform_adjustment_serializer, type: :adjustment-- has_many :order_promotions, serializer: Spree.api.platform_order_promotion_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rbdeleted file mode 100644index 572bb19ce3..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentCaptureEventSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :payment, serializer: Spree.api.platform_payment_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_method_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_method_serializer.rbdeleted file mode 100644index 8f74010cf1..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_method_serializer.rb+++ /dev/null@@ -1,18 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentMethodSerializer < BaseSerializer- attributes :name, :type, :description, :active, :display_on, :auto_capture, :position,- :created_at, :updated_at, :deleted_at, :public_metadata, :private_metadata-- attribute :preferences do |payment_method|- payment_method.preferences- end-- has_many :stores, serializer: Spree.api.platform_store_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_serializer.rbdeleted file mode 100644index 5e1bd1477d..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_serializer.rb+++ /dev/null@@ -1,22 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :payment_method, serializer: Spree.api.platform_payment_method_serializer- belongs_to :source, polymorphic: true, serializer: Spree.api.platform_payment_source_serializer-- has_many :log_entries, serializer: Spree.api.platform_log_entry_serializer- has_many :state_changes, serializer: Spree.api.platform_state_change_serializer- has_many :payment_capture_events, object_method_name: :capture_events,- id_method_name: :capture_event_ids,- serializer: Spree.api.platform_payment_capture_event_serializer- has_many :refunds, serializer: Spree.api.platform_refund_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_source_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_source_serializer.rbdeleted file mode 100644index b8a29cfefc..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/payment_source_serializer.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- module Api- module V2- module Platform- class PaymentSourceSerializer < BaseSerializer- belongs_to :payment_method, serializer: Spree.api.platform_payment_method_serializer- belongs_to :user, serializer: Spree.api.platform_user_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/price_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/price_serializer.rbdeleted file mode 100644index 3cc6657437..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/price_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class PriceSerializer < BaseSerializer- include ResourceSerializerConcern-- attribute :display_price_including_vat_for do |price, params|- price.display_price_including_vat_for(params[:price_options].presence || {}).to_s- end-- attribute :display_compare_at_price_including_vat_for do |price, params|- price.display_compare_at_price_including_vat_for(params[:price_options].presence || {}).to_s- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/product_property_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/product_property_serializer.rbdeleted file mode 100644index 1216e3ee5e..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/product_property_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class ProductPropertySerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/product_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/product_serializer.rbdeleted file mode 100644index f851b1e05f..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/product_serializer.rb+++ /dev/null@@ -1,90 +0,0 @@-module Spree- module Api- module V2- module Platform- class ProductSerializer < BaseSerializer- include ResourceSerializerConcern- include DisplayMoneyHelper-- attribute :purchasable do |product|- product.purchasable?- end-- attribute :in_stock do |product|- product.in_stock?- end-- attribute :backorderable do |product|- product.backorderable?- end-- attribute :available do |product|- product.available?- end-- attribute :currency do |_product, params|- params[:currency]- end-- attribute :price do |product, params|- price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_price do |product, params|- display_price(product, params[:currency], pricing_context_options(params))- end-- attribute :compare_at_price do |product, params|- compare_at_price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_compare_at_price do |product, params|- display_compare_at_price(product, params[:currency], pricing_context_options(params))- end-- def self.pricing_context_options(params)- {- store: params[:store],- user: params[:user],- tax_zone: params.dig(:price_options, :tax_zone)- }- end-- belongs_to :tax_category, serializer: Spree.api.platform_tax_category_serializer-- has_one :primary_variant,- object_method_name: :master,- id_method_name: :master_id,- record_type: :variant,- serializer: Spree.api.platform_variant_serializer-- has_one :default_variant,- object_method_name: :default_variant,- id_method_name: :default_variant_id,- record_type: :variant,- serializer: Spree.api.platform_variant_serializer-- has_many :variants, serializer: Spree.api.platform_variant_serializer- has_many :option_types, serializer: Spree.api.platform_option_type_serializer- has_many :product_properties, serializer: Spree.api.platform_product_property_serializer- has_many :taxons, serializer: Spree.api.platform_taxon_serializer, record_type: :taxon do |object, params|- if params[:store].present?- object.taxons_for_store(params[:store])- else- object.taxons- end- end-- has_many :images,- object_method_name: :variant_images,- id_method_name: :variant_image_ids,- record_type: :image,- serializer: Spree.api.platform_image_serializer-- # TODO: add stock items- # TODO: add prices- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rbdeleted file mode 100644index 42d9ba915c..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionActionLineItemSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :promotion_action, serializer: Spree.api.platform_promotion_action_serializer- belongs_to :variant, serializer: Spree.api.platform_variant_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_serializer.rbdeleted file mode 100644index d6a3e4d0c8..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionActionSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :promotion, serializer: Spree.api.platform_promotion_serializer-- # Some promotion actions have a :calculator, while others do not.- has_one :calculator, serializer: Spree.api.platform_calculator_serializer, if: proc { |record| record.respond_to?(:calculator) }-- # Only the CreateLineItems promotion action uses :promotion_action_line_items.- has_many :promotion_action_line_items, serializer: Spree.api.platform_promotion_action_line_item_serializer, if: proc { |record| record.respond_to?(:promotion_action_line_items) }- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_category_serializer.rbdeleted file mode 100644index 30b5778f4f..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionCategorySerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :promotions, serializer: Spree.api.platform_promotion_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rbdeleted file mode 100644index b43ea6a0a3..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb+++ /dev/null@@ -1,21 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionRuleSerializer < BaseSerializer- include ResourceSerializerConcern-- attribute :preferences do |promotion_rule|- promotion_rule.preferences- end-- belongs_to :promotion, serializer: Spree.api.platform_promotion_serializer-- has_many :products, through: :product_promotion_rules, serializer: Spree.api.platform_product_serializer, if: proc { |record| record.respond_to?(:product_promotion_rules) }- has_many :users, through: :promotion_rule_users, serializer: Spree.api.platform_user_serializer, if: proc { |record| record.respond_to?(:promotion_rule_users) }- has_many :taxons, through: :promotion_rule_taxons, serializer: Spree.api.platform_taxon_serializer, if: proc { |record| record.respond_to?(:promotion_rule_taxons) }- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_serializer.rbdeleted file mode 100644index a89934ef38..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/promotion_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class PromotionSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :promotion_category, serializer: Spree.api.platform_promotion_category_serializer-- has_many :promotion_rules, serializer: Spree.api.platform_promotion_rule_serializer- has_many :promotion_actions, serializer: Spree.api.platform_promotion_action_serializer- has_many :stores, serializer: Spree.api.platform_store_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/property_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/property_serializer.rbdeleted file mode 100644index ebf9767a77..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/property_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class PropertySerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/prototype_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/prototype_serializer.rbdeleted file mode 100644index 19a0e0c586..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/prototype_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module Platform- class PrototypeSerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :properties, serializer: Spree.api.platform_property_serializer- has_many :option_types, serializer: Spree.api.platform_option_type_serializer- has_many :taxons, serializer: Spree.api.platform_taxon_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_reason_serializer.rbdeleted file mode 100644index 8fb0c254cf..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class RefundReasonSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_serializer.rbdeleted file mode 100644index ac442fad73..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/refund_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class RefundSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :refunder, serializer: Spree.api.platform_admin_user_serializer- belongs_to :payment, serializer: Spree.api.platform_payment_serializer- belongs_to :reimbursement, serializer: Spree.api.platform_reimbursement_serializer- belongs_to :refund_reason, object_method_name: :reason, serializer: Spree.api.platform_refund_reason_serializer- has_many :log_entries, serializer: Spree.api.platform_log_entry_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rbdeleted file mode 100644index 8665a34244..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb+++ /dev/null@@ -1,10 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReimbursementCreditSerializer < BaseSerializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_serializer.rbdeleted file mode 100644index 2cd095b949..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReimbursementSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :customer_return, serializer: Spree.api.platform_customer_return_serializer- belongs_to :performed_by, serializer: Spree.api.platform_admin_user_serializer-- has_many :refunds, serializer: Spree.api.platform_refund_serializer- has_many :reimbursement_credits, object_method_name: :credits, id_method_name: :credit_ids, serializer: Spree.api.platform_reimbursement_credit_serializer- has_many :return_items, serializer: Spree.api.platform_return_item_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rbdeleted file mode 100644index c35e33d510..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReimbursementTypeSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rbdeleted file mode 100644index ca75b245b0..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReturnAuthorizationReasonSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_serializer.rbdeleted file mode 100644index fcdbcfcbf1..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReturnAuthorizationSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :stock_location, serializer: Spree.api.platform_stock_location_serializer- belongs_to :return_authorization_reason, object_method_name: :reason, serializer: Spree.api.platform_return_authorization_reason_serializer-- has_many :return_items, serializer: Spree.api.platform_return_item_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_item_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/return_item_serializer.rbdeleted file mode 100644index 260490f531..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/return_item_serializer.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module Api- module V2- module Platform- class ReturnItemSerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :exchange_inventory_units, serializer: Spree.api.platform_inventory_unit_serializer, type: :inventory_unit- belongs_to :exchange_variant, serializer: Spree.api.platform_variant_serializer, type: :variant- belongs_to :preferred_reimbursement_type, serializer: Spree.api.platform_reimbursement_type_serializer, type: :reimbursement_type- belongs_to :override_reimbursement_type, serializer: Spree.api.platform_reimbursement_type_serializer, type: :reimbursement_type- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/role_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/role_serializer.rbdeleted file mode 100644index b747813aa0..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/role_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class RoleSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipment_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/shipment_serializer.rbdeleted file mode 100644index 7e83090c03..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipment_serializer.rb+++ /dev/null@@ -1,22 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShipmentSerializer < BaseSerializer- include ResourceSerializerConcern-- attribute :tracking_url-- belongs_to :order, serializer: Spree.api.platform_order_serializer- belongs_to :address, serializer: Spree.api.platform_address_serializer- belongs_to :stock_location, serializer: Spree.api.platform_stock_location_serializer- has_many :adjustments, serializer: Spree.api.platform_adjustment_serializer- has_many :inventory_units, serializer: Spree.api.platform_inventory_unit_serializer- has_many :shipping_rates, serializer: Spree.api.platform_shipping_rate_serializer- has_many :state_changes, serializer: Spree.api.platform_state_change_serializer- has_one :selected_shipping_rate, serializer: Spree.api.platform_shipping_rate_serializer, type: :shipping_rate- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_category_serializer.rbdeleted file mode 100644index d2fa239cfa..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShippingCategorySerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_method_serializer.rbdeleted file mode 100644index fc58f0c331..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShippingMethodSerializer < BaseSerializer- attributes :name, :code, :admin_name, :display_on, :tracking_url, :created_at, :updated_at, :deleted_at, :public_metadata, :private_metadata-- has_many :shipping_categories, serializer: Spree.api.platform_shipping_category_serializer- has_many :shipping_rates, serializer: Spree.api.platform_shipping_rate_serializer- belongs_to :tax_category, serializer: Spree.api.platform_tax_category_serializer- has_one :calculator, serializer: Spree.api.platform_calculator_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rbdeleted file mode 100644index 1045010e54..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module Platform- class ShippingRateSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :shipment, serializer: Spree.api.platform_shipment_serializer- belongs_to :tax_rate, serializer: Spree.api.platform_tax_rate_serializer- belongs_to :shipping_method, serializer: Spree.api.platform_shipping_method_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/state_change_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/state_change_serializer.rbdeleted file mode 100644index 317eedcdbe..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/state_change_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class StateChangeSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :user, serializer: Spree.api.platform_user_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/state_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/state_serializer.rbdeleted file mode 100644index 9fd037d399..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/state_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class StateSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :country, serializer: Spree.api.platform_country_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_item_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_item_serializer.rbdeleted file mode 100644index d400b9a5d6..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_item_serializer.rb+++ /dev/null@@ -1,18 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockItemSerializer < BaseSerializer- include ResourceSerializerConcern-- attribute :is_available do |stock_item|- stock_item.available?- end-- belongs_to :stock_location, serializer: Spree.api.platform_stock_location_serializer- belongs_to :variant, serializer: Spree.api.platform_variant_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_location_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_location_serializer.rbdeleted file mode 100644index 94ae3dc40b..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_location_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockLocationSerializer < BaseSerializer- include ResourceSerializerConcern-- attributes :name- belongs_to :country, serializer: Spree.api.platform_country_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_movement_serializer.rbdeleted file mode 100644index 2d6b8d009d..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockMovementSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rbdeleted file mode 100644index 5efb6fa021..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module Platform- class StockTransferSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :destination_location, serializer: Spree.api.platform_stock_location_serializer- belongs_to :source_location, serializer: Spree.api.platform_stock_location_serializer- has_many :stock_movements, serializer: Spree.api.platform_stock_movement_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rbdeleted file mode 100644index 7acc1b5cdb..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditCategorySerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-end-diff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rbdeleted file mode 100644index 6fc0736c18..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditEventSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :store_credit, serializer: Spree.api.platform_store_credit_serializer- belongs_to :originator, polymorphic: true- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_serializer.rbdeleted file mode 100644index e39a4a7a69..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_serializer.rb+++ /dev/null@@ -1,18 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :user, serializer: Spree.api.platform_user_serializer- belongs_to :created_by, serializer: Spree.api.platform_admin_user_serializer- belongs_to :store_credit_category, object_method_name: :category, id_method_name: :category_id, serializer: Spree.api.platform_store_credit_category_serializer- belongs_to :store_credit_type, object_method_name: :credit_type, id_method_name: :type_id, serializer: Spree.api.platform_store_credit_type_serializer-- has_many :store_credit_events, serializer: Spree.api.platform_store_credit_event_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rbdeleted file mode 100644index 9dcf51eeeb..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreCreditTypeSerializer < BaseSerializer- include ResourceSerializerConcern- end- end- end- end-end-diff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/store_serializer.rbdeleted file mode 100644index c7cbc70da7..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/store_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class StoreSerializer < BaseSerializer- include ResourceSerializerConcern- include StoreMediaSerializerImagesConcern-- has_one :default_country, serializer: Spree.api.platform_country_serializer, record_type: :country, id_method_name: :default_country_id- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_category_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_category_serializer.rbdeleted file mode 100644index 42fcb75830..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_category_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxCategorySerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :tax_rates, serializer: Spree.api.platform_tax_rate_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_rate_serializer.rbdeleted file mode 100644index a9640349ce..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxRateSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :zone, serializer: Spree.api.platform_zone_serializer- belongs_to :tax_category, serializer: Spree.api.platform_tax_category_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_image_serializer.rbdeleted file mode 100644index 1337de1f21..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxonImageSerializer < BaseSerializer- include ::Spree::Api::V2::TaxonImageTransformationConcern-- set_type :taxon_image-- attributes :alt, :created_at, :updated_at, :original_url- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_serializer.rbdeleted file mode 100644index 0cb6338343..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxon_serializer.rb+++ /dev/null@@ -1,47 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxonSerializer < BaseSerializer- include ResourceSerializerConcern-- attributes :pretty_name, :seo_title-- attribute :description do |taxon|- taxon.description.to_plain_text- end-- attribute :header_url do |taxon|- url_helpers.cdn_image_url(taxon.image.attachment) if taxon.image.present? && taxon.image.attached?- end-- attribute :is_root do |taxon|- taxon.root?- end-- attribute :is_child do |taxon|- taxon.child?- end-- attribute :is_leaf do |taxon|- taxon.leaf?- end-- belongs_to :parent, record_type: :taxon, serializer: Spree.api.platform_taxon_serializer- belongs_to :taxonomy, record_type: :taxonomy, serializer: Spree.api.platform_taxonomy_serializer-- has_many :children, record_type: :taxon, serializer: Spree.api.platform_taxon_serializer- has_many :products, record_type: :product,- serializer: Spree.api.platform_product_serializer,- if: proc { |_taxon, params| params && params[:include_products] == true }-- has_one :image,- object_method_name: :icon,- id_method_name: :icon_id,- record_type: :taxon_image,- serializer: Spree.api.platform_taxon_image_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/taxonomy_serializer.rbdeleted file mode 100644index 15205de0a6..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-module Spree- module Api- module V2- module Platform- class TaxonomySerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :taxons, serializer: Spree.api.platform_taxon_serializer- has_one :root, serializer: Spree.api.platform_taxon_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/user_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/user_serializer.rbdeleted file mode 100644index 86f367bdb9..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/user_serializer.rb+++ /dev/null@@ -1,37 +0,0 @@-module Spree- module Api- module V2- module Platform- class UserSerializer < BaseSerializer- set_type :user-- attributes :email, :first_name, :last_name, :created_at, :updated_at, :public_metadata, :private_metadata, :selected_locale-- attribute :average_order_value do |user, params|- price_stats(user.report_values_for(:average_order_value, params[:store]))- end-- attribute :lifetime_value do |user, params|- price_stats(user.report_values_for(:lifetime_value, params[:store]))- end-- attribute :store_credits do |user, params|- price_stats(user.available_store_credits(params[:store]))- end-- has_one :bill_address,- record_type: :address,- serializer: Spree.api.platform_address_serializer-- has_one :ship_address,- record_type: :address,- serializer: Spree.api.platform_address_serializer-- def self.price_stats(stats)- stats.map { |value| { currency: value.currency.to_s, amount: value.money.to_s } }- end- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/variant_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/variant_serializer.rbdeleted file mode 100644index 0ea9e7cc94..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/variant_serializer.rb+++ /dev/null@@ -1,66 +0,0 @@-module Spree- module Api- module V2- module Platform- class VariantSerializer < BaseSerializer- include ResourceSerializerConcern- include DisplayMoneyHelper-- attributes :name, :options_text, :total_on_hand-- attribute :purchasable do |product|- product.purchasable?- end-- attribute :in_stock do |product|- product.in_stock?- end-- attribute :backorderable do |product|- product.backorderable?- end-- attribute :available do |product|- product.available?- end-- attribute :currency do |_product, params|- params[:currency]- end-- attribute :price do |object, params|- price(object, params[:currency], pricing_context_options(params))- end-- attribute :display_price do |object, params|- display_price(object, params[:currency], pricing_context_options(params))- end-- attribute :compare_at_price do |object, params|- compare_at_price(object, params[:currency], pricing_context_options(params))- end-- attribute :display_compare_at_price do |object, params|- display_compare_at_price(object, params[:currency], pricing_context_options(params))- end-- def self.pricing_context_options(params)- {- store: params[:store],- user: params[:user],- tax_zone: params.dig(:price_options, :tax_zone)- }- end-- belongs_to :product, serializer: Spree.api.platform_product_serializer- belongs_to :tax_category, serializer: Spree.api.platform_tax_category_serializer- has_many :digitals, serializer: Spree.api.platform_digital_serializer- has_many :images, serializer: Spree.api.platform_image_serializer- has_many :option_values, serializer: Spree.api.platform_option_value_serializer- has_many :stock_items, serializer: Spree.api.platform_stock_item_serializer- has_many :stock_locations, serializer: Spree.api.platform_stock_location_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/wished_item_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/wished_item_serializer.rbdeleted file mode 100644index 907faab934..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/wished_item_serializer.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module Api- module V2- module Platform- class WishedItemSerializer < BaseSerializer- include ResourceSerializerConcern-- attribute :price do |wished_item, params|- wished_item.price(currency: params[:currency])- end-- attribute :total do |wished_item, params|- wished_item.total(currency: params[:currency])- end-- attribute :display_price do |wished_item, params|- wished_item.display_price(currency: params[:currency]).to_s- end-- attribute :display_total do |wished_item, params|- wished_item.display_total(currency: params[:currency]).to_s- end-- belongs_to :variant, serializer: Spree.api.platform_variant_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/wishlist_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/wishlist_serializer.rbdeleted file mode 100644index 00a3254c24..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/wishlist_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module Api- module V2- module Platform- class WishlistSerializer < BaseSerializer- include ResourceSerializerConcern-- attributes :token-- attribute :variant_included do |wishlist, params|- wishlist.include?(params[:is_variant_included])- end-- has_many :wished_items, serializer: Spree.api.platform_wished_item_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_member_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_member_serializer.rbdeleted file mode 100644index 6ca7f1050b..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_member_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class ZoneMemberSerializer < BaseSerializer- include ResourceSerializerConcern-- belongs_to :zoneable, polymorphic: true- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_serializer.rb b/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_serializer.rbdeleted file mode 100644index 67f372fdd2..0000000000--- a/legacy_api_v2/app/serializers/spree/api/v2/platform/zone_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module Api- module V2- module Platform- class ZoneSerializer < BaseSerializer- include ResourceSerializerConcern-- has_many :zone_members, serializer: Spree.api.platform_zone_member_serializer- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/address_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/address_serializer.rbdeleted file mode 100644index 64925660aa..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/address_serializer.rb+++ /dev/null@@ -1,22 +0,0 @@-module Spree- module V2- module Storefront- class AddressSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :address-- attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :state_name,- :company, :country_name, :country_iso3, :country_iso, :label, :public_metadata-- attribute :state_code do |address|- address.state_abbr- end-- attribute :state_name do |address|- address.state_name_text- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/base_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/base_serializer.rbdeleted file mode 100644index 34626bc544..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/base_serializer.rb+++ /dev/null@@ -1,10 +0,0 @@-require 'active_support/cache'--module Spree- module V2- module Storefront- class BaseSerializer < ::Spree::Api::V2::BaseSerializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/cart_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/cart_serializer.rbdeleted file mode 100644index d2ba10b509..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/cart_serializer.rb+++ /dev/null@@ -1,67 +0,0 @@-module Spree- module V2- module Storefront- class CartSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :cart-- attributes :number, :item_total, :total, :ship_total, :adjustment_total, :created_at,- :updated_at, :completed_at, :included_tax_total, :additional_tax_total, :display_additional_tax_total,- :display_included_tax_total, :tax_total, :currency, :state, :token, :email,- :display_item_total, :display_ship_total, :display_adjustment_total, :display_tax_total,- :promo_total, :display_promo_total, :item_count, :special_instructions, :display_total,- :pre_tax_item_amount, :display_pre_tax_item_amount, :pre_tax_total, :display_pre_tax_total,- :shipment_state, :payment_state, :public_metadata, :total_minus_store_credits, :display_total_minus_store_credits-- attribute :subtotal_cents do |cart|- cart.display_item_total.amount_in_cents- end-- attribute :ship_total_cents do |cart|- cart.display_ship_total.amount_in_cents- end-- attribute :store_credit_total_cents do |cart|- cart.display_total_applied_store_credit.abs.amount_in_cents- end-- attribute :promo_total_cents do |cart|- cart.display_promo_total.abs.amount_in_cents- end-- attribute :tax_total_cents do |cart|- cart.display_tax_total.amount_in_cents- end-- attribute :total_cents do |cart|- cart.display_total.amount_in_cents- end-- attribute :total_minus_store_credits_cents do |cart|- cart.display_total_minus_store_credits.amount_in_cents- end-- has_many :line_items, serializer: Spree.api.storefront_line_item_serializer- has_many :variants, serializer: Spree.api.storefront_variant_serializer- has_many :promotions, serializer: Spree.api.storefront_order_promotion_serializer, object_method_name: :valid_promotions, id_method_name: :valid_promotion_ids- has_many :payments, serializer: Spree.api.storefront_payment_serializer do |cart|- cart.payments.valid- end- has_many :shipments, serializer: Spree.api.storefront_shipment_serializer-- belongs_to :user, serializer: Spree.api.storefront_user_serializer- belongs_to :billing_address,- id_method_name: :bill_address_id,- serializer: Spree.api.storefront_address_serializer,- record_type: :address-- belongs_to :shipping_address,- id_method_name: :ship_address_id,- serializer: Spree.api.storefront_address_serializer,- record_type: :address- belongs_to :gift_card, serializer: Spree.api.storefront_gift_card_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/country_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/country_serializer.rbdeleted file mode 100644index feab0eb82a..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/country_serializer.rb+++ /dev/null@@ -1,24 +0,0 @@-module Spree- module V2- module Storefront- class CountrySerializer < BaseSerializer- set_type :country-- attributes :iso, :iso3, :iso_name, :name, :states_required,- :zipcode_required-- attribute :default do |object, params|- object.default?(params[:store])- end-- has_many :states, if: proc { |_record, params| params && params[:include_states] }-- has_many :checkout_zone_applicable_states,- serializer: ::Spree::V2::Storefront::StateSerializer,- if: proc { |_record, params| params && params[:store].present? } do |object, params|- params[:store].states_available_for_checkout(object)- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/credit_card_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/credit_card_serializer.rbdeleted file mode 100644index 8699da6f92..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/credit_card_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module V2- module Storefront- class CreditCardSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :credit_card-- attributes :cc_type, :last_digits, :month, :year, :name, :default, :gateway_payment_profile_id, :public_metadata-- belongs_to :payment_method, serializer: Spree.api.storefront_payment_method_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/digital_link_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/digital_link_serializer.rbdeleted file mode 100644index 1297e2a37b..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/digital_link_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class DigitalLinkSerializer < BaseSerializer- set_type :digital_link-- attribute :token- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rbdeleted file mode 100644index d30d4d9bd2..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb+++ /dev/null@@ -1,35 +0,0 @@-module Spree- module V2- module Storefront- class EstimatedShippingRateSerializer < BaseSerializer- set_type :shipping_rate-- cache_options store: nil-- attributes :name, :selected, :cost, :tax_amount-- attribute :shipping_method_id do |shipping_rate|- shipping_rate.shipping_method_id.to_s- end-- belongs_to :shipping_method, serializer: Spree.api.storefront_shipping_method_serializer-- attribute :final_price do |shipping_rate|- shipping_rate.cost- end-- attributes :display_cost, :display_final_price do |object, params|- Spree::Money.new(object.cost, currency: params[:currency]).to_s- end-- attribute :display_tax_amount do |object, params|- Spree::Money.new(object.tax_amount, currency: params[:currency]).to_s- end-- attribute :free do |object|- object.cost.zero?- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/gift_card_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/gift_card_serializer.rbdeleted file mode 100644index 962039874f..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/gift_card_serializer.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module V2- module Storefront- class GiftCardSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :gift_card-- attributes :amount, :amount_used, :amount_remaining, :display_amount, :display_amount_used,- :display_amount_remaining, :expires_at-- attribute :code, &:display_code- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/image_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/image_serializer.rbdeleted file mode 100644index 6326cad449..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/image_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module V2- module Storefront- class ImageSerializer < BaseSerializer- include ::Spree::Api::V2::ImageTransformationConcern-- set_type :image-- attributes :styles, :position, :alt, :original_url- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/line_item_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/line_item_serializer.rbdeleted file mode 100644index de6e790151..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/line_item_serializer.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module V2- module Storefront- class LineItemSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :line_item-- attributes :name, :quantity, :price, :slug, :options_text, :currency,- :display_price, :total, :display_total, :adjustment_total,- :display_adjustment_total, :additional_tax_total,- :discounted_amount, :display_discounted_amount,- :display_additional_tax_total, :promo_total, :display_promo_total,- :included_tax_total, :display_included_tax_total,- :pre_tax_amount, :display_pre_tax_amount, :compare_at_amount, :display_compare_at_amount,- :public_metadata-- belongs_to :variant, serializer: Spree.api.storefront_variant_serializer- has_many :digital_links, serializer: Spree.api.storefront_digital_link_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/metafield_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/metafield_serializer.rbdeleted file mode 100644index 80ea4e3f0c..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/metafield_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module V2- module Storefront- class MetafieldSerializer < BaseSerializer- set_type :metafield-- attributes :name, :type-- attribute :key do |metafield|- metafield.full_key- end-- attribute :value do |metafield|- metafield.serialize_value- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/option_type_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/option_type_serializer.rbdeleted file mode 100644index e2525ea964..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/option_type_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module V2- module Storefront- class OptionTypeSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :option_type-- attributes :name, :presentation, :position, :public_metadata-- has_many :option_values, serializer: Spree.api.storefront_option_value_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/option_value_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/option_value_serializer.rbdeleted file mode 100644index 372efb7e41..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/option_value_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module V2- module Storefront- class OptionValueSerializer < BaseSerializer- set_type :option_value-- attributes :name, :presentation, :position, :public_metadata-- belongs_to :option_type, serializer: Spree.api.storefront_option_type_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/order_promotion_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/order_promotion_serializer.rbdeleted file mode 100644index f0cb724817..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/order_promotion_serializer.rb+++ /dev/null@@ -1,14 +0,0 @@-# this is actually a serializer for Spree::OrderPromotion, not Spree::Promotion-# we should fix this in the future-module Spree- module V2- module Storefront- class OrderPromotionSerializer < BaseSerializer- set_id :promotion_id- set_type :promotion-- attributes :name, :description, :amount, :display_amount, :code, :public_metadata- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/order_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/order_serializer.rbdeleted file mode 100644index 52f1cc3784..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/order_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class OrderSerializer < CartSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :order- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_method_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/payment_method_serializer.rbdeleted file mode 100644index 26a8cad9f6..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_method_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module V2- module Storefront- class PaymentMethodSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :payment_method-- attributes :type, :name, :description, :public_metadata-- attribute :preferences do |object|- object.public_preferences.as_json- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/payment_serializer.rbdeleted file mode 100644index 910cf3b468..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_serializer.rb+++ /dev/null@@ -1,20 +0,0 @@-module Spree- module V2- module Storefront- class PaymentSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :payment-- has_one :source, polymorphic: true- has_one :payment_method, serializer: Spree.api.storefront_payment_method_serializer-- attributes :amount, :response_code, :number, :cvv_response_code, :cvv_response_message, :payment_method_name, :state, :public_metadata-- attribute :payment_method_id do |payment|- payment.payment_method_id&.to_s- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_source_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/payment_source_serializer.rbdeleted file mode 100644index 10fdf6cdd6..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/payment_source_serializer.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- module V2- module Storefront- class PaymentSourceSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- belongs_to :payment_method, serializer: Spree.api.storefront_payment_method_serializer- belongs_to :user, serializer: Spree.api.storefront_user_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/policy_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/policy_serializer.rbdeleted file mode 100644index 59a5694d24..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/policy_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module V2- module Storefront- class PolicySerializer < BaseSerializer- set_type :policy-- attributes :name, :slug, :created_at, :updated_at-- attribute :body do |object|- object.body.to_plain_text- end-- attribute :body_html do |object|- object.body.to_s- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/post_category_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/post_category_serializer.rbdeleted file mode 100644index 141ee0c0ca..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/post_category_serializer.rb+++ /dev/null@@ -1,23 +0,0 @@-module Spree- module V2- module Storefront- class PostCategorySerializer < ::Spree::Api::V2::BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :post_category-- attributes :title, :slug, :created_at, :updated_at-- attribute :description do |category|- category.description.to_plain_text if category.description.present?- end-- has_many :posts, serializer: Spree.api.storefront_post_serializer, record_type: :post, if: proc { |_record, params|- params[:include_posts] == true- } do |category|- category.posts.published.by_newest- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/post_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/post_serializer.rbdeleted file mode 100644index 4abf49e7ec..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/post_serializer.rb+++ /dev/null@@ -1,51 +0,0 @@-module Spree- module V2- module Storefront- class PostSerializer < ::Spree::Api::V2::BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :post-- attributes :title, :slug, :published_at, :meta_title, :meta_description, :created_at, :updated_at-- attribute :excerpt do |post|- post.excerpt.to_plain_text if post.excerpt.present?- end-- attribute :content do |post|- post.content.to_plain_text if post.content.present?- end-- attribute :content_html do |post|- post.content.to_s if post.content.present?- end-- attribute :description do |post|- post.description- end-- attribute :shortened_description do |post|- post.shortened_description- end-- attribute :author_name do |post|- post.author_name- end-- attribute :post_category_title do |post|- post.post_category_title- end-- attribute :tags do |post|- post.tag_list- end-- attribute :image_url do |post, params|- url_helpers.cdn_image_url(post.image.attachment) if post.image.present? && post.image.attached?- end-- belongs_to :post_category, serializer: Spree.api.storefront_post_category_serializer, record_type: :post_category- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/product_property_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/product_property_serializer.rbdeleted file mode 100644index 2272e936ff..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/product_property_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module V2- module Storefront- class ProductPropertySerializer < BaseSerializer- set_type :product_property-- attribute :value, :filter_param, :show_property, :position-- attribute :name do |product_property|- product_property.property_name- end-- attribute :description do |product_property|- product_property.property_presentation- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/product_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/product_serializer.rbdeleted file mode 100644index aaaece4d42..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/product_serializer.rb+++ /dev/null@@ -1,92 +0,0 @@-module Spree- module V2- module Storefront- class ProductSerializer < BaseSerializer- include ::Spree::Api::V2::DisplayMoneyHelper- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :product-- attributes :name, :description, :available_on, :slug, :meta_description, :meta_keywords, :updated_at, :sku, :barcode, :public_metadata-- attribute :purchasable do |product|- product.purchasable?- end-- attribute :in_stock do |product|- product.in_stock?- end-- attribute :backorderable do |product|- product.backorderable?- end-- attribute :available do |product|- product.available?- end-- attribute :currency do |_product, params|- params[:currency]- end-- attribute :price do |product, params|- price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_price do |product, params|- display_price(product, params[:currency], pricing_context_options(params))- end-- attribute :compare_at_price do |product, params|- compare_at_price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_compare_at_price do |product, params|- display_compare_at_price(product, params[:currency], pricing_context_options(params))- end-- def self.pricing_context_options(params)- {- store: params[:store],- user: params[:user],- tax_zone: params.dig(:price_options, :tax_zone)- }- end-- attribute :localized_slugs do |product, params|- product.localized_slugs_for_store(params[:store])- end-- attribute :tags, &:tag_list- attribute :labels, &:label_list-- has_many :variants, serializer: Spree.api.storefront_variant_serializer- has_many :option_types, serializer: Spree.api.storefront_option_type_serializer- has_many :product_properties, serializer: Spree.api.storefront_product_property_serializer-- has_many :taxons, serializer: Spree.api.storefront_taxon_serializer, record_type: :taxon do |object, params|- object.taxons_for_store(params[:store])- end-- # all images from all variants- has_many :images,- object_method_name: :variant_images,- id_method_name: :variant_image_ids,- record_type: :image,- serializer: Spree.api.storefront_image_serializer-- has_one :default_variant,- object_method_name: :default_variant,- id_method_name: :default_variant_id,- record_type: :variant,- serializer: Spree.api.storefront_variant_serializer-- has_one :primary_variant,- object_method_name: :master,- id_method_name: :master_id,- record_type: :variant,- serializer: Spree.api.storefront_variant_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/shipment_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/shipment_serializer.rbdeleted file mode 100644index 1b33439526..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/shipment_serializer.rb+++ /dev/null@@ -1,26 +0,0 @@-module Spree- module V2- module Storefront- class ShipmentSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :shipment-- attributes :number, :final_price, :display_final_price,- :state, :shipped_at, :tracking_url, :public_metadata-- attribute :free do |shipment|- shipment.free?- end-- has_many :shipping_rates, serializer: Spree.api.storefront_shipping_rate_serializer- has_one :selected_shipping_rate, serializer: Spree.api.storefront_shipping_rate_serializer-- belongs_to :stock_location, serializer: Spree.api.storefront_stock_location_serializer- has_many :line_items, serializer: Spree.api.storefront_line_item_serializer do |shipment|- shipment.line_items- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_category_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_category_serializer.rbdeleted file mode 100644index f86af4efeb..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_category_serializer.rb+++ /dev/null@@ -1,10 +0,0 @@-module Spree- module V2- module Storefront- class ShippingCategorySerializer < BaseSerializer- set_type :shipping_category- attribute :name- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_method_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_method_serializer.rbdeleted file mode 100644index b152c38968..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_method_serializer.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- module V2- module Storefront- class ShippingMethodSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :shipping_method- attributes :name, :public_metadata- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_rate_serializer.rbdeleted file mode 100644index 790c92231c..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb+++ /dev/null@@ -1,26 +0,0 @@-module Spree- module V2- module Storefront- class ShippingRateSerializer < BaseSerializer- set_type :shipping_rate-- attributes :name, :selected, :final_price, :display_final_price, :cost,- :display_cost, :tax_amount, :display_tax_amount-- attribute :shipping_method_id do |shipping_rate|- shipping_rate.shipping_method_id.to_s- end-- belongs_to :shipping_method, serializer: Spree.api.storefront_shipping_method_serializer-- attribute :free do |shipping_rate|- shipping_rate.free?- end-- attribute :final_price_cents do |shipping_rate|- shipping_rate.display_final_price.cents- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/state_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/state_serializer.rbdeleted file mode 100644index 06d5b588ff..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/state_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class StateSerializer < BaseSerializer- set_type :state-- attributes :abbr, :name- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/stock_location_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/stock_location_serializer.rbdeleted file mode 100644index 4eaa967491..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/stock_location_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class StockLocationSerializer < BaseSerializer- set_type :stock_location-- attributes :name- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_category_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_category_serializer.rbdeleted file mode 100644index 1cb76704f6..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_category_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class StoreCreditCategorySerializer < BaseSerializer- set_type :store_credit_category-- attributes :name- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_event_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_event_serializer.rbdeleted file mode 100644index e8c34d8008..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_event_serializer.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- module V2- module Storefront- class StoreCreditEventSerializer < BaseSerializer- set_type :store_credit_event-- attributes :action, :amount, :user_total_amount, :created_at-- attribute :order_number do |object|- object.order&.number- end- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_serializer.rbdeleted file mode 100644index ea158cf42d..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_serializer.rb+++ /dev/null@@ -1,19 +0,0 @@-module Spree- module V2- module Storefront- class StoreCreditSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :store_credit-- belongs_to :category, serializer: Spree.api.storefront_store_credit_category_serializer- has_many :store_credit_events, serializer: Spree.api.storefront_store_credit_event_serializer- belongs_to :credit_type,- id_method_name: :type_id,- serializer: Spree.api.storefront_store_credit_type_serializer-- attributes :amount, :amount_used, :created_at, :public_metadata- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_type_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_type_serializer.rbdeleted file mode 100644index 3cb4745a2a..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/store_credit_type_serializer.rb+++ /dev/null@@ -1,11 +0,0 @@-module Spree- module V2- module Storefront- class StoreCreditTypeSerializer < BaseSerializer- set_type :store_credit_type-- attributes :name- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/store_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/store_serializer.rbdeleted file mode 100644index 72c7f37617..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/store_serializer.rb+++ /dev/null@@ -1,18 +0,0 @@-module Spree- module V2- module Storefront- class StoreSerializer < BaseSerializer- include Spree::Api::V2::StoreMediaSerializerImagesConcern- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :store-- attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency,- :default, :supported_currencies, :facebook, :twitter, :instagram, :default_locale,- :customer_support_email, :description, :address, :contact_phone, :supported_locales-- has_one :default_country, serializer: Spree.api.storefront_country_serializer, record_type: :country, id_method_name: :default_country_id- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_image_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_image_serializer.rbdeleted file mode 100644index 677b5505a2..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_image_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module V2- module Storefront- class TaxonImageSerializer < BaseSerializer- include ::Spree::Api::V2::TaxonImageTransformationConcern-- set_type :taxon_image-- attributes :styles, :alt, :original_url- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_serializer.rbdeleted file mode 100644index 2356d9fec0..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/taxon_serializer.rb+++ /dev/null@@ -1,55 +0,0 @@-module Spree- module V2- module Storefront- class TaxonSerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :taxon-- attributes :name, :pretty_name, :permalink, :seo_title, :meta_title, :meta_description,- :meta_keywords, :left, :right, :position, :depth, :updated_at, :public_metadata-- attribute :description do |taxon|- taxon.description.to_plain_text- end-- attribute :has_products do |taxon|- taxon.classification_count.positive? || taxon.active_products_with_descendants.exists?- end-- attribute :header_url do |taxon|- url_helpers.cdn_image_url(taxon.image.attachment) if taxon.image.present? && taxon.image.attached?- end-- attribute :is_root do |taxon|- taxon.root?- end-- attribute :is_child do |taxon|- taxon.child?- end-- attribute :is_leaf do |taxon|- taxon.leaf?- end-- attribute :localized_slugs do |taxon, params|- taxon.localized_slugs_for_store(params[:store])- end-- belongs_to :parent, record_type: :taxon, serializer: Spree.api.storefront_taxon_serializer- belongs_to :taxonomy, record_type: :taxonomy, serializer: Spree.api.storefront_taxonomy_serializer-- has_many :children, record_type: :taxon, serializer: Spree.api.storefront_taxon_serializer- has_many :products, record_type: :product, serializer: Spree.api.storefront_product_serializer,- if: proc { |_taxon, params| params && params[:include_products] == true }-- has_one :image,- object_method_name: :icon,- id_method_name: :icon_id,- record_type: :taxon_image,- serializer: Spree.api.storefront_taxon_image_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/taxonomy_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/taxonomy_serializer.rbdeleted file mode 100644index 3268de3cd0..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/taxonomy_serializer.rb+++ /dev/null@@ -1,13 +0,0 @@-module Spree- module V2- module Storefront- class TaxonomySerializer < BaseSerializer- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :taxonomy-- attributes :name, :position, :public_metadata- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/user_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/user_serializer.rbdeleted file mode 100644index fe6d81d92d..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/user_serializer.rb+++ /dev/null@@ -1,33 +0,0 @@-module Spree- module V2- module Storefront- class UserSerializer < BaseSerializer- set_type :user-- attributes :email, :first_name, :selected_locale, :last_name, :public_metadata-- attribute :tags, &:tag_list-- attribute :store_credits do |user|- user.total_available_store_credit- end-- attribute :completed_orders do |object|- object.orders.complete.count- end-- has_one :default_billing_address,- id_method_name: :bill_address_id,- object_method_name: :bill_address,- record_type: :address,- serializer: Spree.api.storefront_address_serializer-- has_one :default_shipping_address,- id_method_name: :ship_address_id,- object_method_name: :ship_address,- record_type: :address,- serializer: Spree.api.storefront_address_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/variant_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/variant_serializer.rbdeleted file mode 100644index a7115437ba..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/variant_serializer.rb+++ /dev/null@@ -1,58 +0,0 @@-module Spree- module V2- module Storefront- class VariantSerializer < BaseSerializer- include ::Spree::Api::V2::DisplayMoneyHelper- include Spree::Api::V2::PublicMetafieldsConcern-- set_type :variant-- attributes :sku, :barcode, :weight, :height, :width, :depth, :is_master, :options_text, :options, :public_metadata-- attribute :purchasable do |variant|- variant.purchasable?- end-- attribute :in_stock do |variant|- variant.in_stock?- end-- attribute :backorderable do |variant|- variant.backorderable?- end-- attribute :currency do |_product, params|- params[:currency]- end-- attribute :price do |product, params|- price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_price do |product, params|- display_price(product, params[:currency], pricing_context_options(params))- end-- attribute :compare_at_price do |product, params|- compare_at_price(product, params[:currency], pricing_context_options(params))- end-- attribute :display_compare_at_price do |product, params|- display_compare_at_price(product, params[:currency], pricing_context_options(params))- end-- def self.pricing_context_options(params)- {- store: params[:store],- user: params[:user],- tax_zone: params.dig(:price_options, :tax_zone)- }- end-- belongs_to :product, serializer: Spree.api.storefront_product_serializer- has_many :images, serializer: Spree.api.storefront_image_serializer- has_many :option_values, serializer: Spree.api.storefront_option_value_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/wished_item_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/wished_item_serializer.rbdeleted file mode 100644index f643902712..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/wished_item_serializer.rb+++ /dev/null@@ -1,29 +0,0 @@-module Spree- module V2- module Storefront- class WishedItemSerializer < BaseSerializer- set_type :wished_item-- attributes :quantity-- attribute :price do |wished_item, params|- wished_item.price(currency: params[:currency])- end-- attribute :total do |wished_item, params|- wished_item.total(currency: params[:currency])- end-- attribute :display_price do |wished_item, params|- wished_item.display_price(currency: params[:currency]).to_s- end-- attribute :display_total do |wished_item, params|- wished_item.display_total(currency: params[:currency]).to_s- end-- belongs_to :variant, serializer: Spree.api.storefront_variant_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/serializers/spree/v2/storefront/wishlist_serializer.rb b/legacy_api_v2/app/serializers/spree/v2/storefront/wishlist_serializer.rbdeleted file mode 100644index b712aa304c..0000000000--- a/legacy_api_v2/app/serializers/spree/v2/storefront/wishlist_serializer.rb+++ /dev/null@@ -1,17 +0,0 @@-module Spree- module V2- module Storefront- class WishlistSerializer < BaseSerializer- set_type :wishlist-- attributes :token, :name, :is_private, :is_default-- attribute :variant_included do |wishlist, params|- wishlist.include?(params[:is_variant_included])- end-- has_many :wished_items, serializer: Spree.api.storefront_wished_item_serializer- end- end- end-enddiff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/_form.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_form.html.erbdeleted file mode 100644index 05dd642a0b..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/_form.html.erb+++ /dev/null@@ -1,6 +0,0 @@-<div class="card mb-6">- <div class="card-body">- <%= f.spree_text_field :name, required: true, autofocus: f.object.new_record? %>- <%= f.spree_select :scopes, [['Read Only', 'admin read'], ['Read & Write', 'admin write']], { selected: @oauth_application.scopes.to_s }, { required: true } %>- </div>-</div>diff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_header.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_header.html.erbdeleted file mode 100644index fbcccaf45b..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_header.html.erb+++ /dev/null@@ -1,7 +0,0 @@-<tr>- <th scope="col"><%= sort_link @search, :name, Spree.t(:name) %></th>- <th scope="col"><%= Spree.t('admin.oauth_applications.client_id') %></th>- <th scope="col"><%= Spree.t('admin.oauth_applications.scopes') %></th>- <th scope="col"><%= Spree.t('admin.oauth_applications.last_used') %></th>- <th scope="col"></th>-</tr>\ No newline at end of filediff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_row.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_row.html.erbdeleted file mode 100644index 062f84f630..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_row.html.erb+++ /dev/null@@ -1,34 +0,0 @@-<tr id="<%= spree_dom_id oauth_application %>">- <td class="w-20"><code><%= oauth_application.name %></code></td>- <td class="w-40">- <div class="flex gap-2 items-center" data-controller="password-toggle">- <%= button_tag class: 'btn btn-light btn-sm px-1', data: { action: 'click->password-toggle#password' } do %>- <%= icon 'eye', class: 'mr-0' %>- <% end %>- <%= password_field_tag :password, oauth_application.uid, class: 'form-input-plaintext', data: { password_toggle_target: 'unhide' }, readonly: true %>- </div>- </td>- <td class="w-15">- <% if oauth_application.scopes.include?('write') %>- <span class="badge badge-warning">- <%= icon('pencil', class: 'mr-1') %>- <%= Spree.t('admin.oauth_applications.read_and_write') %>- </span>- <% else %>- <span class="badge badge-light">- <%= icon('eye', class: 'mr-1') %>- <%= Spree.t('admin.oauth_applications.read_only') %>- </span>- <% end %>- </td>- <td class="w-15">- <% if oauth_application.last_used_at %>- <%= spree_time(oauth_application.last_used_at) %>- <% else %>- <span class="text-gray-600"><%= Spree.t('admin.oauth_applications.never') %></span>- <% end %>- </td>- <td class="actions w-10">- <%= link_to_edit(oauth_application, no_text: true, data: { turbo_frame: '_top' }) if can? :edit, oauth_application %>- </td>-</tr>\ No newline at end of filediff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/create.turbo_stream.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/create.turbo_stream.erbdeleted file mode 100644index 84b00d2cd5..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/create.turbo_stream.erb+++ /dev/null@@ -1,31 +0,0 @@-<%= turbo_stream.replace "new_oauth_application" do %>- <div class="grid grid-cols-12 gap-6">- <div class="col-span-12 lg:col-span-6 lg:col-start-4">- <div class="card">- <div class="card-body">- <div class="form-group">- <%= label_tag :client_id, Spree.t('admin.oauth_applications.client_id') %>- <div class="flex gap-2 items-center">- <%= text_field_tag :client_id, @object.uid, class: 'form-input-plaintext bg-gray-25 rounded', readonly: true %>- <%= clipboard_component(@object.uid) %>- </div>- </div>-- <div class="form-group">- <%= label_tag :client_secret, Spree.t('admin.oauth_applications.client_secret') %>- <div class="flex gap-2 items-center">- <%= text_field_tag :client_secret, @object.plaintext_secret, class: 'form-input-plaintext bg-gray-25 rounded', readonly: true %>- <%= clipboard_component(@object.plaintext_secret) %>- </div>- <div class="alert alert-warning mt-6">- This is your application's secret token, copy it now and keep it safe. It won't be shown again.- </div>- </div>- </div>- <div class="card-footer border-t">- <%= link_to 'Back to list', spree.admin_oauth_applications_url, class: 'btn btn-light' %>- </div>- </div>- </div>- </div>-<% end %>diff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/edit.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/edit.html.erbdeleted file mode 100644index 520a6f47c2..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/edit.html.erb+++ /dev/null@@ -1 +0,0 @@-<%= render 'spree/admin/shared/edit_resource' %>\ No newline at end of filediff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/index.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/index.html.erbdeleted file mode 100644index bfc8ef96db..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/index.html.erb+++ /dev/null@@ -1,21 +0,0 @@-<%= render 'spree/admin/shared/developers_nav' %>--<%= content_for(:title, Spree.t('admin.oauth_applications.list')) %>--<% content_for :page_actions do %>- <%= render_admin_partials(:oauth_applications_actions_partials) %>- <%= link_to_with_icon 'plus', Spree.t('admin.oauth_applications.new'), new_object_url, class: "btn btn-primary" if can? :create, Spree::OauthApplication %>-<% end %>--<%= content_for :page_alerts do %>- <div class="alert alert-info">- <p>- Here you can manage API keys to access the <%= external_link_to 'Platform API', 'https://spreecommerce.org/docs/api-reference/platform/authentication' %>.- For headless storefronts you don't need an API key, please use the <%= external_link_to 'Storefront API', 'https://spreecommerce.org/docs/api-reference/storefront/authentication' %>.- </p>- </div>-<% end %>--<%= render_admin_partials(:oauth_applications_header_partials) %>--<%= render 'spree/admin/shared/index_table' %>diff --git a/legacy_api_v2/app/views/spree/admin/oauth_applications/new.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/new.html.erbdeleted file mode 100644index 0fd3668cab..0000000000--- a/legacy_api_v2/app/views/spree/admin/oauth_applications/new.html.erb+++ /dev/null@@ -1 +0,0 @@-<%= render 'spree/admin/shared/new_resource' %>\ No newline at end of filediff --git a/legacy_api_v2/config/initializers/doorkeeper.rb b/legacy_api_v2/config/initializers/doorkeeper.rbdeleted file mode 100644index 2fcb9bc1a0..0000000000--- a/legacy_api_v2/config/initializers/doorkeeper.rb+++ /dev/null@@ -1,50 +0,0 @@-Doorkeeper.configure do- orm :active_record- use_refresh_token- api_only- base_controller 'Spree::Api::V2::BaseController'- base_metal_controller 'Spree::Api::V2::BaseController'-- # FIXME: we should only skip this for Storefront API until v5- # we should not skip this for Platform API- skip_client_authentication_for_password_grant { true } if defined?(skip_client_authentication_for_password_grant)-- resource_owner_authenticator { current_spree_user }- use_polymorphic_resource_owner-- resource_owner_from_credentials do- user = Spree.user_class.find_for_database_authentication(email: params[:username])-- next if user.nil?-- if defined?(Spree::Auth::Config) && Spree::Auth::Config[:confirmable] == true- user if user.active_for_authentication? && user.valid_for_authentication? { user.valid_password?(params[:password]) }- elsif user&.valid_for_authentication? { user.valid_password?(params[:password]) }- user- end- end-- admin_authenticator do |routes|- current_spree_user&.spree_admin?(Spree::Store.current) || redirect_to(routes.root_url)- end-- grant_flows %w[password client_credentials]-- allow_blank_redirect_uri true-- handle_auth_errors :raise-- access_token_methods :from_bearer_authorization, :from_access_token_param-- optional_scopes :admin, :write, :read-- access_token_class 'Spree::OauthAccessToken'- access_grant_class 'Spree::OauthAccessGrant'- application_class 'Spree::OauthApplication'-- # using Bcrupt for token secrets is currently not supported by Doorkeeper- hash_token_secrets fallback: :plain- hash_application_secrets fallback: :plain, using: '::Doorkeeper::SecretStoring::BCrypt'-- access_token_expires_in 1.month-enddiff --git a/legacy_api_v2/config/initializers/json_api_mime_types.rb b/legacy_api_v2/config/initializers/json_api_mime_types.rbdeleted file mode 100644index 7ec8f73f59..0000000000--- a/legacy_api_v2/config/initializers/json_api_mime_types.rb+++ /dev/null@@ -1,8 +0,0 @@-api_mime_types = %w(- application/vnd.api+json- text/x-json- application/json-)--Mime::Type.unregister :json-Mime::Type.register 'application/json', :json, api_mime_typesdiff --git a/legacy_api_v2/config/initializers/user_class_extensions.rb b/legacy_api_v2/config/initializers/user_class_extensions.rbdeleted file mode 100644index 15f34b3327..0000000000--- a/legacy_api_v2/config/initializers/user_class_extensions.rb+++ /dev/null@@ -1,7 +0,0 @@-# Ensure that Spree.user_class includes the UserApiMethods concern--Spree::Core::Engine.config.to_prepare do- if Spree.user_class && !Spree.user_class.included_modules.include?(Spree::UserApiMethods)- Spree.user_class.include Spree::UserApiMethods- end-enddiff --git a/legacy_api_v2/config/routes.rb b/legacy_api_v2/config/routes.rbdeleted file mode 100644index 927b48c4da..0000000000--- a/legacy_api_v2/config/routes.rb+++ /dev/null@@ -1,219 +0,0 @@-# frozen_string_literal: true--spree_path = Rails.application.routes.url_helpers.try(:spree_path, trailing_slash: true) || '/'--Rails.application.routes.draw do- use_doorkeeper scope: "#{spree_path}/spree_oauth"-end--Spree::Core::Engine.add_routes do- # Admin UI to manage OAuth applications- namespace :admin do- resources :oauth_applications- end-- namespace :api, defaults: { format: 'json' } do- namespace :v2 do- namespace :storefront do- resource :cart, controller: :cart, only: %i[show create destroy] do- post :add_item- patch :empty- delete 'remove_line_item/:line_item_id', to: 'cart#remove_line_item', as: :cart_remove_line_item- patch :set_quantity- patch :apply_coupon_code- delete 'remove_coupon_code/:coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code, constraints: { coupon_code: /[^\/]+/ }- delete 'remove_coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code_without_code- get :estimate_shipping_rates- patch :associate- patch :change_currency- end-- resource :checkout, controller: :checkout, only: %i[update] do- patch :next- patch :advance- patch :complete- post :create_payment- post :add_store_credit- post :remove_store_credit- get :payment_methods- get :shipping_rates- patch :select_shipping_method- post :validate_order_for_payment- end-- resource :account, controller: :account, only: %i[show create update]-- namespace :account do- resources :addresses, controller: :addresses- resources :credit_cards, controller: :credit_cards, only: %i[index show destroy]- resources :orders, controller: :orders, only: %i[index show]- end-- resources :countries, only: %i[index]- get '/countries/:iso', to: 'countries#show', as: :country- get '/order_status/:number', to: 'order_status#show', as: :order_status- resources :products, only: %i[index show]- get '/products/:id/variants', to: 'variants#index', as: :product_variants- resources :taxons, only: %i[index show], id: /.+/- get '/stores/:code', to: 'stores#show', as: :store- get '/store', to: 'stores#current', as: :current_store-- resources :menus, only: %i[index show]- resources :cms_pages, only: %i[index show]- resources :policies, only: %i[index show]-- resources :wishlists do- get :default, on: :collection-- member do- post :add_item- patch 'set_item_quantity/:item_id', to: 'wishlists#set_item_quantity', as: :set_item_quantity- delete 'remove_item/:item_id', to: 'wishlists#remove_item', as: :remove_item- post :add_items- delete :remove_items- end- end-- resources :posts, only: %i[index show]- resources :post_categories, only: %i[index show]-- get '/digitals/:token', to: 'digitals#download', as: 'digital'- end-- namespace :platform do- # Promotions API- resources :promotions- resources :promotion_actions- resources :promotion_categories- resources :promotion_rules-- # Returns API- resources :customer_returns- resources :reimbursements- resources :return_authorizations do- member do- patch :add- patch :cancel- patch :receive- end- end-- # Product Catalog API- resources :products- resources :taxonomies- resources :taxons do- member do- patch :reposition- end- end- resources :classifications- resources :images- resources :variants- resources :properties- resources :product_properties- resources :option_types- resources :option_values-- # Order API- resources :orders do- member do- patch :next- patch :advance- patch :approve- patch :cancel- patch :empty- patch :apply_coupon_code- patch :complete- patch :use_store_credit- patch :cancel- patch :approve- end- end- resources :line_items- resources :adjustments-- # Payments API- resources :payments-- # Store Credit API- resources :store_credits- resources :store_credit_categories- resources :store_credit_types-- # Geo API- resources :zones- resources :countries, only: [:index, :show]- resources :states, only: [:index, :show]-- # Shipment API- resources :shipments do- member do- %w[ready ship cancel resume pend].each do |state|- patch state.to_sym- end- patch :add_item- patch :remove_item- patch :transfer_to_location- patch :transfer_to_shipment- end- end-- # Tax API- resources :tax_rates- resources :tax_categories-- # Inventory API- resources :inventory_units- resources :stock_items- resources :stock_locations- resources :stock_movements-- # User API- resources :users- resources :credit_cards- resources :addresses-- resources :roles-- # CMS- resources :cms_pages- resources :cms_sections-- # Wishlists API- resources :wishlists- resources :wished_items-- # Digitals API- resources :digitals- resources :digital_links do- member do- patch :reset- end- end-- # Store API- resources :stores-- # Data Feeds API- resources :data_feeds-- # Configurations API- resources :payment_methods- resources :shipping_categories- resources :shipping_methods-- # Webhooks API- namespace :webhooks do- end-- # Gift Cards API- resources :gift_cards- end-- namespace :data_feeds do- # google data feed API- get '/google/:slug', to: 'google#rss_feed'- end- end- end-enddiff --git a/legacy_api_v2/db/migrate/20100107141738_add_api_key_to_spree_users.rb b/legacy_api_v2/db/migrate/20100107141738_add_api_key_to_spree_users.rbdeleted file mode 100644index e73d67b276..0000000000--- a/legacy_api_v2/db/migrate/20100107141738_add_api_key_to_spree_users.rb+++ /dev/null@@ -1,7 +0,0 @@-class AddApiKeyToSpreeUsers < ActiveRecord::Migration[4.2]- def change- unless defined?(User)- add_column :spree_users, :api_key, :string, limit: 40- end- end-enddiff --git a/legacy_api_v2/db/migrate/20120411123334_resize_api_key_field.rb b/legacy_api_v2/db/migrate/20120411123334_resize_api_key_field.rbdeleted file mode 100644index 23d520214f..0000000000--- a/legacy_api_v2/db/migrate/20120411123334_resize_api_key_field.rb+++ /dev/null@@ -1,7 +0,0 @@-class ResizeApiKeyField < ActiveRecord::Migration[4.2]- def change- unless defined?(User)- change_column :spree_users, :api_key, :string, limit: 48- end- end-enddiff --git a/legacy_api_v2/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb b/legacy_api_v2/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rbdeleted file mode 100644index 230a620965..0000000000--- a/legacy_api_v2/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb+++ /dev/null@@ -1,7 +0,0 @@-class RenameApiKeyToSpreeApiKey < ActiveRecord::Migration[4.2]- def change- unless defined?(User)- rename_column :spree_users, :api_key, :spree_api_key- end- end-enddiff --git a/legacy_api_v2/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb b/legacy_api_v2/db/migrate/20131017162334_add_index_to_user_spree_api_key.rbdeleted file mode 100644index a1472bd5d5..0000000000--- a/legacy_api_v2/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb+++ /dev/null@@ -1,7 +0,0 @@-class AddIndexToUserSpreeApiKey < ActiveRecord::Migration[4.2]- def change- unless defined?(User)- add_index :spree_users, :spree_api_key- end- end-enddiff --git a/legacy_api_v2/db/migrate/20180320110726_create_doorkeeper_tables.rb b/legacy_api_v2/db/migrate/20180320110726_create_doorkeeper_tables.rbdeleted file mode 100644index aacc661ee6..0000000000--- a/legacy_api_v2/db/migrate/20180320110726_create_doorkeeper_tables.rb+++ /dev/null@@ -1,69 +0,0 @@-class CreateDoorkeeperTables < ActiveRecord::Migration[5.1]- def change- create_table :spree_oauth_applications do |t|- t.string :name, null: false- t.string :uid, null: false- t.string :secret, null: false- t.text :redirect_uri, null: false- t.string :scopes, null: false, default: ''- t.boolean :confidential, null: false, default: true- t.timestamps null: false- end-- add_index :spree_oauth_applications, :uid, unique: true-- create_table :spree_oauth_access_grants do |t|- t.integer :resource_owner_id, null: false- t.references :application, null: false- t.string :token, null: false- t.integer :expires_in, null: false- t.text :redirect_uri, null: false- t.datetime :created_at, null: false- t.datetime :revoked_at- t.string :scopes- end-- add_index :spree_oauth_access_grants, :token, unique: true- add_foreign_key(- :spree_oauth_access_grants,- :spree_oauth_applications,- column: :application_id- )-- create_table :spree_oauth_access_tokens do |t|- t.integer :resource_owner_id- t.references :application-- # If you use a custom token generator you may need to change this column- # from string to text, so that it accepts tokens larger than 255- # characters. More info on custom token generators in:- # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator- #- # t.text :token, null: false- t.string :token, null: false-- t.string :refresh_token- t.integer :expires_in- t.datetime :revoked_at- t.datetime :created_at, null: false- t.string :scopes-- # If there is a previous_refresh_token column,- # refresh tokens will be revoked after a related access token is used.- # If there is no previous_refresh_token column,- # previous tokens are revoked as soon as a new access token is created.- # Comment out this line if you'd rather have refresh tokens- # instantly revoked.- t.string :previous_refresh_token, null: false, default: ""- end-- add_index :spree_oauth_access_tokens, :token, unique: true- add_index :spree_oauth_access_tokens, :resource_owner_id- add_index :spree_oauth_access_tokens, :refresh_token, unique: true- add_foreign_key(- :spree_oauth_access_tokens,- :spree_oauth_applications,- column: :application_id- )- end-enddiff --git a/legacy_api_v2/db/migrate/20210727102516_change_integer_id_columns_type.rb b/legacy_api_v2/db/migrate/20210727102516_change_integer_id_columns_type.rbdeleted file mode 100644index c21852dfab..0000000000--- a/legacy_api_v2/db/migrate/20210727102516_change_integer_id_columns_type.rb+++ /dev/null@@ -1,9 +0,0 @@-class ChangeIntegerIdColumnsType < ActiveRecord::Migration[5.2]- def change- change_column :spree_oauth_access_grants, :resource_owner_id, :bigint- change_column :spree_oauth_access_grants, :application_id, :bigint-- change_column :spree_oauth_access_tokens, :resource_owner_id, :bigint- change_column :spree_oauth_access_tokens, :application_id, :bigint- end-enddiff --git a/legacy_api_v2/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb b/legacy_api_v2/db/migrate/20210919183228_enable_polymorphic_resource_owner.rbdeleted file mode 100644index 081b32da70..0000000000--- a/legacy_api_v2/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb+++ /dev/null@@ -1,21 +0,0 @@-class EnablePolymorphicResourceOwner < ActiveRecord::Migration[5.2]- def change- add_column :spree_oauth_access_tokens, :resource_owner_type, :string- add_column :spree_oauth_access_grants, :resource_owner_type, :string- change_column_null :spree_oauth_access_grants, :resource_owner_type, false-- add_index :spree_oauth_access_tokens,- [:resource_owner_id, :resource_owner_type],- name: 'polymorphic_owner_oauth_access_tokens'-- add_index :spree_oauth_access_grants,- [:resource_owner_id, :resource_owner_type],- name: 'polymorphic_owner_oauth_access_grants'-- Spree::OauthAccessToken.reset_column_information- Spree::OauthAccessToken.update_all(resource_owner_type: Spree.user_class)-- Spree::OauthAccessGrant.reset_column_information- Spree::OauthAccessGrant.update_all(resource_owner_type: Spree.user_class)- end-enddiff --git a/legacy_api_v2/lib/generators/spree/legacy_api_v2/install/install_generator.rb b/legacy_api_v2/lib/generators/spree/legacy_api_v2/install/install_generator.rbdeleted file mode 100644index 7a794c05c7..0000000000--- a/legacy_api_v2/lib/generators/spree/legacy_api_v2/install/install_generator.rb+++ /dev/null@@ -1,24 +0,0 @@-# frozen_string_literal: true--module Spree- module LegacyApiV2- module Generators- class InstallGenerator < Rails::Generators::Base- class_option :migrate, type: :boolean, default: true-- def add_migrations- run 'bundle exec rake railties:install:migrations FROM=spree_legacy_api_v2'- end-- def run_migrations- run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))- if run_migrations- run 'bin/rails db:migrate'- else- puts 'Skipping rails db:migrate, don\'t forget to run it!'- end- end- end- end- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2.rb b/legacy_api_v2/lib/spree/legacy_api_v2.rbdeleted file mode 100644index 7557280bbd..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2.rb+++ /dev/null@@ -1,5 +0,0 @@-require 'spree'-require 'doorkeeper'-require 'jsonapi/serializer'--require 'spree/legacy_api_v2/engine'diff --git a/legacy_api_v2/lib/spree/legacy_api_v2/engine.rb b/legacy_api_v2/lib/spree/legacy_api_v2/engine.rbdeleted file mode 100644index 719c6bfc70..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/engine.rb+++ /dev/null@@ -1,77 +0,0 @@-require 'rails/engine'--module Spree- module LegacyApiV2- class Engine < Rails::Engine- isolate_namespace Spree- engine_name 'spree_legacy_api_v2'-- # Merge V2 dependencies into Spree::Api::Dependencies for backward compatibility- # This allows existing code using Spree.api.storefront_cart_serializer to continue working- # initializer 'spree.legacy_api_v2.merge_dependencies', after: 'spree.api.environment' do- # Engine.merge_v2_dependencies_into_api!- # end-- initializer 'spree.legacy_api_v2.checking_migrations' do- Migrations.new(config, engine_name).check unless Rails.env.test?- end-- class << self- def merge_v2_dependencies_into_api!- api_deps_class = Spree::Api::ApiDependencies- v2_defaults = Spree::LegacyApiV2::ApiDependencies::INJECTION_POINTS_WITH_DEFAULTS-- # Collect all new V2 points that don't exist in V3- new_points = []-- v2_defaults.each do |point, default_value|- # Skip if already defined (V3 has priority)- next if api_deps_class::INJECTION_POINTS.include?(point)-- new_points << point-- # Define getter- api_deps_class.attr_reader(point)-- # Define setter with override tracking- api_deps_class.define_method("#{point}=") do |value|- @overrides ||= {}- @overrides[point] = {- value: value,- source: find_caller_source,- set_at: Time.current- }- remove_instance_variable("@#{point}_resolved") if instance_variable_defined?("@#{point}_resolved")- instance_variable_set("@#{point}", value)- end-- # Define _class method for resolved class access- api_deps_class.define_method("#{point}_class") do- return instance_variable_get("@#{point}_resolved") if instance_variable_defined?("@#{point}_resolved")-- value = send(point)- resolved = case value- when String then value.constantize- when Proc then value.call.then { |v| v.is_a?(String) ? v.constantize : v }- else value- end- instance_variable_set("@#{point}_resolved", resolved)- resolved- end-- # Set the default value on the existing Dependencies instance- value = default_value.respond_to?(:call) ? default_value.call : default_value- Spree::Api::Dependencies.instance_variable_set("@#{point}", value)- end-- # Update INJECTION_POINTS constant with all new points at once- if new_points.any?- combined_points = (api_deps_class::INJECTION_POINTS.to_a + new_points).freeze- api_deps_class.send(:remove_const, :INJECTION_POINTS)- api_deps_class.const_set(:INJECTION_POINTS, combined_points)- end- end- end- end- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories.rbdeleted file mode 100644index 5f86263523..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories.rb+++ /dev/null@@ -1 +0,0 @@-Dir[File.dirname(__FILE__) + '/factories/**/*.rb'].each { |f| load f }diff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories/oauth_application_factory.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories/oauth_application_factory.rbdeleted file mode 100644index 953a843911..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/factories/oauth_application_factory.rb+++ /dev/null@@ -1,7 +0,0 @@-FactoryBot.define do- factory :oauth_application, class: Spree::OauthApplication do- name { 'Test Application' }- redirect_uri { '' }- scopes { '' }- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/serializers.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/serializers.rbdeleted file mode 100644index 75b7d7b346..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/serializers.rb+++ /dev/null@@ -1,15 +0,0 @@-module Spree- class TestArgumentsJob < Spree::BaseJob- def perform(serializer); end- end-end--shared_examples 'an ActiveJob serializable hash' do- it 'can be serialized by ActiveJob' do- # It should fail if subject contains any custom instance (e.g Spree::Money)- expect { Spree::TestArgumentsJob.perform_later(subject) }.not_to raise_error- expect { Spree::TestArgumentsJob.perform_later(subject.merge(price: Spree::Money.new(0))) }.to(- raise_error(ActiveJob::SerializationError)- )- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/base.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/base.rbdeleted file mode 100644index 863adbe1b7..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/base.rb+++ /dev/null@@ -1,13 +0,0 @@-shared_context 'API v2 tokens' do- let(:token) { Spree::OauthAccessToken.create!(resource_owner: user, expires_in: nil) }- let(:headers_bearer) { { 'Authorization' => "Bearer #{token.token}" } }- let(:headers_order_token) { { 'X-Spree-Order-Token' => order.token } }-end--[200, 201, 204, 400, 401, 404, 403, 422].each do |status_code|- shared_examples "returns #{status_code} HTTP status" do- it "returns #{status_code}" do- expect(response.status).to eq(status_code)- end- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/current_order.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/current_order.rbdeleted file mode 100644index f0af23131a..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/current_order.rb+++ /dev/null@@ -1,116 +0,0 @@-def ensure_order_totals- order.update_with_updater!-end--shared_context 'creates order with line item' do- let!(:line_item) { create(:line_item, order: order, currency: currency) }- let!(:headers) { headers_bearer }-- before do- order.reload- ensure_order_totals- end-end--shared_context 'order with a physical line item' do- include_context 'creates order with line item'-end--shared_context 'order with a digital line item' do- let(:digital_shipping_method) { create(:digital_shipping_method) }- let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }- let(:variant_digital) { create(:variant, product: digital_product) }- let!(:digital) { create(:digital, variant: variant_digital) }- let!(:line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }- let!(:headers) { headers_bearer }-- before do- order.reload- ensure_order_totals- end-end--shared_context 'order with a physical and digital line item' do- let(:digital_shipping_method) { create(:digital_shipping_method) }- let(:product_digital) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }- let(:variant_digital) { create(:variant, product: product_digital) }- let!(:digital) { create(:digital, variant: variant_digital) }- let!(:digital_line_item) { create(:line_item, variant: variant_digital, order: order, currency: currency) }- let!(:physical_line_item) { create(:line_item, order: order, currency: currency) }-- let!(:headers) { headers_bearer }-- before do- order.reload- ensure_order_totals- end-end--shared_context 'creates guest order with guest token' do- let(:guest_token) { 'guest_token' }- let!(:order) { create(:order, token: guest_token, store: store, currency: currency) }- let!(:line_item) { create(:line_item, order: order, currency: currency) }- let!(:headers) { headers_order_token }-- before { ensure_order_totals }-end--shared_examples 'returns valid cart JSON' do- it 'returns a valid cart JSON response' do- order.reload- expect(json_response['data']).to be_present- expect(json_response['data']).to have_id(order.id.to_s)- expect(json_response['data']).to have_type('cart')- expect(json_response['data']).to have_attribute(:number).with_value(order.number)- expect(json_response['data']).to have_attribute(:state).with_value(order.state)- expect(json_response['data']).to have_attribute(:payment_state).with_value(order.payment_state)- expect(json_response['data']).to have_attribute(:shipment_state).with_value(order.shipment_state)- expect(json_response['data']).to have_attribute(:token).with_value(order.token)- expect(json_response['data']).to have_attribute(:total).with_value(order.total.to_s)- expect(json_response['data']).to have_attribute(:item_total).with_value(order.item_total.to_s)- expect(json_response['data']).to have_attribute(:ship_total).with_value(order.ship_total.to_s)- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(order.adjustment_total.to_s)- expect(json_response['data']).to have_attribute(:included_tax_total).with_value(order.included_tax_total.to_s)- expect(json_response['data']).to have_attribute(:additional_tax_total).with_value(order.additional_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_additional_tax_total).with_value(order.display_additional_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_included_tax_total).with_value(order.display_included_tax_total.to_s)- expect(json_response['data']).to have_attribute(:tax_total).with_value(order.tax_total.to_s)- expect(json_response['data']).to have_attribute(:currency).with_value(order.currency.to_s)- expect(json_response['data']).to have_attribute(:email).with_value(order.email)- expect(json_response['data']).to have_attribute(:display_item_total).with_value(order.display_item_total.to_s)- expect(json_response['data']).to have_attribute(:display_ship_total).with_value(order.display_ship_total.to_s)- expect(json_response['data']).to have_attribute(:display_adjustment_total).with_value(order.display_adjustment_total.to_s)- expect(json_response['data']).to have_attribute(:display_tax_total).with_value(order.display_tax_total.to_s)- expect(json_response['data']).to have_attribute(:item_count).with_value(order.item_count)- expect(json_response['data']).to have_attribute(:special_instructions).with_value(order.special_instructions)- expect(json_response['data']).to have_attribute(:promo_total).with_value(order.promo_total.to_s)- expect(json_response['data']).to have_attribute(:display_promo_total).with_value(order.display_promo_total.to_s)- expect(json_response['data']).to have_attribute(:display_total).with_value(order.display_total.to_s)- expect(json_response['data']).to have_attribute(:pre_tax_item_amount).with_value(order.pre_tax_item_amount.to_s)- expect(json_response['data']).to have_attribute(:display_pre_tax_item_amount).with_value(order.display_pre_tax_item_amount.to_s)- expect(json_response['data']).to have_attribute(:pre_tax_total).with_value(order.pre_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_pre_tax_total).with_value(order.display_pre_tax_total.to_s)- expect(json_response['data']).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments,- :promotions)- end-end--shared_examples 'no current order' do- context "order doesn't exist" do- before do- order.destroy- execute- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'already completed order' do- before do- order.update_column(:completed_at, Time.current)- execute- end-- it_behaves_like 'returns 404 HTTP status'- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/platform_contexts.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/platform_contexts.rbdeleted file mode 100644index d97960d28d..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/platform_contexts.rb+++ /dev/null@@ -1,272 +0,0 @@-class String- def articleize- if split.first == 'User'- "a #{self}"- else- %w(a e i o u).include?(self[0].downcase) ? "an #{self}" : "a #{self}"- end- end-end--shared_context 'Platform API v2' do- let(:store) { Spree::Store.default }- let(:admin_app) { Spree::OauthApplication.find_or_create_by!(name: 'Admin Panel', scopes: 'admin', redirect_uri: '') }- let(:read_app) { Spree::OauthApplication.find_or_create_by!(name: 'Read App', scopes: 'read', redirect_uri: '') }- let(:oauth_token) do- Spree::OauthAccessToken.create!(- application_id: admin_app.id,- scopes: admin_app.scopes- )- end- let(:read_oauth_token) do- Spree::OauthAccessToken.create!(- application_id: read_app.id,- scopes: read_app.scopes- )- end- let(:user_oauth_token) do- Spree::OauthAccessToken.create!(- resource_owner: user,- application_id: admin_app.id,- scopes: admin_app.scopes- )- end- let(:user_oauth_token_without_app) do- Spree::OauthAccessToken.create!(- resource_owner: user,- scopes: 'admin'- )- end-- let(:valid_authorization) { "Bearer #{oauth_token.token}" }- let(:valid_read_authorization) { "Bearer #{read_oauth_token.token}" }- let(:valid_user_authorization) { "Bearer #{user_oauth_token.token}" }- let(:valid_user_authorization_without_app) { "Bearer #{user_oauth_token_without_app.token}" }- let(:bogus_authorization) { "Bearer #{::Base64.strict_encode64('bogus:bogus')}" }-- let(:Authorization) { valid_authorization }-end--shared_context 'jsonapi pagination' do- let(:page) { 1 }- let(:per_page) { '' }- parameter name: :page, in: :query, type: :integer, example: 1- parameter name: :per_page, in: :query, type: :integer, example: 50-end--JSON_API_INCLUDES_DESCRIPTION = 'Select which associated resources you would like to fetch'\- ', see: <a href="https://jsonapi.org/format/#fetching-includes">'\- 'https://jsonapi.org/format/#fetching-includes</a>'.freeze-JSON_API_FILTER_DESCRIPTION = ''--def json_api_include_parameter(example = '')- let(:include) { nil }- parameter name: :include, in: :query, type: :string, description: JSON_API_INCLUDES_DESCRIPTION, example: example-end--def json_api_filter_parameter(examples = [])- examples.each do |api_filter|- name = api_filter[:name].to_sym- example = api_filter[:example]- let(name) { nil }-- parameter name: name, in: :query, type: :string, description: JSON_API_FILTER_DESCRIPTION, example: example- end-end--shared_examples 'authentication failed' do- response '401', 'Authentication Failed' do- let(:Authorization) { bogus_authorization }- schema '$ref' => '#/components/schemas/error'- run_test!- end-end--shared_examples 'record not found' do- response '404', 'Record not found' do- let(:id) { 'invalid' }- schema '$ref' => '#/components/schemas/error'- run_test!- end-end--shared_examples 'record found' do- response '200', 'Record found' do- schema '$ref' => '#/components/schemas/resource'- run_test!- end-end--shared_examples 'record deleted' do- response '204', 'Record deleted' do- run_test!- end-end--shared_examples 'records returned' do- response '200', 'Records returned' do- schema '$ref' => '#/components/schemas/resources_list'- run_test!- end-end--shared_examples 'record created' do- response '201', 'Record created' do- schema '$ref' => '#/components/schemas/resource'- run_test!- end-end--shared_examples 'record updated' do- response '200', 'Record updated' do- schema '$ref' => '#/components/schemas/resource'- run_test!- end-end--shared_examples 'invalid request' do |param_name|- response '422', 'Invalid request' do- let(param_name) { invalid_param_value }- schema '$ref' => '#/components/schemas/validation_errors'- run_test!- end-end--# index action-shared_examples 'GET records list' do |resource_name, **options|- endpoint_name = options[:custom_endpoint_name] || resource_name-- get "Return a list of #{endpoint_name.pluralize}" do- tags endpoint_name.pluralize- security [ bearer_auth: [] ]- description "Returns a list of #{endpoint_name.pluralize}"- operationId "#{resource_name.parameterize.pluralize.to_sym}-list"- include_context 'jsonapi pagination'- json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?- json_api_filter_parameter(options[:filter_examples]) unless options[:filter_examples].nil?-- before { records_list }-- it_behaves_like 'records returned'- it_behaves_like 'authentication failed'- end-end--# show-shared_examples 'GET record' do |resource_name, **options|- endpoint_name = options[:custom_endpoint_name] || resource_name-- get "Return #{endpoint_name.articleize}" do- tags endpoint_name.pluralize- security [ bearer_auth: [] ]- description "Returns #{endpoint_name.articleize}"- operationId "show-#{resource_name.parameterize.to_sym}"- parameter name: :id, in: :path, type: :string- json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?-- it_behaves_like 'record found'- it_behaves_like 'record not found'- it_behaves_like 'authentication failed'- end-end--# create-shared_examples 'POST create record' do |resource_name, **options|- custom_create_params = options[:custom_create_params] || nil- endpoint_name = options[:custom_endpoint_name] || resource_name- param_name = resource_name.parameterize(separator: '_').to_sym- consumes_kind = options[:consumes_kind] || 'application/json'- request_data_type = case consumes_kind- when 'multipart/form-data'- :formData- else- :body- end-- post "Create #{endpoint_name.articleize}" do- tags endpoint_name.pluralize- consumes consumes_kind- security [ bearer_auth: [] ]- description "Creates #{endpoint_name.articleize}"- operationId "create-#{resource_name.parameterize.to_sym}"- if custom_create_params- parameter name: param_name, in: request_data_type, schema: custom_create_params- else- parameter name: param_name, in: request_data_type, schema: { '$ref' => "#/components/schemas/create_#{param_name}_params" }- end- json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?-- let(param_name) { valid_create_param_value }-- it_behaves_like 'record created'- it_behaves_like 'invalid request', param_name unless options[:skip_invalid_params] == true- end-end--# update-shared_examples 'PATCH update record' do |resource_name, **options|- custom_update_params = options[:custom_update_params] || nil- endpoint_name = options[:custom_endpoint_name] || resource_name- param_name = resource_name.parameterize(separator: '_').to_sym- consumes_kind = options[:consumes_kind] || 'application/json'- request_data_type = case consumes_kind- when 'multipart/form-data'- :formData- else- :body- end-- patch "Update #{endpoint_name.articleize}" do- tags endpoint_name.pluralize- security [ bearer_auth: [] ]- description "Updates #{endpoint_name.articleize}"- operationId "update-#{resource_name.parameterize.to_sym}"- consumes consumes_kind- parameter name: :id, in: :path, type: :string- if custom_update_params- parameter name: param_name, in: request_data_type, schema: custom_update_params- else- parameter name: param_name, in: request_data_type, schema: { '$ref' => "#/components/schemas/update_#{param_name}_params" }- end- json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?-- let(param_name) { valid_update_param_value }-- it_behaves_like 'record updated'- it_behaves_like 'invalid request', param_name unless options[:skip_invalid_params] == true- it_behaves_like 'record not found'- it_behaves_like 'authentication failed'- end-end--# destroy-shared_examples 'DELETE record' do |resource_name, **options|- endpoint_name = options[:custom_endpoint_name] || resource_name-- delete "Delete #{endpoint_name.articleize}" do- tags endpoint_name.pluralize- security [ bearer_auth: [] ]- description "Deletes #{endpoint_name.articleize}"- operationId "delete-#{resource_name.parameterize.to_sym}"- parameter name: :id, in: :path, type: :string-- it_behaves_like 'record deleted'- it_behaves_like 'record not found'- it_behaves_like 'authentication failed'- end-end--shared_examples 'CRUD examples' do |resource_name, **options|- resource_path = resource_name.parameterize(separator: '_').pluralize-- path "/api/v2/platform/#{resource_path}" do- include_examples 'GET records list', resource_name, options- include_examples 'POST create record', resource_name, options- end-- path "/api/v2/platform/#{resource_path}/{id}" do- include_examples 'GET record', resource_name, options- include_examples 'PATCH update record', resource_name, options- include_examples 'DELETE record', resource_name, options- end-enddiff --git a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/serializers_params.rb b/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/serializers_params.rbdeleted file mode 100644index 3dcd385aaa..0000000000--- a/legacy_api_v2/lib/spree/legacy_api_v2/testing_support/v2/serializers_params.rb+++ /dev/null@@ -1,16 +0,0 @@-shared_context 'API v2 serializers params' do- let(:store) { Spree::Store.default || create(:store, default: true) }- let(:currency) { store.default_currency }- let(:locale) { store.default_locale }- let(:zone) { Spree::Zone.default_tax || create(:zone, default_tax: true) }-- let(:serializer_params) do- {- store: store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: zone }- }- end-enddiff --git a/legacy_api_v2/lib/spree_legacy_api_v2.rb b/legacy_api_v2/lib/spree_legacy_api_v2.rbdeleted file mode 100644index 232fc7073a..0000000000--- a/legacy_api_v2/lib/spree_legacy_api_v2.rb+++ /dev/null@@ -1 +0,0 @@-require 'spree/legacy_api_v2'diff --git a/legacy_api_v2/spec/controllers/doorkeeper/application_metal_controller_spec.rb b/legacy_api_v2/spec/controllers/doorkeeper/application_metal_controller_spec.rbdeleted file mode 100644index 02bb889ea2..0000000000--- a/legacy_api_v2/spec/controllers/doorkeeper/application_metal_controller_spec.rb+++ /dev/null@@ -1,7 +0,0 @@-require 'spec_helper'--describe Doorkeeper::ApplicationMetalController, type: :controller do- it 'inherits from Spree::Api::V2::BaseController' do- expect(described_class.superclass).to eq Spree::Api::V2::BaseController- end-enddiff --git a/legacy_api_v2/spec/controllers/doorkeeper/tokens_controller_spec.rb b/legacy_api_v2/spec/controllers/doorkeeper/tokens_controller_spec.rbdeleted file mode 100644index b5512307a8..0000000000--- a/legacy_api_v2/spec/controllers/doorkeeper/tokens_controller_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Doorkeeper::TokensController, type: :controller do- describe '#current_store' do- let!(:store) { @default_store }-- it 'returns current store' do- expect(controller.current_store).to eq(store)- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/admin/oauth_applications_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/admin/oauth_applications_controller_spec.rbdeleted file mode 100644index 8224d58886..0000000000--- a/legacy_api_v2/spec/controllers/spree/admin/oauth_applications_controller_spec.rb+++ /dev/null@@ -1,116 +0,0 @@-require 'spec_helper'--describe Spree::Admin::OauthApplicationsController, type: :controller do- stub_authorization!-- render_views-- describe '#index' do- let!(:oauth_application) { create(:oauth_application) }-- it 'responds successfully' do- get :index- expect(response).to be_successful- end- end-- describe '#new' do- it 'responds successfully' do- get :new- expect(response).to be_successful- end-- it 'sets default scopes to admin' do- get :new- expect(assigns(:object).scopes.to_s).to eq('admin')- end- end-- describe '#create' do- let(:params) do- {- oauth_application: {- name: 'Test App',- scopes: 'admin read'- }- }- end-- it 'creates a new oauth application' do- expect {- post :create, params: params- }.to change(Spree::OauthApplication, :count).by(1)- end-- it 'sets the attributes' do- post :create, params: params- oauth_app = Spree::OauthApplication.last- expect(oauth_app.name).to eq('Test App')- expect(oauth_app.scopes.to_s).to eq('admin read')- end-- it 'redirects to index with success flash' do- post :create, params: params- oauth_app = Spree::OauthApplication.last- expect(response).to redirect_to(spree.edit_admin_oauth_application_path(oauth_app))- expect(flash[:success]).to be_present- end- end-- describe '#edit' do- let!(:oauth_application) { create(:oauth_application) }-- it 'responds successfully' do- get :edit, params: { id: oauth_application.id }- expect(response).to be_successful- end-- it 'sets default scopes to admin if blank' do- oauth_application.update(scopes: '')- get :edit, params: { id: oauth_application.id }- expect(assigns(:object).scopes.to_s).to eq('admin')- end- end-- describe '#update' do- let!(:oauth_application) { create(:oauth_application) }- let(:params) do- {- id: oauth_application.id,- oauth_application: {- name: 'Updated App',- scopes: 'admin write'- }- }- end-- it 'updates the oauth application' do- put :update, params: params- oauth_application.reload- expect(oauth_application.name).to eq('Updated App')- expect(oauth_application.scopes.to_s).to eq('admin write')- end-- it 'redirects to index with success flash' do- put :update, params: params- expect(response).to redirect_to(spree.edit_admin_oauth_application_path(oauth_application))- expect(flash[:success]).to be_present- end- end-- describe '#destroy' do- let!(:oauth_application) { create(:oauth_application) }-- it 'destroys the oauth application' do- expect {- delete :destroy, params: { id: oauth_application.id }- }.to change(Spree::OauthApplication, :count).by(-1)- end-- it 'redirects to index with success flash' do- delete :destroy, params: { id: oauth_application.id }- expect(response).to redirect_to(spree.admin_oauth_applications_path)- expect(flash[:success]).to be_present- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/api/v2/base_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/api/v2/base_controller_spec.rbdeleted file mode 100644index 850dd0d24a..0000000000--- a/legacy_api_v2/spec/controllers/spree/api/v2/base_controller_spec.rb+++ /dev/null@@ -1,185 +0,0 @@-require 'spec_helper'--class DummyController < Spree::Api::V2::BaseController- private-- def default_resource_includes- %w[variants images]- end-end--describe Spree::Api::V2::BaseController, type: :controller do- let(:dummy_controller) { DummyController.new }-- describe '#default_resource_includes' do- context 'not implemented' do- it 'returns an empty array' do- expect(controller.send(:default_resource_includes)).to eq([])- end- end-- context 'implemented' do- it 'overrides the method' do- expect(dummy_controller.send(:default_resource_includes)).to eq(%w[variants images])- end- end- end-- describe '#resource_includes' do- context 'passed as params' do- before do- dummy_controller.params = { include: 'variants,images,taxons' }- end-- it 'returns included resources specified in params' do- expect(dummy_controller.send(:resource_includes)).to eq([:variants, :images, :taxons])- end- end-- context 'not passed in params' do- before do- dummy_controller.params = {}- end-- it 'returns default resources' do- expect(dummy_controller.send(:resource_includes)).to eq([:variants, :images])- end- end- end-- describe '#sparse_fields' do- shared_examples 'invalid params format' do- it 'returns nil' do- expect(dummy_controller.send(:sparse_fields)).to eq(nil)- end- end-- context 'not passed in params' do- before do- dummy_controller.params = {}- end-- it_behaves_like 'invalid params format'- end-- context 'with no field type specified' do- before do- dummy_controller.params = { fields: 'name,slug,price' }- end-- it_behaves_like 'invalid params format'- end-- context 'with type values not comma separated' do- before do- dummy_controller.params = { fields: { product: { values: 'name,slug,price' } } }- end-- it_behaves_like 'invalid params format'- end-- context 'with valid params format' do- before do- dummy_controller.params = { fields: { product: 'name,slug,price' } }- end-- it 'returns specified params' do- expect(dummy_controller.send(:sparse_fields)).to eq(product: [:name, :slug, :price])- end- end- end-- describe '#error_during_processing' do- controller(described_class) do- def index- render plain: { 'products' => [] }.to_json- end- end-- before do- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|- r.draw { get 'index', to: 'spree/api/v2/base#index' }- end- end-- let!(:user) { create :user }- let(:result_class) { Struct.new(:value) }- let(:result) { result_class.new({message: 'foo'}) }-- shared_examples 'rescues from error' do- it do- expect(subject).to receive(:index).and_raise(exception)- expect(subject).to receive(:spree_current_user).at_least(:once).and_return(user)- expect(Rails.error).to receive(:report).with(exception, context: { user_id: user.id }, source: 'spree.api')- get :index, params: { token: 'exception-message' }- expect(json_response).to eql('error' => 'foo')- end- end-- context 'ArgumentError' do- let(:exception) { ArgumentError.new('foo') }-- it_behaves_like 'rescues from error'- end-- context 'ActionDispatch::Http::Parameters::ParseError' do- let(:exception) { ActionDispatch::Http::Parameters::ParseError.new }-- before { expect($!).to receive(:message).and_return('foo') }-- it_behaves_like 'rescues from error'- end- end-- describe '#serializer_params' do- let(:store) { @default_store }- let(:currency) { store.default_currency }- let(:locale) { store.default_locale }- let(:user) { nil }- let(:price_options) { { tax_zone: Spree::Zone.new } }-- shared_examples 'returns proper values' do- before do- allow(dummy_controller).to receive(:params).and_return(ActionController::Parameters.new)- allow(dummy_controller).to receive(:current_store).and_return(store)- allow(dummy_controller).to receive(:current_currency).and_return(currency)- allow(dummy_controller).to receive(:current_locale).and_return(locale)- allow(dummy_controller).to receive(:spree_current_user).and_return(user)- allow(dummy_controller).to receive(:current_price_options).and_return(price_options)- end-- let(:serializer_params) { dummy_controller.send(:serializer_params) }-- it 'contains the expected hash serializer keys' do- expect(serializer_params.keys).to match_array(%i[currency image_transformation locale price_options store taxon_image_transformation user])- end-- it do- expect(serializer_params).to eq(- {- store: store,- currency: currency,- price_options: price_options,- user: user,- locale: locale,- image_transformation: nil,- taxon_image_transformation: nil- }- )- end- end-- context 'default values' do- it_behaves_like 'returns proper values'- end-- context 'non-default values' do- let(:user) { create(:user) }- let(:currency) { 'EUR' }- let(:locale) { 'de' }- let(:store) { create(:store, default_locale: locale, default_currency: currency) }-- it_behaves_like 'returns proper values'- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/api/v2/platform/resource_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/api/v2/platform/resource_controller_spec.rbdeleted file mode 100644index d832847b52..0000000000--- a/legacy_api_v2/spec/controllers/spree/api/v2/platform/resource_controller_spec.rb+++ /dev/null@@ -1,78 +0,0 @@-require 'spec_helper'--class PlatformApiDummyController < Spree::Api::V2::Platform::ResourceController- private-- def model_class- Spree::Product- end-end--describe Spree::Api::V2::Platform::ResourceController, type: :controller do- let(:dummy_controller) { PlatformApiDummyController.new }- let(:store) { @default_store }-- describe '#resource_serializer' do- subject { dummy_controller.send(:resource_serializer) }-- it { expect(subject).to be Spree::Api::V2::Platform::ProductSerializer }- end-- describe '#collection_serializer' do- it { expect(dummy_controller.send(:collection_serializer)).to be Spree::Api::V2::Platform::ProductSerializer }- end-- describe '#collection' do- let!(:product) { create(:product, stores: [store]) }- let!(:product_from_another_store) { create(:product, stores: [create(:store)]) }- let(:collection) { dummy_controller.send(:collection) }-- before do- dummy_controller.params = {}- allow(dummy_controller).to receive(:current_store).and_return(store)- allow(dummy_controller).to receive(:spree_current_user).and_return(nil)- end-- it 'returns collection of records from the current store' do- expect(collection.first).to be_instance_of(Spree::Product)- expect(collection.count).to eq(store.products.count)- expect(collection.map(&:id)).to include(product.id)- expect(collection.map(&:id)).not_to include(product_from_another_store.id)- end- end-- describe '#permitted_resource_params' do- let(:valid_attributes) do- {- product: {- name: 'Test'- }- }- end-- before do- dummy_controller.params = valid_attributes- end-- it { expect(dummy_controller.send(:permitted_resource_params)).to eq(ActionController::Parameters.new(valid_attributes).require(:product).permit!) }-- context 'when model supports metafields' do- before do- allow(dummy_controller).to receive(:model_class).and_return(Spree::Product)- end-- let!(:metafield_definition) { create(:metafield_definition, :short_text_field, resource_type: Spree::Product) }-- let(:valid_attributes) do- {- product: {- name: 'Test',- metafields_attributes: [{ metafield_definition_id: metafield_definition.id, value: 'Test' }]- }- }- end-- it { expect(dummy_controller.send(:permitted_resource_params)).to include(:metafields_attributes) }- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/api/v2/resource_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/api/v2/resource_controller_spec.rbdeleted file mode 100644index 28a9f4f092..0000000000--- a/legacy_api_v2/spec/controllers/spree/api/v2/resource_controller_spec.rb+++ /dev/null@@ -1,75 +0,0 @@-require 'spec_helper'--class ApiV2DummyController < Spree::Api::V2::ResourceController- private-- def model_class- Spree::Product- end-end--describe Spree::Api::V2::ResourceController, type: :controller do- let(:dummy_controller) { ApiV2DummyController.new }- let(:store) { @default_store }-- describe '#finder_params' do- let(:currency) { store.default_currency }- let(:locale) { store.default_locale }- let(:user) { nil }- let(:params) { {} }-- shared_examples 'returns proper values' do- before do- allow(dummy_controller).to receive(:current_store).and_return(store)- allow(dummy_controller).to receive(:current_currency).and_return(currency)- allow(dummy_controller).to receive(:current_locale).and_return(locale)- allow(dummy_controller).to receive(:spree_current_user).and_return(user)- allow(dummy_controller).to receive(:params).and_return(params)- end-- it do- expect(dummy_controller.send(:finder_params)).to eq(- params.merge(- store: store,- currency: currency,- user: user,- locale: locale- )- )- end- end-- context 'default values' do- it_behaves_like 'returns proper values'- end-- context 'non-default values' do- let(:user) { create(:user) }- let(:currency) { 'EUR' }- let(:locale) { 'de' }- let(:store) { create(:store, default_locale: locale, default_currency: currency) }- let(:params) { { filter: {}, page: 1, per_page: 10 } }-- it_behaves_like 'returns proper values'- end- end-- describe '#collection' do- let!(:product) { create(:product, stores: [store]) }- let!(:product_from_another_store) { create(:product, stores: [create(:store)]) }- let(:collection) { dummy_controller.send(:collection) }-- before do- dummy_controller.params = {}- allow(dummy_controller).to receive(:current_store).and_return(store)- allow(dummy_controller).to receive(:spree_current_user).and_return(nil)- end-- it 'returns collection of records from the current store' do- expect(collection.first).to be_instance_of(Spree::Product)- expect(collection.count).to eq(store.products.count)- expect(collection.map(&:id)).to include(product.id)- expect(collection.map(&:id)).not_to include(product_from_another_store.id)- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/api/v2/storefront/account/addresses_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/api/v2/storefront/account/addresses_controller_spec.rbdeleted file mode 100644index e52ef5d63e..0000000000--- a/legacy_api_v2/spec/controllers/spree/api/v2/storefront/account/addresses_controller_spec.rb+++ /dev/null@@ -1,234 +0,0 @@-require 'spec_helper'--describe 'Spree::Api::V2::Storefront::Account::AddressesController', type: :request do- let!(:user) { create(:user_with_addresses) }- let!(:addresses) { create_list(:address, 1, user_id: user.id, country: country, state: state) }- let!(:country) { create(:country) }- let!(:state) { create(:state, country: country) }- let(:params) { { address: new_attributes } }-- include_context 'API v2 tokens'-- describe 'addresses#create' do- subject :post_create do- post '/api/v2/storefront/account/addresses', params: params, headers: headers_bearer- end-- context 'valid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: 'England',- country_id: country.id- }- end-- it 'returns created address attributes' do- post_create-- expect(json_response['data']).to have_attribute(:firstname).with_value(new_attributes[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(new_attributes[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(new_attributes[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(new_attributes[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(new_attributes[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(new_attributes[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(new_attributes[:zipcode])- expect(json_response['data']).to have_attribute(:state_name).with_value(new_attributes[:state_name])- expect(json_response.size).to eq(1)- end-- it 'creates address' do- expect{ post_create }.to change { Spree::Address.count }.by(1)- end- end-- context 'invalid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor'- }- end-- it 'returns errors' do- post_create-- expect(json_response['error']).to eq("City can't be blank, Country can't be blank, Zip Code can't be blank")- expect(json_response['errors']).to eq(- 'city' => ["can't be blank"],- 'zipcode' => ["can't be blank"],- 'country' => ["can't be blank"]- )- end-- it 'does not create address' do- expect{ post_create }.to change { Spree::Address.count }.by(0)- end- end-- context 'with missing authorization token' do- before { post '/api/v2/storefront/account/addresses' }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'addresses#update' do- subject :patch_update do- patch "/api/v2/storefront/account/addresses/#{address.id}", params: params, headers: headers_bearer- end-- let(:address) { addresses.last }-- context 'when address is editable' do- context 'valid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: state.name,- }- end-- it 'updates and returns address' do- patch_update-- expect(json_response['data']).to have_id(address.id.to_s)- expect(json_response['data']).to have_attribute(:firstname).with_value(new_attributes[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(new_attributes[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(new_attributes[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(new_attributes[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(new_attributes[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(new_attributes[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(new_attributes[:zipcode])- expect(json_response['data']).to have_attribute(:state_name).with_value(new_attributes[:state_name])- expect(json_response.size).to eq(1)- end-- it 'does not create new address' do- expect{ patch_update }.to change { Spree::Address.count }.by(0)- end- end-- context 'invalid request' do- let(:new_attributes) do- {- firstname: '',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: state.name,- }- end-- it 'returns errors' do- patch_update-- expect(json_response['error']).to eq("First Name can't be blank")- expect(json_response['errors']).to eq(- 'firstname' => ["can't be blank"]- )- end-- it 'does not update address' do- expect { patch_update }.not_to change { address }- end- end- end-- context 'when address is not editable' do- let!(:complete_order) { create(:completed_order_with_totals, ship_address: address) }-- context 'valid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: state.name,- }- end-- it 'returns created address attributes' do- patch_update-- expect(json_response['data']).to have_attribute(:firstname).with_value(new_attributes[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(new_attributes[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(new_attributes[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(new_attributes[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(new_attributes[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(new_attributes[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(new_attributes[:zipcode])- expect(json_response['data']).to have_attribute(:state_name).with_value(new_attributes[:state_name])- expect(json_response.size).to eq(1)- end-- it 'creates address' do- expect{ patch_update }.to change { Spree::Address.count }.by(1)- end-- it 'sets deleted_at attribute of original address' do- Timecop.freeze(Time.current) do- expect(address.deleted_at).to be_nil-- patch_update-- expect(address.reload.deleted_at).not_to be nil- end- end- end-- context 'invalid request' do- let(:new_attributes) do- {- firstname: '',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: '',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: state.name,- }- end-- it 'returns errors' do- patch_update-- expect(json_response['error']).to eq("City can't be blank")- expect(json_response['errors']).to eq('city' => ["can't be blank"])- end-- it 'does not update address' do- expect { patch_update }.not_to change { address }- end- end- end-- context 'with missing authorization token' do- before { patch "/api/v2/storefront/account/addresses/#{address.id}" }-- it_behaves_like 'returns 403 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/controllers/spree/api/v2/storefront/checkout_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/api/v2/storefront/checkout_controller_spec.rbdeleted file mode 100644index 8cc43fd005..0000000000--- a/legacy_api_v2/spec/controllers/spree/api/v2/storefront/checkout_controller_spec.rb+++ /dev/null@@ -1,78 +0,0 @@-require 'spec_helper'--describe 'Spree::Api::V2::Storefront::CheckoutController', type: :request do- let(:user) { create(:user_with_addresses) }- let(:params) { { order: order_attributes } }- let(:store) { @default_store }-- include_context 'API v2 tokens'-- describe 'checkout#update' do- subject :patch_update do- patch '/api/v2/storefront/checkout', params: params, headers: headers_bearer- end-- let(:order) { create(:order_with_line_items, user: user, state: 'address', store: store, bill_address_id: nil, ship_address_id: nil) }- let(:headers_bearer) { { 'X-Spree-Order-Token' => order.token } }-- context 'with address attributes' do- context 'with new address attributes' do- let(:order_attributes) do- {- bill_address_attributes: {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: 'England',- country_id: create(:country).id- }- }- end-- it 'updates address from new attributes' do- expect { patch_update }.to change { order.reload.bill_address&.firstname }.to('John')- end- end-- context 'with existing address attributes' do- let(:order_attributes) do- {- bill_address_id: existing_address.id- }- end-- context 'with logged in user' do- let(:existing_address) { create(:address, user: user) }-- it 'updates address from existing address' do- expect { patch_update }.to change { order.reload.bill_address_id }.from(nil).to(existing_address.id)- end- end-- context 'with guest user' do- let(:user) { nil }-- context 'with address that belongs to existing user' do- let(:existing_address) { create(:address, user: create(:user)) }-- it 'does not update guest user address' do- expect { patch_update }.not_to change { order.reload.bill_address_id }- end- end-- context 'with address that belongs to guest user' do- let(:existing_address) { create(:address, user: nil) }-- it 'does not update guest user address' do- expect { patch_update }.not_to change { order.reload.bill_address_id }- end- end- end- end- end- end-enddiff --git a/legacy_api_v2/spec/models/legacy_user_spec.rb b/legacy_api_v2/spec/models/legacy_user_spec.rbdeleted file mode 100644index 9038718946..0000000000--- a/legacy_api_v2/spec/models/legacy_user_spec.rb+++ /dev/null@@ -1,19 +0,0 @@-require 'spec_helper'--module Spree- describe LegacyUser, type: :model do- let(:user) { LegacyUser.new }-- it 'can generate an API key' do- expect(user).to receive(:save!)- user.generate_spree_api_key!- expect(user.spree_api_key).not_to be_blank- end-- it 'can clear an API key' do- expect(user).to receive(:save!)- user.clear_spree_api_key!- expect(user.spree_api_key).to be_blank- end- end-enddiff --git a/legacy_api_v2/spec/models/oauth_application_spec.rb b/legacy_api_v2/spec/models/oauth_application_spec.rbdeleted file mode 100644index 7c1c99a873..0000000000--- a/legacy_api_v2/spec/models/oauth_application_spec.rb+++ /dev/null@@ -1,28 +0,0 @@-require 'spec_helper'-require 'bcrypt'--module Spree- describe OauthApplication, type: :model do- subject { build(:oauth_application) }-- it 'creates a valid oauth application' do- expect(subject).to be_valid- end-- it 'assigns client id and secret' do- expect { subject.save! }.to change(subject, :uid).and change(subject, :secret)- end-- it 'can access plain text secret only once after save' do- subject.save!- expect(subject.plaintext_secret).to be_present- expect(described_class.last.plaintext_secret).to be_nil- end-- it 'encrypts secret' do- subject.save!- expect(subject.secret).not_to eq(subject.plaintext_secret)- expect(BCrypt::Password.new(subject.secret)).to eq(subject.plaintext_secret)- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/errors_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/errors_spec.rbdeleted file mode 100644index 4b2bab8825..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/errors_spec.rb+++ /dev/null@@ -1,55 +0,0 @@-require 'spec_helper'--describe 'API v2 Errors spec', type: :request do- context 'record not found' do- before { get '/api/v2/storefront/products/product-that-doesn-t-exist' }-- it 'returns proper error message' do- expect(response.status).to eq(404)- expect(json_response['error']).to eq('The resource you were looking for could not be found.')- end- end-- context 'authorization failure' do- let(:user) { create(:user) }- let(:another_user) { create(:user) }- let!(:order) { create(:order, user: another_user) }-- include_context 'API v2 tokens'-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::CartController).to receive(:spree_current_order).and_return(order)- patch '/api/v2/storefront/cart/empty', headers: headers_bearer- end-- it 'returns proper error message' do- expect(response.status).to eq(403)- expect(json_response['error']).to eq('You are not authorized to access this page.')- end-- it 'calls error handler' do- expect(Rails.error).to receive(:report).with(- instance_of(CanCan::AccessDenied),- context: { user_id: user.id },- source: 'spree.api'- )-- patch '/api/v2/storefront/cart/empty', headers: headers_bearer- end- end-- context 'expired token failure' do- let(:user) { create(:user) }- let(:headers) { headers_bearer }-- include_context 'API v2 tokens'-- before do- token.expires_in = -1- token.save- get '/api/v2/storefront/account', headers: headers- end-- it_behaves_like 'returns 401 HTTP status'- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/data_feeds/google_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/data_feeds/google_spec.rbdeleted file mode 100644index e033a1a7f7..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/data_feeds/google_spec.rb+++ /dev/null@@ -1,32 +0,0 @@-require 'spec_helper'--describe 'Data Feeds API Google Feed', type: :request do- subject { get '/api/v2/data_feeds/google/test-feed.rss' }-- let(:store) { @default_store }-- context 'when a feed with given permalink does not exist' do- before { subject }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'when there is a feed with a given slug' do- before do- create(:google_data_feed, store: store, slug: 'test-feed', active: active)- subject- end-- context 'when the feed is active' do- let(:active) { true }-- it_behaves_like 'returns 200 HTTP status'- end-- context 'when the feed is not active' do- let(:active) { false }-- it_behaves_like 'returns 404 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/digitals_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/digitals_spec.rbdeleted file mode 100644index ce2d56fed8..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/digitals_spec.rb+++ /dev/null@@ -1,25 +0,0 @@-require 'spec_helper'--describe 'Platform API v2 Digitals spec', type: :request do- subject { post '/api/v2/platform/digitals', headers: bearer_token, params: params }-- include_context 'API v2 tokens'- include_context 'Platform API v2'- include ActionDispatch::TestProcess::FixtureFile-- let(:bearer_token) { { 'Authorization' => valid_authorization } }- let(:params) { { digital: { variant_id: variant.id.to_s, attachment: file_upload } } }- let(:variant) { create(:variant) }- let(:file_upload) { fixture_file_upload(file_fixture('icon_256x256.jpg'), 'image/jpg') }-- context 'valid request' do- it 'returns status created' do- subject- expect(response).to have_http_status :created- end-- it 'creates a blob ' do- expect { subject }.to change { ActiveStorage::Blob.count }.from(0).to(1)- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/line_items_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/line_items_spec.rbdeleted file mode 100644index dd8fee0f4c..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/line_items_spec.rb+++ /dev/null@@ -1,148 +0,0 @@-require 'spec_helper'--describe 'API V2 Platform Line Items Spec' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- let!(:line_items) { create_list(:line_item, 5) }-- describe 'line_items#index' do- context 'with no params' do- before { get '/api/v2/platform/line_items', headers: bearer_token }-- it 'returns all line_items' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].first).to have_type('line_item')- end- end-- context 'filtering' do- context 'by order_id' do- let(:order) { create(:order, store: store) }- let!(:line_item) { create(:line_item, order: order) }-- before { get "/api/v2/platform/line_items?filter[order_id_eq]=#{order.id}", headers: bearer_token }-- it 'returns line items from this order' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first['id']).to eq line_item.id.to_s- end- end-- context 'by price' do- let(:order) { create(:order, store: store) }- let!(:line_item) { create(:line_item, order: order, price: 100) }-- before { get "/api/v2/platform/line_items?filter[price_gteq]=100", headers: bearer_token }-- it 'returns line items with price greater than or equal to the given price' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first['id']).to eq line_item.id.to_s- end- end-- context 'by variant name' do- before { get "/api/v2/platform/line_items?filter[variant_product_name_or_variant_sku_cont]=#{line_items.first.variant.name}", headers: bearer_token }-- it 'returns line items with correct variant name' do- expect(json_response['data'].count).to eq 1- end- end- end-- context 'sorting' do- context 'by price' do- before { store.line_items.each_with_index { |p, i| p.update(price: p.price + i) } }-- context 'ascending order' do- before { get '/api/v2/platform/line_items?sort=price', headers: bearer_token }-- it 'returns line items sorted by price' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(price: :asc).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/line_items?sort=-price', headers: bearer_token }-- it 'returns line items sorted by price with descending order' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(price: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'by updated_at' do- context 'ascending order' do- before { get '/api/v2/platform/line_items?sort=updated_at', headers: bearer_token }-- it 'returns line items sorted by updated_at' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(:updated_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/line_items?sort=-updated_at', headers: bearer_token }-- it 'returns line items sorted by updated_at with descending order' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(updated_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'by created_at' do- context 'ascending order' do- before { get '/api/v2/platform/line_items?sort=created_at', headers: bearer_token }-- it 'returns line items sorted by created_at' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(:created_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/line_items?sort=-created_at', headers: bearer_token }-- it 'returns line items sorted by created_at with descending order' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['data'].pluck(:id)).to eq store.line_items.order(created_at: :desc).map(&:id).map(&:to_s)- end- end- end- end-- context 'paginate line items' do- context 'with specified pagination params' do- context 'when per_page is between 1 and default value' do- before { get '/api/v2/platform/line_items?page=1&per_page=2', headers: bearer_token }-- it 'returns the default number of line items' do- expect(json_response['data'].count).to eq 2- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq store.line_items.count- expect(json_response['links']['self']).to include('/api/v2/platform/line_items?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/platform/line_items?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/platform/line_items?page=1&per_page=2')- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/platform/line_items', headers: bearer_token }-- it 'returns specified amount line items' do- expect(json_response['data'].count).to eq store.line_items.count- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).to eq store.line_items.count- expect(json_response['links']['self']).to include('/api/v2/platform/line_items')- expect(json_response['links']['next']).to include('/api/v2/platform/line_items?page=1')- expect(json_response['links']['prev']).to include('/api/v2/platform/line_items?page=1')- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/number_resources_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/number_resources_spec.rbdeleted file mode 100644index de61d11927..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/number_resources_spec.rb+++ /dev/null@@ -1,43 +0,0 @@-require 'spec_helper'--describe 'API V2 Number Resources Spec' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- let(:order) { create(:order, store: store, total: 100) }-- describe 'orders#show' do- context 'can fetch order by the number' do- before do- get "/api/v2/platform/orders/#{order.number}", headers: bearer_token- end-- it_behaves_like 'returns 200 HTTP status'- end- end-- describe 'shipments#show' do- let(:shipment) { create(:shipment, order: order) }-- context 'can fetch order by the number' do- before do- get "/api/v2/platform/shipments/#{shipment.number}", headers: bearer_token- end-- it_behaves_like 'returns 200 HTTP status'- end- end-- describe 'payments#show' do- let(:payment) { create(:payment, order: order) }-- context 'can fetch order by the number' do- before do- get "/api/v2/platform/payments/#{payment.number}", headers: bearer_token- end-- it_behaves_like 'returns 200 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/payment_methods_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/payment_methods_spec.rbdeleted file mode 100644index 75ce8784ed..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/payment_methods_spec.rb+++ /dev/null@@ -1,73 +0,0 @@-require 'spec_helper'--describe 'Platform API v2 Payment Methods', type: :request do- include_context 'API v2 tokens'- include_context 'Platform API v2'-- let!(:store) { @default_store }-- let!(:resource_a) { create(:payment_method, stores: [store]) }- let!(:resource_b) { create(:payment_method, stores: [store]) }- let!(:resource_c) { create(:payment_method, stores: [store]) }- let!(:resource_d) { create(:payment_method, stores: [store]) }- let!(:resource_e) { create(:payment_method, stores: [store]) }-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- describe 'payment_methods#update' do- context 'move resource_a from position 1 down to position 5' do- let(:params) do- {- payment_method: { position: 5 }- }- end-- before do- patch "/api/v2/platform/payment_methods/#{resource_a.id}", headers: bearer_token, params: params- end-- it_behaves_like 'returns 200 HTTP status'-- it 'moves resource_a from position 1 to position 5 and updates the positions of its siblings accordingly' do- reload_sections-- expect(resource_b.position).to eq(1)- expect(resource_c.position).to eq(2)- expect(resource_d.position).to eq(3)- expect(resource_e.position).to eq(4)- expect(resource_a.position).to eq(5)- end- end-- context 'can move position and update other attribute' do- let(:params) do- {- payment_method: {- name: 'Rename resource and update Position!',- position: 1- }- }- end-- before do- patch "/api/v2/platform/payment_methods/#{resource_d.id}", headers: bearer_token, params: params- end-- it_behaves_like 'returns 200 HTTP status'-- it 'moves resource_d from position 4 to position 1, and updates the name' do- reload_sections- expect(resource_d.position).to eq(1)- expect(resource_d.name).to eq('Rename resource and update Position!')- end- end-- def reload_sections- resource_a.reload- resource_b.reload- resource_c.reload- resource_d.reload- resource_e.reload- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/products_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/products_spec.rbdeleted file mode 100644index 2703b410e9..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/products_spec.rb+++ /dev/null@@ -1,369 +0,0 @@-require 'spec_helper'--describe 'API V2 Platform Products Spec' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- let!(:products) { create_list(:product, 5, stores: [store]) }- let(:taxonomy) { create(:taxonomy, store: store) }- let!(:taxon) { taxonomy.root }- let(:product_with_taxon) { create(:product, taxons: [taxon], stores: [store]) }- let(:product_with_name) { create(:product, name: 'Test Product', stores: [store]) }- let(:product_with_price) { create(:product, price: 13.44, stores: [store]) }- let!(:option_type) { create(:option_type) }- let!(:option_value) { create(:option_value, option_type: option_type) }- let(:product_with_option) { create(:product, option_types: [option_type], stores: [store]) }- let!(:variant) { create(:variant, product: product_with_option, option_values: [option_value]) }- let(:product) { create(:product, stores: [store]) }- let!(:deleted_product) { create(:product, deleted_at: Time.current - 1.day, stores: [store]) }- let!(:discontinued_product) { create(:product, discontinue_on: Time.current - 1.day, stores: [store]) }- let!(:not_available_product) { create(:product, status: 'draft', stores: [store]) }- let!(:in_stock_product) { create(:product_in_stock, stores: [store]) }- let!(:not_backorderable_product) { create(:product_in_stock, :without_backorder, stores: [store]) }- let!(:property) { create(:property) }- let!(:new_property) { create(:property) }- let!(:product_with_property) { create(:product, stores: [store]) }- let!(:product_property) { create(:product_property, property: new_property, product: product_with_property, value: 'Some Value') }- let!(:product_property2) { create(:product_property, property: property, product: product_with_property, value: 'Some Value 2') }-- describe 'products#index' do- context 'with no params' do- before { get '/api/v2/platform/products', headers: bearer_token }-- it 'returns all products' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].first).to have_type('product')- end- end-- context 'when product associated with two stores' do- let!(:new_store_taxonomy) { create(:taxonomy, store: store) }- let(:store2) { create(:store) }- let(:taxonomy2) { create(:taxonomy, store: store2) }- let!(:taxon2) { taxonomy2.root }-- before do- product_with_taxon.stores << store2- product_with_taxon.taxons << taxon2- end-- shared_examples 'should not return not related taxon' do- it do- expect(json_response['data'][0]).not_to have_relationship(:taxons).with_data([{ 'id' => new_store_taxonomy.id.to_s, 'type' => 'taxon' }])- end- end- end-- context 'current store' do- let(:store_2) { create(:store) }- let!(:product_from_another_store) { create(:product, stores: [store_2]) }-- before { get '/api/v2/platform/products', headers: bearer_token }-- it 'returns products from this store only' do- expect(json_response['data'].count).to eq store.products.count- product_ids = json_response['data'].pluck(:id)-- expect(product_ids).not_to include(product_from_another_store.id)- expect(product_ids).to match_array(store.products.ids.map(&:to_s))- end- end-- context 'sort products' do- context 'sorting by price' do- before { store.products.each_with_index { |p, i| p.update(price: p.price + i) } }-- context 'ascending order' do- before { get '/api/v2/platform/products?sort=price', headers: bearer_token }-- it 'returns products sorted by price' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.joins(variants_including_master: :prices).select("#{store.products.table_name}.*, #{Spree::Price.table_name}.amount").distinct.order("#{Spree::Price.table_name}.amount").map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/products?sort=-price', headers: bearer_token }-- it 'returns products sorted by price with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.joins(variants_including_master: :prices).select("#{store.products.table_name}.*, #{Spree::Price.table_name}.amount").distinct.order("#{Spree::Price.table_name}.amount DESC").map(&:id).map(&:to_s)- end- end- end-- context 'sorting by name' do- context 'A-Z' do- before { get '/api/v2/platform/products?sort=name', headers: bearer_token }-- it 'returns products sorted by name' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(:name).map(&:id).map(&:to_s)- end- end-- context 'Z-A' do- before { get '/api/v2/platform/products?sort=-name', headers: bearer_token }-- it 'returns products sorted by name with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(name: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by updated_at' do- context 'ascending order' do- before { get '/api/v2/platform/products?sort=updated_at', headers: bearer_token }-- it 'returns products sorted by updated_at' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(:updated_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/products?sort=-updated_at', headers: bearer_token }-- it 'returns products sorted by updated_at with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(updated_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by created_at' do- context 'ascending order' do- before { get '/api/v2/platform/products?sort=created_at', headers: bearer_token }-- it 'returns products sorted by created_at' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(:created_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/products?sort=-created_at', headers: bearer_token }-- it 'returns products sorted by created_at with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(created_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by available_on' do- before { store.products.each_with_index { |p, i| p.update(available_on: Time.current - i.days) } }-- context 'ascending order' do- before { get '/api/v2/platform/products?sort=available_on', headers: bearer_token }-- it 'returns products sorted by available_on' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(:available_on).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/products?sort=-available_on', headers: bearer_token }-- it 'returns products sorted by available_on with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(available_on: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by make_active_at' do- before { store.products.each_with_index { |p, i| p.update(make_active_at: Time.current - i.days) } }-- context 'ascending order' do- before { get '/api/v2/platform/products?sort=make_active_at', headers: bearer_token }-- it 'returns products sorted by make_active_at' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(:make_active_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/products?sort=-make_active_at', headers: bearer_token }-- it 'returns products sorted by make_active_at with descending order' do- expect(json_response['data'].count).to eq store.products.count- expect(json_response['data'].pluck(:id)).to eq store.products.order(make_active_at: :desc).map(&:id).map(&:to_s)- end- end- end- end-- context 'paginate products' do- context 'with specified pagination params' do- context 'when per_page is between 1 and default value' do- before { get '/api/v2/platform/products?page=1&per_page=2', headers: bearer_token }-- it 'returns the default number of products' do- expect(json_response['data'].count).to eq 2- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq store.products.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/platform/products?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/platform/products?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/platform/products?page=1&per_page=2')- end- end-- context 'when per_page is above the default value' do- before { get '/api/v2/platform/products?page=1&per_page=8', headers: bearer_token }-- it 'returns the per_page number of products' do- expect(json_response['data'].count).to eq 8- end- end-- context 'when per_page is less than 0' do- before { get '/api/v2/platform/products?page=1&per_page=-1', headers: bearer_token }-- it 'returns the max or default number of products' do- expect(json_response['data'].count).to eq 11- end- end-- context 'when per_page is equal 0' do- before { get '/api/v2/platform/products?page=1&per_page=0', headers: bearer_token }-- it 'returns the max or default number of products' do- expect(json_response['data'].count).to eq 11- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/platform/products', headers: bearer_token }-- it 'returns specified amount products' do- expect(json_response['data'].count).to eq store.products.count- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).to eq store.products.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/platform/products')- expect(json_response['links']['next']).to include('/api/v2/platform/products?page=1')- expect(json_response['links']['prev']).to include('/api/v2/platform/products?page=1')- end- end- end-- context 'fetch products by curency param' do- before { store.update(supported_currencies: 'USD,EUR,GBP') }-- context 'with default currency' do- before { get '/api/v2/platform/products?currency=USD', headers: bearer_token }-- it 'returns products' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'][0]['attributes']['currency']).to eq 'USD'- expect(json_response['data'].count).to eq store.products.count- end- end- end-- context 'filtering' do- before { get "/api/v2/platform/products?filter[name_cont]=#{in_stock_product.name}", headers: bearer_token }-- it 'returns line items with correct variant name' do- expect(json_response['data'].count).to eq 1- end- end- end-- describe 'products#update' do- context 'with metadata' do- let(:public_metadata) { { 'foo' => 'bar' } }- let(:private_metadata) { { 'baz' => 'qux' } }-- before { put "/api/v2/platform/products/#{product.id}", params: { product: { public_metadata: public_metadata, private_metadata: private_metadata } }, headers: bearer_token }-- it 'returns product with metadata' do- expect(json_response['data']['attributes']['public_metadata']).to eq public_metadata- expect(json_response['data']['attributes']['private_metadata']).to eq private_metadata- end-- it 'does not clear metadata when param is missing' do- put "/api/v2/platform/products/#{product.id}", params: { product: { name: 'New name' } }, headers: bearer_token-- expect(json_response['data']['attributes']['public_metadata']).to eq public_metadata- expect(json_response['data']['attributes']['private_metadata']).to eq private_metadata- end- end-- context 'with metafields' do- let(:metafield_definition) { create(:metafield_definition, :short_text_field, resource_type: Spree::Product) }-- let(:params) { { product: { metafields_attributes: [{ metafield_definition_id: metafield_definition.id, value: 'Test' }] }, include: 'metafields' } }-- before { put "/api/v2/platform/products/#{product.id}", params: params, headers: bearer_token }-- it 'returns product with metafields' do- product.reload-- expect(product.has_metafield?(metafield_definition.full_key)).to be_truthy-- expect(json_response['included'].count).to eq 1- expect(json_response['included'].first['type']).to eq 'metafield'- expect(json_response['included'].first['attributes']['name']).to eq metafield_definition.name- expect(json_response['included'].first['attributes']['type']).to eq 'Spree::Metafields::ShortText'- expect(json_response['included'].first['attributes']['value']).to eq 'Test'- expect(json_response['included'].first['attributes']['display_on']).to eq 'both'- expect(json_response['included'].first['attributes']['key']).to eq metafield_definition.full_key- end- end- end-- describe 'products#show' do- context 'with product image data' do- shared_examples 'returns product image data' do- it 'returns product image data' do- expect(json_response['data']['relationships']['images'].count).to eq(1)- expect(json_response['included'].count).to eq(1)- expect(json_response['included'].first['type']).to eq('image')- end- end-- let!(:image) { create(:image, viewable: product.master) }- let(:image_json_data) { json_response['included'].first['attributes'] }-- before { get "/api/v2/platform/products/#{product.id}?include=images#{image_transformation_params}", headers: bearer_token }-- context 'when no image transformation params are passed' do- let(:image_transformation_params) { '' }-- it_behaves_like 'returns product image data'-- it 'returns product image' do- expect(image_json_data['transformed_url']).to be_nil- end- end-- context 'when product image json returned' do- let(:image_transformation_params) { '&image_transformation[size]=100x50&image_transformation[quality]=50' }-- it_behaves_like 'returns product image data'-- it 'returns product image' do- expect(image_json_data['transformed_url']).not_to be_nil- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/promotions_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/promotions_spec.rbdeleted file mode 100644index c400511c07..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/promotions_spec.rb+++ /dev/null@@ -1,148 +0,0 @@-require 'spec_helper'--describe 'Promotion API v2 spec', type: :request do- include_context 'API v2 tokens'- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }- let!(:store) { @default_store }- let(:second_store) { create(:store) }- let(:third_store) { create(:store) }-- let(:promotion_rule) { create(:promotion_rule) }- let(:existing_promotion) { create(:promotion_with_item_adjustment, promotion_rules: [promotion_rule]) }- let(:promotion_category) { create(:promotion_category, code: 'o8ehG', name: 'Super Saver Promotions') }- let(:promotion_category_two) { create(:promotion_category, code: 'XiP83df-u', name: 'Promotions From 2018') }-- let(:new_promotion_attributes) do- {- name: 'Cyber Monday Sale',- code: 'CM-20',- promotion_category_id: promotion_category.id.to_s,- match_policy: 'all',- type: 'Spree::Promotion',- description: 'Save big this Cyber Monday - First 100 Customers save 20%',- starts_at: '2021-10-20 13:09:00 UTC',- expires_at: '2021-10-25 13:09:00 UTC',- usage_limit: 100,- path: '/cyber-monday/today',- advertise: true,- store_ids: [second_store.id.to_s],- promotion_rules_attributes: [- {- code: 'ESJD',- type: 'Spree::Promotion::Rules::User'- }- ],- promotion_actions_attributes: [- {- type: 'Spree::Promotion::Actions::FreeShipping',- position: 1- }- ]- }- end-- let(:update_promotion_attributes) do- {- name: 'Black Friday Sale',- code: 'BF-20',- promotion_category_id: promotion_category.id.to_s,- match_policy: 'any',- type: 'Spree::Promotion',- description: 'Black Friday Saver - First 100 Customers save 20%',- starts_at: '2021-10-20 13:09:00 UTC',- expires_at: '2021-10-25 13:09:00 UTC',- usage_limit: 100,- path: '/black-fri/today',- advertise: true,- store_ids: [second_store.id.to_s, third_store.id.to_s],- promotion_rules_attributes: [- {- id: existing_promotion.promotion_rules.first.id.to_s,- code: 'PliDp9328',- type: 'Spree::Promotion::Rules::User'- }- ],- promotion_actions_attributes: [- {- id: existing_promotion.promotion_actions.first.id.to_s,- type: 'Spree::Promotion::Actions::FreeShipping'- }- ]- }- end-- describe 'promotions#create' do- context 'with valid params' do- before { post '/api/v2/platform/promotions?include=promotion_category,promotion_actions,promotion_rules,stores', params: params, headers: bearer_token }-- let(:params) { { promotion: new_promotion_attributes } }-- it 'creates and returns a promotion' do- # promotion- expect(json_response['data']).to have_attribute(:name).with_value(new_promotion_attributes[:name])- expect(json_response['data']).to have_attribute(:code).with_value(new_promotion_attributes[:code].downcase)- expect(json_response['data']).to have_attribute(:match_policy).with_value(new_promotion_attributes[:match_policy])- expect(json_response['data']).to have_attribute(:type).with_value(new_promotion_attributes[:type])- expect(json_response['data']).to have_attribute(:description).with_value(new_promotion_attributes[:description])- expect(json_response['data']).to have_attribute(:starts_at).with_value('2021-10-20T13:09:00.000Z')- expect(json_response['data']).to have_attribute(:expires_at).with_value('2021-10-25T13:09:00.000Z')- expect(json_response['data']).to have_attribute(:usage_limit).with_value(new_promotion_attributes[:usage_limit])- expect(json_response['data']).to have_attribute(:path).with_value(new_promotion_attributes[:path])- expect(json_response['data']).to have_attribute(:advertise).with_value(new_promotion_attributes[:advertise])-- # included promotion_category- expect(json_response['included']).to include(have_type('promotion_category'))- expect(json_response['included'][0]).to eq(Spree::Api::V2::Platform::PromotionCategorySerializer.new(promotion_category).as_json['data'])-- # included promotion_action- expect(json_response['included']).to include(have_type('promotion_action'))- expect(json_response['included'][1]).to have_attribute(:type).with_value('Spree::Promotion::Actions::FreeShipping')-- # included promotion_rule- expect(json_response['included']).to include(have_type('promotion_rule'))- expect(json_response['included'][2]).to have_attribute(:type).with_value('Spree::Promotion::Rules::User')- expect(json_response['included'][2]).to have_attribute(:code).with_value('ESJD')-- expect(json_response['included'].size).to eq 5- end- end-- describe 'promotions#update' do- before { patch "/api/v2/platform/promotions/#{existing_promotion.id}?include=promotion_category,promotion_actions,promotion_rules,stores", params: params, headers: bearer_token }-- let(:params) { { promotion: update_promotion_attributes } }-- it 'updates and returns a promotion' do- # promotion- expect(json_response['data']).to have_attribute(:name).with_value(update_promotion_attributes[:name])- expect(json_response['data']).to have_attribute(:code).with_value(update_promotion_attributes[:code].downcase)- expect(json_response['data']).to have_attribute(:match_policy).with_value(update_promotion_attributes[:match_policy])- expect(json_response['data']).to have_attribute(:type).with_value(update_promotion_attributes[:type])- expect(json_response['data']).to have_attribute(:description).with_value(update_promotion_attributes[:description])- expect(json_response['data']).to have_attribute(:starts_at).with_value('2021-10-20T13:09:00.000Z')- expect(json_response['data']).to have_attribute(:expires_at).with_value('2021-10-25T13:09:00.000Z')- expect(json_response['data']).to have_attribute(:usage_limit).with_value(update_promotion_attributes[:usage_limit])- expect(json_response['data']).to have_attribute(:path).with_value(update_promotion_attributes[:path])- expect(json_response['data']).to have_attribute(:advertise).with_value(update_promotion_attributes[:advertise])-- # included promotion_category- expect(json_response['included']).to include(have_type('promotion_category'))- expect(json_response['included'][0]).to eq(Spree::Api::V2::Platform::PromotionCategorySerializer.new(promotion_category).as_json['data'])- end-- it 'updates and returns the nested resources' do- # included promotion_action- expect(json_response['included']).to include(have_type('promotion_action'))- expect(json_response['included'][1]).to have_attribute(:type).with_value('Spree::Promotion::Actions::FreeShipping')-- # # included promotion_rule- expect(json_response['included']).to include(have_type('promotion_rule'))- expect(json_response['included'][2]).to have_attribute(:type).with_value('Spree::Promotion::Rules::User')- expect(json_response['included'][2]).to have_attribute(:code).with_value('PliDp9328')- expect(json_response['included'].size).to eq 6- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/resources_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/resources_spec.rbdeleted file mode 100644index f0064e2537..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/resources_spec.rb+++ /dev/null@@ -1,543 +0,0 @@-require 'spec_helper'--describe 'Platform API v2 Resources spec', type: :request do- include_context 'API v2 tokens'- include_context 'Platform API v2'-- let!(:store) { @default_store }- let(:store_two) { create(:store) }- let(:store_three) { create(:store) }-- let(:bearer_token) { { 'Authorization' => valid_authorization } }- let(:resource_params) { {} }- let(:params) { { address: resource_params } }- let(:country) { create(:country, states_required: true) }- let(:state) { create(:state, country: country) }- let(:user) { create(:user) }- let(:resource) { create(:address, state: state, country: country, user: user) }- let(:id) { resource.id }-- shared_examples 'returns auth token errors' do- context 'with missing authorization token' do- let(:bearer_token) { nil }-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end-- context 'with wrong authorization token' do- let(:bearer_token) { { 'Authorization' => bogus_authorization } }-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end-- context 'with token not associated with an client application' do- let(:bearer_token) { { 'Authorization' => valid_user_authorization_without_app } }-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end- end-- shared_examples 'returns error when record does not exist' do- let(:id) { 'bogus' }-- before { execute }-- it_behaves_like 'returns 404 HTTP status'- end-- describe '#index' do- let(:params) { }- let(:execute) { get '/api/v2/platform/addresses', headers: bearer_token, params: params }- let!(:resources) { create_list(:address, 5) }- let(:resources_count) { 5 }-- shared_examples 'valid request' do- before { execute }-- it 'returns valid JSON' do- expect(json_response['data'][0]).to have_type(resource.class.json_api_type)- expect(json_response['data'].count).to eq(resources_count)- end- end-- context 'application with access token' do- it_behaves_like 'valid request'-- context 'ransack filtering' do- let(:ids) { resources.last(2).map(&:id) }-- context 'single filter' do- let(:params) { { filter: { 'id_in': ids } } }-- before { execute }-- it 'returns proper resources' do- expect(json_response['data'][0]).to have_type(resource.class.json_api_type)- expect(json_response['data'].count).to eq(2)- expect(json_response['data'].first).to have_id(ids.first.to_s)- expect(json_response['data'].last).to have_id(ids.last.to_s)- end- end-- context 'multiple filters' do- let(:params) { { filter: { 'id_in': ids, firstname_cont: 'Joan' } } }-- before do- resources.last.update(firstname: 'Joanna')- execute- end-- it 'returns proper resources' do- expect(json_response['data'][0]).to have_type(resource.class.json_api_type)- expect(json_response['data'].count).to eq(1)- expect(json_response['data'].first).to have_id(ids.last.to_s)- end- end- end-- context 'pagination' do- context 'when per_page is between 1 and default value' do- let(:params) { { page: 1, per_page: 2 } }-- before { execute }-- it 'returns proper resource count' do- expect(json_response['data'].count).to eq 2- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq resources.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/platform/addresses?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/platform/addresses?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/platform/addresses?page=1&per_page=2')- end- end-- context 'when per_page is above the default value' do- let(:params) { { page: 1, per_page: 10 } }-- before { execute }-- it 'returns the proper resource count' do- expect(json_response['data'].count).to eq resources.count- end- end-- context 'when per_page is less than 0' do- let(:params) { { page: 1, per_page: '-1' } }-- before { execute }-- it 'returns the proper resource count' do- expect(json_response['data'].count).to eq resources.count- end- end-- context 'when per_page is equal 0' do- let(:params) { { page: 1, per_page: 0 } }-- before { execute }-- it 'returns the proper resource count' do- expect(json_response['data'].count).to eq resources.count- end- end- end-- context 'without specified pagination params' do- before { execute }-- it 'returns specified amount resources' do- expect(json_response['data'].count).to eq resources.count- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).to eq resources.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/platform/addresses')- expect(json_response['links']['next']).to include('/api/v2/platform/addresses?page=1')- expect(json_response['links']['prev']).to include('/api/v2/platform/addresses?page=1')- end- end- end-- context 'user with access token' do- let(:bearer_token) { { 'Authorization' => valid_user_authorization } }-- before do- resources.first(3).each { |r| r.update(user: user) }- execute- end-- context 'regular user' do- let(:resources_count) { 3 }-- it_behaves_like 'valid request'- end-- context 'admin user' do- let(:user) { create(:admin_user) }- let(:resources_count) { 5 }-- it_behaves_like 'valid request'- end- end-- it_behaves_like 'returns auth token errors'- end-- describe '#show' do- let(:execute) { get "/api/v2/platform/addresses/#{id}", headers: bearer_token }-- shared_examples 'valid request' do- before { execute }-- it 'returns valid JSON' do- expect(json_response['data']).to have_attribute(:firstname).with_value(resource.firstname)- expect(json_response['data']).to have_attribute(:lastname).with_value(resource.lastname)- expect(json_response['data']).to have_relationships(:state, :country, :user)- end- end-- context 'application with access token' do- it_behaves_like 'valid request'- end-- context 'user with access token' do- let(:bearer_token) { { 'Authorization' => valid_user_authorization } }-- context 'user with access' do- it_behaves_like 'valid request'- end-- context 'user without access' do- let(:another_user) { create(:user) }-- before do- resource.update!(user: another_user)- execute- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'admin user' do- let(:user) { create(:admin_user) }-- it_behaves_like 'valid request'- end- end-- it_behaves_like 'returns auth token errors'- it_behaves_like 'returns error when record does not exist'- end-- describe '#create' do- let(:execute) { post '/api/v2/platform/addresses', params: params, headers: bearer_token }- let(:resource_params) { build(:address, country: country, state: state, user: user).attributes.symbolize_keys }-- shared_examples 'valid request' do- before { execute }-- it 'creates and returns resource' do- expect(json_response['data']).to have_attribute(:firstname).with_value(resource_params[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(resource_params[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(resource_params[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(resource_params[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(resource_params[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(resource_params[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(resource_params[:zipcode])- expect(json_response['data']).to have_relationship(:state).with_data({ 'id' => state.id.to_s, 'type' => 'state' })- expect(json_response['data']).to have_relationship(:country).with_data({ 'id' => country.id.to_s, 'type' => 'country' })- expect(json_response['data']).to have_relationship(:user).with_data({ 'id' => user.id.to_s, 'type' => 'user' })- end-- it_behaves_like 'returns 201 HTTP status'- end-- context 'application with admin access token' do- it_behaves_like 'valid request'- end-- context 'application with read access token' do- let(:bearer_token) { { 'Authorization' => valid_read_authorization } }-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end-- context 'user with access token' do- let(:bearer_token) { { 'Authorization' => valid_user_authorization } }-- it_behaves_like 'valid request'- end-- context 'invalid request' do- let(:resource_params) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor'- }- end-- before { execute }-- it 'returns errors' do- expect(json_response['error']).to eq("City can't be blank, Country can't be blank, and Zip Code can't be blank")- expect(json_response['errors']).to eq(- 'city' => ["can't be blank"],- 'zipcode' => ["can't be blank"],- 'country' => ["can't be blank"]- )- end- end-- it_behaves_like 'returns auth token errors'-- context '#ensure_current_store' do- context 'single store resource' do- let(:execute) { post '/api/v2/platform/taxonomies', params: taxonomy_resource_params, headers: bearer_token }- let(:taxonomy_resource_params) { { taxonomy: build(:taxonomy, name: 'Ensure-TaxonomyTest', store: nil).attributes.symbolize_keys } }-- before { execute }-- it_behaves_like 'returns 201 HTTP status'-- it 'adds the current store to the newly created resource' do- new_taxonomy = Spree::Taxonomy.find_by(name: 'Ensure-TaxonomyTest')- expect(new_taxonomy.store).to eql(store)- end- end-- context 'multi store resource empty array passed' do- let(:execute) { post '/api/v2/platform/payment_methods', params: payment_method_resource_params, headers: bearer_token }- let(:payment_method_resource_params) do- {- payment_method: {- name: 'Stripe-API-TEST',- store_ids: []- }- }- end-- before { execute }-- it_behaves_like 'returns 201 HTTP status'-- it 'adds the current store to the newly created resource' do- new_resource = Spree::PaymentMethod.find_by(name: 'Stripe-API-TEST')- expect(new_resource.stores).to match_array([store])- end- end-- context 'multi store resource array of stores ids passed' do- let(:execute) { post '/api/v2/platform/payment_methods', params: payment_method_resource_params, headers: bearer_token }- let(:payment_method_resource_params) do- {- payment_method: {- name: 'Stripe-API-TEST-2',- store_ids: [store_three.id.to_s]- }- }- end-- before { execute }-- it_behaves_like 'returns 201 HTTP status'-- it 'adds the current store and the stores in the array to the newly created resource' do- new_resource = Spree::PaymentMethod.find_by(name: 'Stripe-API-TEST-2')- expect(new_resource.stores).to match_array([store, store_three])- end- end- end- end-- describe '#update' do- let(:execute) { put "/api/v2/platform/addresses/#{id}", params: params, headers: bearer_token }-- shared_examples 'valid request' do- let(:resource_params) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_id: another_state.id- }- end-- let(:another_state) { create(:state, country: country) }-- before { execute }-- it 'updates and returns resource' do- expect(json_response['data']).to have_id(resource.id.to_s)- expect(json_response['data']).to have_attribute(:firstname).with_value(resource_params[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(resource_params[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(resource_params[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(resource_params[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(resource_params[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(resource_params[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(resource_params[:zipcode])-- expect(json_response['data']).to have_relationship(:state).with_data({ 'id' => another_state.id.to_s, 'type' => 'state' })- end- end-- context 'application with full access token' do- it_behaves_like 'valid request'- end-- context 'application with read access token' do- let(:bearer_token) { { 'Authorization' => valid_read_authorization } }- let(:resource_params) do- {- firstname: 'John',- lastname: 'Doe'- }- end-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end-- context 'user with access token' do- let(:bearer_token) { { 'Authorization' => valid_user_authorization } }-- it_behaves_like 'valid request'- end-- context 'user without access' do- let(:another_user) { create(:user) }- let(:bearer_token) { { 'Authorization' => valid_user_authorization } }- let(:resource_params) do- {- firstname: 'John',- lastname: 'Doe'- }- end-- before do- resource.update!(user: another_user)- execute- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'invalid request' do- let(:resource_params) do- {- city: '',- zipcode: ''- }- end-- before { execute }-- it 'returns errors' do- expect(json_response['error']).to eq("City can't be blank and Zip Code can't be blank")- expect(json_response['errors']).to eq(- 'city' => ["can't be blank"],- 'zipcode' => ["can't be blank"]- )- end- end-- context '#ensure_current_store' do- context 'multiple store resource' do- context 'when an empty array is passed to a resource that can belong to many stores' do- let!(:payment_method) { create(:payment_method, stores: [store, store_three, store_two]) }- let(:execute_payment_method) { patch "/api/v2/platform/payment_methods/#{payment_method.id}", params: payment_method_params, headers: bearer_token }- let(:payment_method_params) do- {- payment_method: {- store_ids: []- }- }- end-- before { execute_payment_method }-- it 'will not let you remove the current store from the resource' do- payment_method.reload- expect(payment_method.stores).to match_array([store])- expect(payment_method.stores.count).to eq(1)- end-- it_behaves_like 'returns auth token errors'- it_behaves_like 'returns error when record does not exist'- end-- context 'when an array of store ids are passed to a resource that can belong to many stores' do- let!(:payment_method) { create(:payment_method, stores: [store]) }- let(:execute_payment_method) { patch "/api/v2/platform/payment_methods/#{payment_method.id}", params: payment_method_params, headers: bearer_token }- let(:payment_method_params) do- {- payment_method: {- store_ids: [store_three.id.to_s, store_two.id.to_s]- }- }- end-- before { execute_payment_method }-- it 'will add the stores passed in' do- payment_method.reload- expect(payment_method.stores).to match_array([store, store_two, store_three])- expect(payment_method.stores.count).to eq(3)- end-- it_behaves_like 'returns auth token errors'- it_behaves_like 'returns error when record does not exist'- end- end- end- end-- context '#destroy' do- let(:execute) { delete "/api/v2/platform/addresses/#{id}", headers: bearer_token }-- context 'deletes record' do- before { execute }-- it_behaves_like 'returns 204 HTTP status'-- it 'returns with empty response' do- expect(response.body).to be_empty- end- end-- context 'application with read access token' do- let(:bearer_token) { { 'Authorization' => valid_read_authorization } }-- before { execute }-- it_behaves_like 'returns 401 HTTP status'- end-- it_behaves_like 'returns auth token errors'- it_behaves_like 'returns error when record does not exist'- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/stock_items_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/stock_items_spec.rbdeleted file mode 100644index a9eba46be1..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/stock_items_spec.rb+++ /dev/null@@ -1,35 +0,0 @@-require 'spec_helper'--describe 'Platform API v2 Stock Items API' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- let(:product_1) { create(:product, stores: [store]) }- let(:product_2) { create(:product, stores: [store]) }- let!(:stock_location_1) { create(:stock_location) }- let!(:stock_location_2) { create(:stock_location) }-- describe 'stock_items#index' do- let!(:variants) { create_list(:variant, 2, product: product_1) }-- context 'filtering by stock location id' do- before { get "/api/v2/platform/stock_items?filter[stock_location_id_eq]=#{stock_location_1.id}", headers: bearer_token }-- it 'returns stock_items with matching stock location ids' do- expect(json_response['data'].count).to eq(2)- expect(json_response['data'].first).to have_type('stock_item')- end- end-- context 'filtering by variant product name or sku' do- before { get "/api/v2/platform/stock_items?filter[variants_product_name_or_variants_sku_cont]=#{product_2.name}", headers: bearer_token }-- it 'returns stock_items with matching stock location ids' do- # default variant + 2 variants for product_2, each inside two stock locations- expect(json_response['data'].count).to eq 6- expect(json_response['data'].first).to have_type('stock_item')- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/taxons_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/taxons_spec.rbdeleted file mode 100644index 0c9305ce64..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/taxons_spec.rb+++ /dev/null@@ -1,265 +0,0 @@-require 'spec_helper'--describe 'Platform API v2 Taxons API' do- include_context 'Platform API v2'-- let(:store) { @default_store }- let(:taxonomy) { store.taxonomies.find_by(name: Spree.t(:taxonomy_categories_name)) }- let(:store_2) { create(:store) }- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- describe 'taxons#index' do- let!(:taxon) { create(:taxon, name: 'T-Shirts', taxonomy: taxonomy) }- let!(:taxon_2) { create(:taxon, name: 'Pants', taxonomy: taxonomy) }- let!(:taxon_3) { create(:taxon, name: 'T-Shirts', taxonomy: create(:taxonomy, store: store_2)) }-- context 'filtering' do- before { get '/api/v2/platform/taxons?filter[name_i_cont]=shirt', headers: bearer_token }-- it 'returns taxons with matching name' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(taxon.id.to_s)- expect(json_response['data'].first).to have_relationships(:taxonomy, :parent, :children, :image)- end- end-- xcontext 'sorting' do- before { get '/api/v2/platform/taxons?sort=name', headers: bearer_token }-- it 'returns taxons sorted by name' do- expect(json_response['data'].count).to eq 4- expect(json_response['data'].second).to have_id(taxon_2.id.to_s)- end- end- end-- describe 'taxons#show' do- let!(:taxon) { create(:taxon, name: 'T-Shirts', taxonomy: taxonomy) }-- context 'with valid id' do- before { get "/api/v2/platform/taxons/#{taxon.id}", headers: bearer_token }-- it 'returns taxon' do- expect(json_response['data']).to have_id(taxon.id.to_s)- expect(json_response['data']).to have_relationships(:taxonomy, :parent, :children, :image, :products)- end- end-- context 'with taxon image data' do- shared_examples 'returns taxon image data' do- it 'returns taxon image data' do- expect(json_response['included'].count).to eq(1)- expect(json_response['included'].first['type']).to eq('taxon_image')- end- end-- let!(:image) { create(:taxon_image, viewable: taxon) }- let(:image_json_data) { json_response['included'].first['attributes'] }-- before { get "/api/v2/storefront/taxons/#{taxon.id}?include=image#{taxon_image_transformation_params}", headers: bearer_token }-- context 'when no image transformation params are passed' do- let(:taxon_image_transformation_params) { '' }-- it_behaves_like 'returns taxon image data'-- it 'returns taxon image' do- expect(image_json_data['transformed_url']).to be_nil- end- end-- context 'when taxon image json returned' do- let(:taxon_image_transformation_params) { '&taxon_image_transformation[size]=100x50&taxon_image_transformation[quality]=50' }-- it_behaves_like 'returns taxon image data'-- it 'returns taxon image' do- expect(image_json_data['transformed_url']).not_to be_nil- end- end- end- end-- shared_examples 'a resource containing metadata' do- describe 'public metadata' do- let(:metadata_params) { { public_metadata: public_metadata_params } }-- describe 'string entry' do- let(:public_metadata_params) { { ability_to_recycle: '60%' } }-- it 'adds the metadata property' do- expect(json_response['data']['attributes']['public_metadata']['ability_to_recycle']).to eq('60%')- end- end-- describe 'number entry' do- let(:public_metadata_params) { { profitability: 3.4 } }-- it { expect(json_response['data']['attributes']['public_metadata']['profitability']).to eq('3.4') }- end-- describe 'boolean entry' do- let(:public_metadata_params) { { in_foreign_country: true } }-- it { expect(json_response['data']['attributes']['public_metadata']['in_foreign_country']).to eq('true') }- end-- describe 'array entry' do- let(:public_metadata_params) { { top_years: %w[2011 2016 2020] } }-- it { expect(json_response['data']['attributes']['public_metadata']['top_years']).to eq(%w[2011 2016 2020]) }- end- end-- describe 'private metadata' do- let(:metadata_params) { { private_metadata: private_metadata_params } }-- describe 'string entry' do- let(:private_metadata_params) { { ability_to_recycle: '60%' } }-- it { expect(json_response['data']['attributes']['private_metadata']['ability_to_recycle']).to eq('60%') }- end-- describe 'number entry' do- let(:private_metadata_params) { { profitability: 3.4 } }-- it { expect(json_response['data']['attributes']['private_metadata']['profitability']).to eq('3.4') }- end-- describe 'boolean entry' do- let(:private_metadata_params) { { in_foreign_country: false } }-- it { expect(json_response['data']['attributes']['private_metadata']['in_foreign_country']).to eq('false') }- end-- describe 'array entry' do- let(:private_metadata_params) { { top_years: %w[2011 2016 2020] } }-- it { expect(json_response['data']['attributes']['private_metadata']['top_years']).to eq(%w[2011 2016 2020]) }- end- end- end-- describe 'taxons#update for metadata' do- let!(:taxon) { create(:taxon, name: 'T-Shirts', taxonomy: taxonomy) }-- before do- patch "/api/v2/platform/taxons/#{taxon.id}",- headers: bearer_token,- params: { taxon: metadata_params }- end-- it_behaves_like 'a resource containing metadata'- end-- describe 'taxons#create for metadata' do- before do- post '/api/v2/platform/taxons/',- headers: bearer_token,- params: {- taxon: {- name: 'Tires',- taxonomy_id: taxonomy.id,- parent_id: taxonomy.root.id- }.merge(metadata_params)- }- end-- it_behaves_like 'a resource containing metadata'- end-- describe 'taxons#reposition' do- let!(:taxon_a) { create(:taxon, name: 'T-Shirts', taxonomy: taxonomy) }- let!(:taxon_b) { create(:taxon, name: 'Shorts', taxonomy: taxonomy) }- let!(:taxon_c) { create(:taxon, name: 'Pants', taxonomy: taxonomy) }-- context 'with no params' do- let(:params) do- {- taxon: {- new_parent_id: nil,- new_position_idx: nil- }- }- end-- before do- patch "/api/v2/platform/taxons/#{taxon_a.id}/reposition", headers: bearer_token, params: params- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with none existing parent ID' do- let(:params) do- {- taxon: {- new_parent_id: 999129192192,- new_position_idx: 0- }- }- end-- before do- patch "/api/v2/platform/taxons/#{taxon_a.id}/reposition", headers: bearer_token, params: params- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with correct params' do- let(:params) do- {- taxon: {- new_parent_id: taxon_c.id,- new_position_idx: 0- }- }- end-- before do- patch "/api/v2/platform/taxons/#{taxon_a.id}/reposition", headers: bearer_token, params: params- end-- it_behaves_like 'returns 200 HTTP status'-- it 'taxon_a can be nested inside another taxon_c' do- reload_taxons-- expect(taxon_a.permalink).to eq("#{taxonomy.root.permalink}/pants/t-shirts")- expect(taxon_a.parent_id).to eq(taxon_c.id)- expect(taxon_a.depth).to eq(2)- end- end-- context 'with correct params moving within the same taxon' do- let(:params) do- {- taxon: {- new_parent_id: taxon_b.id,- new_position_idx: 0- }- }- end-- before do- patch "/api/v2/platform/taxons/#{taxon_a.id}/reposition", headers: bearer_token, params: params- end-- it_behaves_like 'returns 200 HTTP status'-- it 're-indexes the taxon' do- reload_taxons-- expect(taxon_a.parent_id).to eq(taxon_b.id)- expect(taxon_a.lft).to eq(taxon_b.lft + 1)- end- end-- def reload_taxons- taxon_a.reload- taxon_b.reload- taxon_c.reload- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/users_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/users_spec.rbdeleted file mode 100644index 32de0a7337..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/users_spec.rb+++ /dev/null@@ -1,59 +0,0 @@-require 'spec_helper'--# TODO: this spec needs to be rewritten as it name clashes with the admin users spec-xdescribe 'Platform API v2 Users API' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- describe 'users#index' do- let!(:user) { create(:user, email: '[email protected]') }- let!(:user_2) { create(:user, email: '[email protected]') }-- context 'filtering' do- context 'by email' do- before { get '/api/v2/platform/users?filter[email_eq][email protected]', headers: bearer_token }-- it 'returns users with matching email' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(user.id.to_s)- end- end-- context 'by address firstname' do- let!(:address) { create(:address, firstname: 'Daenerys', user: user_2) }-- before { get '/api/v2/platform/users?filter[addresses_firstname_eq]=Daenerys', headers: bearer_token }-- it 'returns users with matching address firstname' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(user_2.id.to_s)- end- end-- context 'by address lastname' do- let!(:address) { create(:address, lastname: 'Targaryen', user: user_2) }-- before { get '/api/v2/platform/users?filter[addresses_lastname_eq]=Targaryen', headers: bearer_token }-- it 'returns users with matching address lastname' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(user_2.id.to_s)- end- end-- context 'by address firstname, lastname and email combined' do- let!(:address) { create(:address, firstname: 'John', user: user) }- let!(:address_2) { create(:address, lastname: 'Targaryen', user: user_2) }-- before do- get '/api/v2/platform/users?filter[m]=or&filter[addresses_lastname_eq]=targaryen&filter[addresses_firstname_eq]=John', headers: bearer_token- end-- it 'returns users with matching address lastname' do- expect(json_response['data'].count).to eq 2- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/platform/variants_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/platform/variants_spec.rbdeleted file mode 100644index 6f9b2fb86a..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/platform/variants_spec.rb+++ /dev/null@@ -1,134 +0,0 @@-require 'spec_helper'--describe 'API V2 Platform Variants Spec' do- include_context 'Platform API v2'-- let(:bearer_token) { { 'Authorization' => valid_authorization } }-- let(:product) { create(:product, stores: [store]) }- let!(:variants) { create_list(:variant, 5, product: product) }-- describe 'variants#index' do- context 'with no params' do- before { get '/api/v2/platform/variants', headers: bearer_token }-- it 'returns all variants' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['data'].first).to have_type('variant')- end- end-- context 'current store' do- let(:store_2) { create(:store) }- let(:product_2) { create(:product, stores: [store_2]) }- let!(:variant_from_another_store) { create(:variant, product: product_2) }-- before { get '/api/v2/platform/variants', headers: bearer_token }-- it 'returns variants from this store only' do- expect(json_response['data'].count).to eq store.variants.count- variant_ids = json_response['data'].pluck(:id)-- expect(variant_ids).not_to include(variant_from_another_store.id)- expect(variant_ids).to match_array(store.variants.ids.map(&:to_s))- end- end-- context 'filtering' do- context 'by name' do- let(:product_2) { create(:product, stores: [store], name: 'Vendo T-shirt') }- let!(:variant) { create(:variant, product: product_2) }-- before { get '/api/v2/platform/variants?filter[product_name_cont]=vendo&filter[is_master_eq]=false', headers: bearer_token }-- it 'returns variant with a specified name' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first['id']).to eq variant.id.to_s- end- end-- xcontext 'by price' do- let!(:variant) { create(:variant, price: 100) }-- before { get '/api/v2/platform/variants?filter[product_price_between]=100,200', headers: bearer_token }-- it 'returns variants with price greater than or equal to the given price' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first['id']).to eq variant.id.to_s- end- end- end-- context 'sorting' do- context 'by updated_at' do- context 'ascending order' do- before { get '/api/v2/platform/variants?sort=updated_at', headers: bearer_token }-- it 'returns variants sorted by updated_at' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['data'].pluck(:id)).to eq store.variants.order(:updated_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/variants?sort=-updated_at', headers: bearer_token }-- it 'returns variants sorted by updated_at with descending order' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['data'].pluck(:id)).to eq store.variants.order(updated_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'by created_at' do- context 'ascending order' do- before { get '/api/v2/platform/variants?sort=created_at', headers: bearer_token }-- it 'returns variants sorted by created_at' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['data'].pluck(:id)).to eq store.variants.order(:created_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/platform/variants?sort=-created_at', headers: bearer_token }-- it 'returns variants sorted by created_at with descending order' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['data'].pluck(:id)).to eq store.variants.order(created_at: :desc).map(&:id).map(&:to_s)- end- end- end- end-- context 'paginate variants' do- context 'with specified pagination params' do- context 'when per_page is between 1 and default value' do- before { get '/api/v2/platform/variants?page=1&per_page=2', headers: bearer_token }-- it 'returns proper pagination data' do- expect(json_response['data'].count).to eq 2- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq store.variants.count- expect(json_response['links']['self']).to include('/api/v2/platform/variants?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/platform/variants?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/platform/variants?page=1&per_page=2')- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/platform/variants', headers: bearer_token }-- it 'returns proper pagination data' do- expect(json_response['data'].count).to eq store.variants.count- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).to eq store.variants.count- expect(json_response['links']['self']).to include('/api/v2/platform/variants')- expect(json_response['links']['next']).to include('/api/v2/platform/variants?page=1')- expect(json_response['links']['prev']).to include('/api/v2/platform/variants?page=1')- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/resource_includes_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/resource_includes_spec.rbdeleted file mode 100644index 027ed7d9c9..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/resource_includes_spec.rb+++ /dev/null@@ -1,101 +0,0 @@-require 'spec_helper'--describe 'API v2 JSON API Resource Includes Spec', type: :request do- let(:store) { @default_store }- let!(:products) { create_list(:product, 5, stores: [store]) }- let!(:product) { create(:product, stores: [store]) }- let!(:product_option_type) { create(:product_option_type, product: product) }- let!(:option_value) { create(:option_value, option_type: product_option_type.option_type) }- let(:primary_variant) { product.master }- let!(:default_variant) { create(:variant, product: product) }-- shared_examples 'requested resources' do- it 'are returned' do- expect(json_response['included']).to be_present- expect(json_response['included']).to include(have_type('variant').and have_id(default_variant.id.to_s))- expect(json_response['included']).not_to include(have_type('variant').and have_id(primary_variant.id.to_s))- expect(json_response['included']).not_to include(have_type('option_type'))- end- end-- shared_examples 'nested requested resources' do- it 'are returned' do- expect(json_response['included']).to be_present- expect(json_response['included']).to include(have_type('variant').and have_id(primary_variant.id.to_s))- expect(json_response['included']).to include(have_type('option_type'))- expect(json_response['included']).to include(have_type('option_value'))- end- end-- shared_examples 'requested no resources' do- it 'nothing is returned' do- expect(json_response['included']).not_to be_present- end- end-- context 'singular resource' do- context 'without include param' do- before { get "/api/v2/storefront/products/#{product.id}" }-- it_behaves_like 'requested no resources'- end-- context 'with include param' do- context 'empty param' do- before { get "/api/v2/storefront/products/#{product.id}?include=" }-- it_behaves_like 'requested no resources'- end-- context 'with non-existing relation requested' do- before { get "/api/v2/storefront/products/#{product.id}?include=does_not_exist" }-- it_behaves_like 'returns 400 HTTP status'- end-- context 'present param' do- context 'without nested resources' do- before { get "/api/v2/storefront/products/#{product.id}?include=default_variant" }-- it_behaves_like 'requested resources'- end-- context 'with nested resources' do- before { get "/api/v2/storefront/products/#{product.id}?include=primary_variant,option_types,option_types.option_values" }-- it_behaves_like 'nested requested resources'- end- end- end- end-- context 'collections' do- context 'without include param' do- before { get '/api/v2/storefront/products' }-- it_behaves_like 'requested no resources'- end-- context 'with include param' do- context 'empty param' do- before { get '/api/v2/storefront/products?include=' }-- it_behaves_like 'requested no resources'- end-- context 'present param' do- context 'without nested resources' do- before { get '/api/v2/storefront/products?include=default_variant' }-- it_behaves_like 'requested resources'- end-- context 'with nested resources' do- before { get '/api/v2/storefront/products?include=primary_variant,option_types,option_types.option_values' }-- it_behaves_like 'nested requested resources'- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/store_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/store_spec.rbdeleted file mode 100644index a9987dd744..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/store_spec.rb+++ /dev/null@@ -1,43 +0,0 @@-require 'spec_helper'--describe 'API v2 Store Switching spec', type: :request do- let!(:store) { @default_store }- let!(:another_store) { create(:store, url: 'another-store.lvh.me', name: 'Another Store') }-- let!(:product) { create(:product, stores: [store]) }- let!(:another_product) { create(:product, stores: [another_store]) }-- context 'existing store found' do- before { host!('another-store.lvh.me') }-- context 'product associated with store' do- before { get "/api/v2/storefront/products/#{another_product.slug}" }-- it_behaves_like 'returns 200 HTTP status'- end-- context 'product not associated with store' do- before { get "/api/v2/storefront/products/#{product.slug}" }-- it_behaves_like 'returns 404 HTTP status'- end- end-- context 'non-existing store' do- before { host!('missing-store.lvh.me') }-- context 'fallbacks to the default store' do- context 'product associated with store' do- before { get "/api/v2/storefront/products/#{product.slug}" }-- it_behaves_like 'returns 200 HTTP status'- end-- context 'product not associated with store' do- before { get "/api/v2/storefront/products/#{another_product.slug}" }-- it_behaves_like 'returns 404 HTTP status'- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/addresses_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/addresses_spec.rbdeleted file mode 100644index 9cf1a37228..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/addresses_spec.rb+++ /dev/null@@ -1,277 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Addresses spec', type: :request do- let!(:user) { create(:user) }- let!(:params) { { user_id: user.id } }- let!(:addresses) { create_list(:address, 3, user_id: user.id) }- let!(:country) { create(:country, iso: 'GBR') }- let!(:state) { create(:state, country: country) }- let(:store) { @default_store }-- shared_examples 'returns valid user addresses resource JSON' do- it 'returns a valid user addresses resource JSON response' do- expect(response.status).to eq(200)-- expect(json_response['data'][0]).to have_type('address')- expect(json_response['data'][0]).to have_attribute(:firstname)- expect(json_response['data'][0]).to have_attribute(:lastname)- expect(json_response['data'][0]).to have_attribute(:address1)- expect(json_response['data'][0]).to have_attribute(:address2)- expect(json_response['data'][0]).to have_attribute(:city)- expect(json_response['data'][0]).to have_attribute(:zipcode)- expect(json_response['data'][0]).to have_attribute(:phone)- expect(json_response['data'][0]).to have_attribute(:state_name)- expect(json_response['data'][0]).to have_attribute(:company)- expect(json_response['data'][0]).to have_attribute(:country_name)- expect(json_response['data'][0]).to have_attribute(:country_iso3)- expect(json_response['data'][0]).to have_attribute(:country_iso)- expect(json_response['data'][0]).to have_attribute(:state_code)- expect(json_response['data'][0]).to have_attribute(:public_metadata)- end- end-- include_context 'API v2 tokens'-- describe 'addresses#index' do- context 'without options' do- let!(:other_user) { create(:user_with_addresses) }-- before { get '/api/v2/storefront/account/addresses', headers: headers_bearer }-- it_behaves_like 'returns valid user addresses resource JSON'-- it 'returns all user addresses' do- expect(json_response['data'][0]).to have_type('address')- expect(json_response['data'].size).to eq(addresses.count)- expect(json_response['data'].size).not_to eq Spree::Address.count- end- end-- context 'with missing authorization token' do- before { get '/api/v2/storefront/account/addresses' }-- it_behaves_like 'returns 403 HTTP status'- end-- context 'when address can not be deleted' do- let!(:address) { create(:address, user_id: user.id) }-- before do- expect(address).to receive(:can_be_deleted?).and_return(false).at_least(:once)- address.destroy!- get '/api/v2/storefront/account/addresses', headers: headers_bearer- end-- it 'should not return deleted address' do- expect(address.deleted_at).not_to be_nil- expect(json_response['data'][0]).to have_type('address')- expect(json_response['data'].size).to eq(addresses.count)- end- end-- context 'when address from countries that are supported in the current store' do- let(:country) { create(:country, name: 'France') }- let(:zone) { create(:zone, name: 'EU_VAT', countries: [country], kind: 'country') }- let!(:eu_address) { create(:address, user_id: user.id, country: country) }-- before do- store.update(checkout_zone: zone)- get '/api/v2/storefront/account/addresses', headers: headers_bearer- end-- it 'should return addresses from supported countries' do- expect(user.addresses.size).to eq 4- expect(json_response['data'].size).to eq 1- expect(json_response['data'][0]).to have_attribute(:country_name).with_value(eu_address.country.name)- end- end-- context 'when address from countries that are not supported in the current store' do- let(:eu_country) { create(:country, name: 'France') }- let(:zone) { create(:zone, name: 'EU_VAT', countries: [eu_country], kind: 'country') }- let(:country) { create(:country) }- let!(:us_address) { create(:address, user_id: user.id, country: country) }-- before do- store.update(checkout_zone: zone)- get '/api/v2/storefront/account/addresses', headers: headers_bearer- end-- it 'should not return addresses from not supported countries' do- expect(user.addresses.size).to eq 4- expect(json_response['data'].size).to eq 0- end- end-- context 'when address without user exists' do- let!(:address) { create(:address, user_id: nil) }-- before do- get '/api/v2/storefront/account/addresses', headers: headers_bearer- end-- it 'should not return address without user id' do- expect(json_response['data'][0]).to have_type('address')- expect(json_response['data'].size).to eq(addresses.count)- end- end- end-- describe 'addresses#create' do- context 'valid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: 'EAW',- country_iso: 'GBR'- }- end- let(:params) { { address: new_attributes } }-- before { post '/api/v2/storefront/account/addresses', params: params, headers: headers_bearer }-- it 'creates and returns address' do- expect(json_response['data']).to have_attribute(:firstname).with_value(new_attributes[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(new_attributes[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(new_attributes[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(new_attributes[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(new_attributes[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(new_attributes[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(new_attributes[:zipcode])- expect(json_response['data']).to have_attribute(:state_name).with_value(new_attributes[:state_name])- expect(json_response['data']).to have_attribute(:country_iso).with_value(new_attributes[:country_iso])- expect(json_response.size).to eq(1)- end- end-- context 'invalid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor'- }- end- let(:params) { { address: new_attributes } }-- before { post '/api/v2/storefront/account/addresses', params: params, headers: headers_bearer }-- it 'returns errors' do- expect(json_response['error']).to eq("City can't be blank, Country can't be blank, Zip Code can't be blank")- expect(json_response['errors']).to eq(- 'city' => ["can't be blank"],- 'zipcode' => ["can't be blank"],- 'country' => ["can't be blank"]- )- end- end-- context 'with missing authorization token' do- before { post '/api/v2/storefront/account/addresses' }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'addresses#update' do- let(:address) { addresses.last }-- context 'valid request' do- let(:new_attributes) do- {- firstname: 'John',- lastname: 'Doe',- address1: '51 Guild Street',- address2: '2nd floor',- city: 'London',- phone: '079 4721 9458',- zipcode: 'SE25 3FZ',- state_name: state.name,- country_iso: country.iso- }- end- let(:params) { { address: new_attributes } }-- before { patch "/api/v2/storefront/account/addresses/#{address.id}", params: params, headers: headers_bearer }-- it 'updates and returns address' do- expect(json_response['data']).to have_id(address.id.to_s)- expect(json_response['data']).to have_attribute(:firstname).with_value(new_attributes[:firstname])- expect(json_response['data']).to have_attribute(:lastname).with_value(new_attributes[:lastname])- expect(json_response['data']).to have_attribute(:address1).with_value(new_attributes[:address1])- expect(json_response['data']).to have_attribute(:address2).with_value(new_attributes[:address2])- expect(json_response['data']).to have_attribute(:city).with_value(new_attributes[:city])- expect(json_response['data']).to have_attribute(:phone).with_value(new_attributes[:phone])- expect(json_response['data']).to have_attribute(:zipcode).with_value(new_attributes[:zipcode])- expect(json_response['data']).to have_attribute(:state_name).with_value(new_attributes[:state_name])- expect(json_response['data']).to have_attribute(:country_iso).with_value(new_attributes[:country_iso])- expect(json_response.size).to eq(1)- end- end-- context 'invalid request' do- let(:new_attributes) do- {- city: '',- zipcode: ''- }- end- let(:params) { { address: new_attributes } }-- before { patch "/api/v2/storefront/account/addresses/#{address.id}", params: params, headers: headers_bearer }-- it 'returns errors' do- expect(json_response['error']).to eq("City can't be blank, Zip Code can't be blank")- expect(json_response['errors']).to eq(- 'city' => ["can't be blank"],- 'zipcode' => ["can't be blank"]- )- end- end-- context 'with missing authorization token' do- before { patch "/api/v2/storefront/account/addresses/#{address.id}" }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'addresses#destroy' do- let(:address) { addresses.last }-- context 'valid request' do- before { delete "/api/v2/storefront/account/addresses/#{address.id}", headers: headers_bearer }-- it 'destroys address permanently' do- expect { Spree::Address.unscoped.find(address.id) }.to raise_exception(ActiveRecord::RecordNotFound)- expect { address.reload }.to raise_exception(ActiveRecord::RecordNotFound)- end- end-- context 'valid request with existing shipment' do- let!(:order) { create :completed_order_with_totals, ship_address: address, bill_address: address}-- before {- delete "/api/v2/storefront/account/addresses/#{address.id}", headers: headers_bearer- address.reload- }-- it 'sets deleted_at date for address' do- expect(address.deleted_at).not_to be_nil- end- end-- context 'with missing authorization token' do- before { delete "/api/v2/storefront/account/addresses/#{address.id}" }-- it_behaves_like 'returns 403 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/credit_cards_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/credit_cards_spec.rbdeleted file mode 100644index 53539da1e6..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/credit_cards_spec.rb+++ /dev/null@@ -1,173 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 CreditCards spec', type: :request do- let!(:user) { create(:user) }- let!(:credit_cards) { create_list(:credit_card, 3, user_id: user.id) }-- shared_examples 'returns valid user credit cards resource JSON' do- it 'returns a valid user credit cards resource JSON response' do- expect(response.status).to eq(200)-- expect(json_response['data'][0]).to have_type('credit_card')- expect(json_response['data'][0]).to have_relationships(:payment_method)- expect(json_response['data'][0]).to have_attribute(:last_digits)- expect(json_response['data'][0]).to have_attribute(:month)- expect(json_response['data'][0]).to have_attribute(:year)- expect(json_response['data'][0]).to have_attribute(:name)- expect(json_response['data'][0]).to have_attribute(:gateway_payment_profile_id)- expect(json_response['data'][0]).to have_attribute(:public_metadata)- end- end-- include_context 'API v2 tokens'-- describe 'credit_cards#index' do- let(:payment_method_id) { credit_cards.first.payment_method_id }-- context 'with filter options' do- before { get "/api/v2/storefront/account/credit_cards?filter[payment_method_id]=#{payment_method_id}&include=payment_method", headers: headers_bearer }-- it_behaves_like 'returns valid user credit cards resource JSON'-- it 'returns all user credit_cards' do- expect(json_response['data'].count).to eq user.credit_cards.where(payment_method_id: payment_method_id).count- end- end-- context 'without options' do- before { get '/api/v2/storefront/account/credit_cards', headers: headers_bearer }-- it_behaves_like 'returns valid user credit cards resource JSON'-- it 'returns all user credit_cards' do- expect(json_response['data'][0]).to have_type('credit_card')- expect(json_response['data'].size).to eq(credit_cards.count)- end-- context 'user has credit cards that are not available on the front end' do- let!(:credit_cards) { create_list(:credit_card, 3, user_id: user.id, payment_method: payment_method) }- let(:payment_method) { create(:credit_card_payment_method, display_on: display_on, stores: stores) }- let(:stores) { [@default_store] }- let(:display_on) { :back_end }-- it 'does not return any' do- expect(response.status).to eq(200)- expect(json_response['data'].size).to eq(0)- end-- context 'user has a credit cards available on the front end but in different store' do- let(:stores) { [create(:store)] }- let(:display_on) { :front_end }-- it 'does not return any' do- expect(response.status).to eq(200)- expect(json_response['data'].size).to eq(0)- end- end-- context 'deleted credit cards are omitted' do- let!(:deleted_credit_card) { create(:credit_card, user_id: user.id, payment_method: payment_method, deleted_at: Time.current) }-- it 'returns all user credit_cards' do- expect(json_response['data'].map(&:id)).not_to include(deleted_credit_card.id)- end- end- end- end-- context 'with missing authorization token' do- before { get '/api/v2/storefront/account/credit_cards' }-- it_behaves_like 'returns 403 HTTP status'- end-- context 'when user has admin privileges' do- let!(:user) { create(:admin_user) }- let!(:new_user) { create(:user) }- let!(:new_credit_card) { create(:credit_card, user_id: new_user.id, last_digits: '2222') }-- before { get '/api/v2/storefront/account/credit_cards', headers: headers_bearer }-- it 'should return user credit cards only' do- expect(json_response['data'][0]).to have_type('credit_card')- expect(json_response['data'].size).to eq(credit_cards.count)- expect(json_response['data'].map { |card| card['attributes']['last_digits'] }).not_to include(new_credit_card.last_digits)- end- end- end-- describe 'credit_cards#show' do- let!(:default_credit_card) { create(:credit_card, user_id: user.id, default: true) }- let!(:credit_card) { create(:credit_card, user_id: user.id, default: false) }-- context 'by "default"' do- before { get '/api/v2/storefront/account/credit_cards/default', headers: headers_bearer }-- it 'returns user default credit_card' do- expect(json_response['data']).to have_id(default_credit_card.id.to_s)- expect(json_response['data']).to have_attribute(:cc_type).with_value(default_credit_card.cc_type)- expect(json_response['data']).to have_attribute(:last_digits).with_value(default_credit_card.last_digits)- expect(json_response['data']).to have_attribute(:name).with_value(default_credit_card.name)- expect(json_response['data']).to have_attribute(:month).with_value(default_credit_card.month)- expect(json_response['data']).to have_attribute(:year).with_value(default_credit_card.year)- end- end-- context 'by ID' do- before { get "/api/v2/storefront/account/credit_cards/#{credit_card.id}", headers: headers_bearer }-- it 'returns proper credit_card' do- expect(json_response['data']).to have_id(credit_card.id.to_s)- expect(json_response['data']).to have_attribute(:cc_type).with_value(credit_card.cc_type)- expect(json_response['data']).to have_attribute(:last_digits).with_value(credit_card.last_digits)- expect(json_response['data']).to have_attribute(:name).with_value(credit_card.name)- expect(json_response['data']).to have_attribute(:month).with_value(credit_card.month)- expect(json_response['data']).to have_attribute(:year).with_value(credit_card.year)- end- end-- context 'with missing authorization token' do- before { get '/api/v2/storefront/account/credit_cards/default' }-- it_behaves_like 'returns 403 HTTP status'- end-- context 'deleted credit card' do- let!(:credit_card) { create(:credit_card, user_id: user.id, default: false) }-- before { credit_card.destroy }-- it 'returns 404 HTTP status' do- get "/api/v2/storefront/account/credit_cards/#{credit_card.id}", headers: headers_bearer- expect(response.status).to eq(404)- end- end- end-- describe 'credit_cards#destroy' do- context 'when credit card exist' do- let!(:credit_card) { create(:credit_card, user_id: user.id) }-- it 'deletes a credit card' do- delete "/api/v2/storefront/account/credit_cards/#{credit_card.id}", headers: headers_bearer-- expect(credit_card.reload.deleted_at).not_to be_nil- expect(response.status).to eq(204)- end-- context 'with missing authorization token' do- before { delete "/api/v2/storefront/account/credit_cards/#{credit_card.id}" }-- it_behaves_like 'returns 403 HTTP status'- end- end-- context 'when credit card does not exist' do- it 'should not find a credit card' do- delete "/api/v2/storefront/account/credit_cards/dummy_id", headers: headers_bearer-- expect(response.status).to eq(404)- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/orders_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/orders_spec.rbdeleted file mode 100644index e0d1d6a32f..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account/orders_spec.rb+++ /dev/null@@ -1,222 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Orders spec', type: :request do- let(:store) { @default_store }- let!(:user) { create(:user_with_addresses) }- let!(:order) { create(:order, state: 'complete', user: user, completed_at: Time.current, store: store) }-- before do- allow(Spree::Api::Config).to receive(:[]).and_call_original- allow(Spree::Api::Config).to receive(:[]).with(:api_v2_per_page_limit).and_return(2)- end-- include_context 'API v2 tokens'-- def expect_order_json(json)- expect(json).to be_present- expect(json).to have_id(order.id.to_s)- expect(json).to have_type('order')- expect(json).to have_attribute(:number).with_value(order.number)- expect(json).to have_attribute(:state).with_value(order.state)- expect(json).to have_attribute(:token).with_value(order.token)- expect(json).to have_attribute(:total).with_value(order.total.to_s)- expect(json).to have_attribute(:item_total).with_value(order.item_total.to_s)- expect(json).to have_attribute(:ship_total).with_value(order.ship_total.to_s)- expect(json).to have_attribute(:adjustment_total).with_value(order.adjustment_total.to_s)- expect(json).to have_attribute(:included_tax_total).with_value(order.included_tax_total.to_s)- expect(json).to have_attribute(:additional_tax_total).with_value(order.additional_tax_total.to_s)- expect(json).to have_attribute(:display_additional_tax_total).with_value(order.display_additional_tax_total.to_s)- expect(json).to have_attribute(:display_included_tax_total).with_value(order.display_included_tax_total.to_s)- expect(json).to have_attribute(:tax_total).with_value(order.tax_total.to_s)- expect(json).to have_attribute(:currency).with_value(order.currency.to_s)- expect(json).to have_attribute(:email).with_value(order.email)- expect(json).to have_attribute(:display_item_total).with_value(order.display_item_total.to_s)- expect(json).to have_attribute(:display_ship_total).with_value(order.display_ship_total.to_s)- expect(json).to have_attribute(:display_adjustment_total).with_value(order.display_adjustment_total.to_s)- expect(json).to have_attribute(:display_tax_total).with_value(order.display_tax_total.to_s)- expect(json).to have_attribute(:item_count).with_value(order.item_count)- expect(json).to have_attribute(:special_instructions).with_value(order.special_instructions)- expect(json).to have_attribute(:promo_total).with_value(order.promo_total.to_s)- expect(json).to have_attribute(:display_promo_total).with_value(order.display_promo_total.to_s)- expect(json).to have_attribute(:display_total).with_value(order.display_total.to_s)- expect(json).to have_attribute(:public_metadata).with_value(order.public_metadata)- expect(json).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments, :promotions)- end-- describe 'orders#index' do- context 'with option: include' do- before { get '/api/v2/storefront/account/orders?include=billing_address', headers: headers_bearer }-- it 'returns orders' do- expect(json_response['data'].size).to eq 1- expect(json_response['data']).to be_kind_of(Array)-- expect_order_json(json_response['data'].first)- end-- it 'returns included resource' do- expect(json_response['included'].size).to eq Spree::Order.count- expect(json_response['included'][0]).to have_type('address')- end- end-- context 'when per_page is between 1 and default value' do- let!(:order) { create(:order, state: 'complete', user: user, completed_at: Time.current, store: store) }- let!(:order_1) { create(:order, state: 'complete', user: user, completed_at: Time.current + 1.day, store: store) }- let!(:order_2) { create(:order, state: 'complete', user: user, completed_at: Time.current + 2.days, store: store) }- let!(:order_3) { create(:order, state: 'complete', user: user, completed_at: Time.current + 3.days, store: store) }-- context 'with specified pagination params' do- before { get '/api/v2/storefront/account/orders?page=1&per_page=2', headers: headers_bearer }-- it 'returns specified amount orders' do- expect(json_response['data'].count).to eq 2- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq Spree::Order.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/account/orders?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/storefront/account/orders?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/storefront/account/orders?page=1&per_page=2')- end- end-- context 'when per_page is above the default value' do- before { get '/api/v2/storefront/account/orders?page=1&per_page=10', headers: headers_bearer }-- it 'returns the default number of orders' do- expect(json_response['data'].count).to eq 4- end- end-- context 'when per_page is less than 0' do- before { get '/api/v2/storefront/account/orders?page=1&per_page=-1', headers: headers_bearer }-- it 'returns the default number of orders' do- expect(json_response['data'].count).to eq 4- end- end-- context 'when per_page is equal 0' do- before { get '/api/v2/storefront/account/orders?page=1&per_page=0', headers: headers_bearer }-- it 'returns the default number of orders' do- expect(json_response['data'].count).to eq 4- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/storefront/account/orders', headers: headers_bearer }-- it 'returns specified amount orders' do- expect(json_response['data'].count).to eq Spree::Order.count- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq Spree::Order.count- expect(json_response['meta']['total_count']).to eq Spree::Order.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/account/orders')- expect(json_response['links']['next']).to include('/api/v2/storefront/account/orders?page=1')- expect(json_response['links']['prev']).to include('/api/v2/storefront/account/orders?page=1')- end- end-- context 'sort orders' do- let!(:order) { create(:order, state: 'complete', user: user, completed_at: Time.current) }- let!(:order_1) { create(:order, state: 'complete', user: user, completed_at: Time.current + 1.day) }- let!(:order_2) { create(:order, state: 'complete', user: user, completed_at: Time.current + 2.days) }- let!(:order_3) { create(:order, state: 'complete', user: user, completed_at: Time.current + 3.days) }-- context 'sorting by completed_at' do- context 'ascending order' do- before { get '/api/v2/storefront/account/orders?sort=completed_at', headers: headers_bearer }-- it 'returns orders sorted by completed_at' do- expect(json_response['data'].count).to eq store.orders.count- expect(json_response['data'].pluck(:id)).to eq store.orders.select('*').order(completed_at: :asc).pluck(:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/storefront/account/orders?sort=-completed_at', headers: headers_bearer }-- it 'returns orders sorted by completed_at' do- expect(json_response['data'].count).to eq store.orders.count- expect(json_response['data'].pluck(:id)).to eq store.orders.select('*').order(completed_at: :desc).pluck(:id).map(&:to_s)- end- end- end- end-- context 'do not return orders from different stores' do- let!(:order_2) { create(:order, state: 'complete', user: user, completed_at: Time.current, store: create(:store)) }-- before { get '/api/v2/storefront/account/orders', headers: headers_bearer }-- it 'returns orders sorted by completed_at' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].pluck(:id)).not_to include(order_2.id.to_s)- end- end-- context 'with missing authorization token' do- before { get '/api/v2/storefront/account/orders' }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'orders#show' do- let(:user) { create(:user_with_addresses) }- let(:order) { create(:order, state: 'complete', user: user, completed_at: Time.current, store: store) }-- context 'without option: include' do- before { get "/api/v2/storefront/account/orders/#{order.number}", headers: headers_bearer }-- it 'returns valid order JSON' do- expect_order_json(json_response['data'])- end- end-- context 'with option: include' do- before { get "/api/v2/storefront/account/orders/#{order.number}?include=billing_address", headers: headers_bearer }-- it 'returns valid order JSON' do- expect_order_json(json_response['data'])- end-- it 'return hash with included' do- expect(json_response['included']).to be_present- expect(json_response['included'][0]).to have_type('address')- end- end-- context 'with missing order number' do- before { get '/api/v2/storefront/account/orders/23212', headers: headers_bearer }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with missing authorization token' do- before { get '/api/v2/storefront/account/orders' }-- it_behaves_like 'returns 403 HTTP status'- end-- context 'do not return order from different stores' do- let!(:order_2) { create(:order, state: 'complete', user: user, completed_at: Time.current, store: create(:store)) }-- before { get "/api/v2/storefront/account/orders/#{order_2.number}", headers: headers_bearer }-- it_behaves_like 'returns 404 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/account_spec.rbdeleted file mode 100644index aa7340b271..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/account_spec.rb+++ /dev/null@@ -1,279 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Account spec', type: :request do- include_context 'API v2 tokens'-- let!(:user) { create(:user_with_addresses) }- let(:headers) { headers_bearer }-- shared_examples 'mock tests for failed user saving' do- it { expect(service).to receive(:call).with(permitted_params).and_return(result) }- it { expect(result).to receive(:success?).and_return(false) }- it { expect(result).to receive(:error).and_return(error) }- it { expect(error).to receive_message_chain(:full_messages, :to_sentence).and_return("Password Confirmation doesn't match Password") }- end-- shared_context 'stubs for failed user saving' do- before do- allow(service).to receive(:call).with(permitted_params).and_return(result)- allow(result).to receive(:success?).and_return(false)- allow(result).to receive(:error).and_return(error)- allow(error).to receive(:is_a?).with(ActiveModel::Errors).and_return(true)- allow(error).to receive(:messages).and_return({ password_confirmation: "doesn't match Password" })- allow(error).to receive_message_chain(:full_messages, :to_sentence).and_return("Password Confirmation doesn't match Password")- end- end-- shared_examples 'password mismatched error' do- it 'returns error' do- expect(json_response['error']).to eq "Password Confirmation doesn't match Password"- end- end-- describe 'account#show' do- before do- user.reload-- allow_any_instance_of(Spree.user_class).to receive(:first_name).and_return(user.first_name)- allow_any_instance_of(Spree.user_class).to receive(:last_name).and_return(user.last_name)-- get '/api/v2/storefront/account', headers: headers- end-- it 'return JSON API payload of User and associations (default billing and shipping address)' do- expect(json_response['data']).to have_id(user.id.to_s)- expect(json_response['data']).to have_type('user')- expect(json_response['data']).to have_relationships(:default_shipping_address, :default_billing_address)-- expect(json_response['data']).to have_attribute(:email).with_value(user.email)- expect(json_response['data']).to have_attribute(:store_credits).with_value(user.total_available_store_credit)- expect(json_response['data']).to have_attribute(:first_name).with_value(user.first_name)- expect(json_response['data']).to have_attribute(:last_name).with_value(user.last_name)- expect(json_response['data']).to have_attribute(:completed_orders).with_value(user.orders.complete.count)- expect(json_response['data']).to have_attribute(:public_metadata).with_value(user.public_metadata)- end-- context 'with params "include=default_billing_address"' do- before { get '/api/v2/storefront/account?include=default_billing_address', headers: headers }-- it 'returns account data with included default billing address' do- expect(json_response['included']).to include(have_type('address'))- expect(json_response['included'][0]).to eq(Spree::V2::Storefront::AddressSerializer.new(user.billing_address).as_json['data'])- end- end-- context 'with params "include=default_shipping_address"' do- before { get '/api/v2/storefront/account?include=default_shipping_address', headers: headers }-- it 'returns account data with included default shipping address' do- expect(json_response['included']).to include(have_type('address'))- expect(json_response['included'][0]).to eq(Spree::V2::Storefront::AddressSerializer.new(user.shipping_address).as_json['data'])- end- end-- context 'with params include=default_billing_address,default_shipping_address' do- before { get '/api/v2/storefront/account?include=default_billing_address,default_shipping_address', headers: headers }-- it 'returns account data with included default billing and shipping addresses' do- expect(json_response['included']).to include(have_type('address'))- expect(json_response['included'][0]).to eq(Spree::V2::Storefront::AddressSerializer.new(user.billing_address).as_json['data'])- expect(json_response['included'][1]).to eq(Spree::V2::Storefront::AddressSerializer.new(user.shipping_address).as_json['data'])- end- end-- context 'as a guest user' do- let(:headers) { {} }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'users#create' do- let(:default_bill_address) { create(:address) }- let(:default_ship_address) { create(:address) }- let(:new_attributes) do- {- email: '[email protected]',- password: 'newpassword123',- password_confirmation: 'newpassword123',- bill_address_id: default_bill_address.id.to_s,- ship_address_id: default_ship_address.id.to_s,- first_name: 'Peter',- last_name: 'Parker',- public_metadata: { 'has_other_account' => 'true' },- private_metadata: { 'shops_in_other_stores' => 'false' }- }- end- let(:params) { { user: new_attributes } }-- before { post "/api/v2/storefront/account", params: params }-- context 'valid request' do- it 'creates and returns user' do- created_user = Spree.user_class.last- expect(json_response['data']['id']).to eq created_user.id.to_s- expect(json_response['data']).to have_attribute(:email).with_value(new_attributes[:email])- expect(json_response['data']).to have_attribute(:first_name).with_value(new_attributes[:first_name])- expect(json_response['data']).to have_attribute(:last_name).with_value(new_attributes[:last_name])- expect(json_response['data']).to have_attribute(:public_metadata).with_value(new_attributes[:public_metadata])- expect(created_user.private_metadata).to eq(new_attributes[:private_metadata])- expect(json_response.size).to eq(1)- end-- it 'does not create user default bill_address and ship_address' do- expect(json_response['data']['relationships']['default_billing_address']).to eq ({ "data" => nil })- expect(json_response['data']['relationships']['default_shipping_address']).to eq ({ "data" => nil })- end- end-- context 'invalid request' do- let(:new_attributes) do- {- email: '[email protected]',- password: 'newpassword123',- password_confirmation: ''- }- end- let(:service) { double(Spree::Account::Create) }- let(:permitted_params) { {user_params: ActionController::Parameters.new(params).require(:user).permit!} }- let(:result) { instance_double(Spree::ServiceModule::Result) }- let(:error) { instance_double(ActiveModel::Errors) }-- before do- allow(Spree).to receive_message_chain(:api, :storefront_account_create_service).and_return(service)- end-- include_context 'stubs for failed user saving'-- describe 'mocks' do- after { post "/api/v2/storefront/account", params: params }-- it { expect(Spree).to receive_message_chain(:api, :storefront_account_create_service).and_return(service) }-- it_behaves_like 'mock tests for failed user saving'- end-- describe 'response' do- before { post "/api/v2/storefront/account", params: params }-- it_behaves_like 'password mismatched error'- end- end- end-- describe 'users#update' do- let(:new_attributes) do- {- email: '[email protected]',- first_name: 'Michael',- last_name: 'Scott',- password: 'newpassword123',- password_confirmation: 'newpassword123',- bill_address_id: new_default_bill_address.id.to_s,- ship_address_id: new_default_ship_address.id.to_s- }- end- let(:params) { { user: new_attributes } }-- context 'valid request' do- context 'all params passed' do- let(:new_default_bill_address) { create(:address, user: user) }- let(:new_default_ship_address) { create(:address, user: user) }-- before { patch "/api/v2/storefront/account", params: params, headers: headers }-- it 'updates and returns user' do- expect(json_response['data']).to have_id(user.id.to_s)- expect(json_response['data']).to have_attribute(:email).with_value(new_attributes[:email])- expect(json_response['data']).to have_attribute(:first_name).with_value(new_attributes[:first_name])- expect(json_response['data']).to have_attribute(:last_name).with_value(new_attributes[:last_name])- expect(json_response['data']).to have_relationship(:default_billing_address)- .with_data({ 'id' => new_default_bill_address.id.to_s, 'type' => 'address' })- expect(json_response['data']).to have_relationship(:default_shipping_address)- .with_data({ 'id' => new_default_ship_address.id.to_s, 'type' => 'address' })- expect(json_response.size).to eq(1)- end- end-- context 'with only email passed' do- let(:new_attributes) do- {- email: '[email protected]'- }- end-- before { patch "/api/v2/storefront/account", params: params, headers: headers }-- it 'updates only email' do- expect(json_response['data']).to have_id(user.id.to_s)- expect(json_response['data']).to have_attribute(:email).with_value(new_attributes[:email])- expect(json_response['data']).to have_relationship(:default_billing_address)- .with_data({ 'id' => user.bill_address_id.to_s, 'type' => 'address' })- expect(json_response['data']).to have_relationship(:default_shipping_address)- .with_data({ 'id' => user.ship_address_id.to_s, 'type' => 'address' })- expect(json_response.size).to eq(1)- end- end- end-- context 'invalid request' do- context 'wrong default address' do- let!(:other_user) { create(:user_with_addresses) }- let(:new_default_bill_address) { create(:address, user: other_user) }- let(:new_default_ship_address) { create(:address, user: other_user) }-- before { patch "/api/v2/storefront/account", params: params, headers: headers }-- it 'returns errors' do- expect(json_response['errors']).to eq(- 'bill_address_id' => ["belongs to other user"],- 'ship_address_id' => ["belongs to other user"]- )- end- end-- context 'password mismatch error' do- let(:new_attributes) do- {- email: '[email protected]',- password: 'newpassword123',- password_confirmation: ''- }- end- let(:service) { double(Spree::Account::Update) }- let(:permitted_params) { { user_params: ActionController::Parameters.new(params).require(:user).permit!, user: user } }- let(:result) { instance_double(Spree::ServiceModule::Result) }- let(:error) { instance_double(ActiveModel::Errors) }-- before do- allow(Spree).to receive_message_chain(:api, :storefront_account_update_service).and_return(service)- end-- include_context 'stubs for failed user saving'-- describe 'mocks' do- after { patch "/api/v2/storefront/account", params: params, headers: headers }-- it { expect(Spree).to receive_message_chain(:api, :storefront_account_update_service).and_return(service) }-- it_behaves_like 'mock tests for failed user saving'- end-- describe 'response' do- before { patch "/api/v2/storefront/account", params: params, headers: headers }-- it_behaves_like 'password mismatched error'- end- end- end-- context 'with missing authorization token' do- let(:new_default_bill_address) { create(:address, user: user) }- let(:new_default_ship_address) { create(:address, user: user) }-- before { patch "/api/v2/storefront/account", params: params }-- it_behaves_like 'returns 403 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/cart_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/cart_spec.rbdeleted file mode 100644index 14a80141b2..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/cart_spec.rb+++ /dev/null@@ -1,1130 +0,0 @@-require 'spec_helper'--describe 'API V2 Storefront Cart Spec', type: :request do- let!(:store) { create(:store) }- let!(:store_credit_payment_method) { create(:store_credit_payment_method, stores: [store]) }- let(:currency) { store.default_currency }- let(:user) { create(:user) }- let(:order) { create(:order, user: user, store: store, currency: currency) }- let(:product) { create(:product, stores: [store]) }- let(:variant) { create(:variant, product: product) }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::CartController).to receive(:current_store).and_return(store)- end-- include_context 'API v2 tokens'-- shared_examples 'coupon code error' do- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response[:error]).to eq("The coupon code you entered doesn't exist. Please try again.")- end- end-- shared_context 'coupon codes' do- let!(:line_item) { create(:line_item, order: order) }- let!(:shipment) { create(:shipment, order: order) }- let!(:promotion) { create(:promotion, name: 'Free shipping', code: 'freeship', stores: [store]) }- let(:coupon_code) { promotion.code }- let!(:promotion_action) { Spree::PromotionAction.create(promotion_id: promotion.id, type: 'Spree::Promotion::Actions::FreeShipping') }- end-- describe 'cart#create' do- let(:order) { Spree::Order.last }- let(:params) { {} }- let(:execute) { post '/api/v2/storefront/cart', headers: headers, params: params }-- shared_examples 'sets public and private metadata' do- let(:params) do- {- public_metadata: { 'property1' => 'value1' },- private_metadata: { 'property2' => 'value2' }- }- end-- it do- expect(order.public_metadata).to eq(params[:public_metadata])- expect(order.private_metadata).to eq(params[:private_metadata])- end- end-- shared_examples 'creates an order' do- before { execute }-- it_behaves_like 'returns valid cart JSON'- it_behaves_like 'returns 201 HTTP status'- it_behaves_like 'sets public and private metadata'- end-- shared_examples 'creates an order with different currency' do- context 'store default' do- before do- store.default_currency = 'EUR'- store.save!- execute- end-- it_behaves_like 'returns valid cart JSON'- it_behaves_like 'returns 201 HTTP status'-- it 'sets requested currency' do- expect(json_response['data']).to have_attribute(:currency).with_value('EUR')- end- end-- context 'currency passed as a param' do- let(:params) { { currency: 'EUR' } }-- before { execute }-- it_behaves_like 'returns valid cart JSON'- it_behaves_like 'returns 201 HTTP status'-- it 'sets requested currency' do- expect(json_response['data']).to have_attribute(:currency).with_value('EUR')- end- end- end-- context 'as a signed in user' do- let(:headers) { headers_bearer }-- it_behaves_like 'creates an order'- it_behaves_like 'creates an order with different currency'-- context 'user association' do- before { execute }-- it 'associates order with user' do- expect(json_response['data']).to have_relationship(:user).with_data('id' => user.id.to_s, 'type' => 'user')- end-- context 'with canceled order' do- let(:order) { create(:order, user: user, store: store, currency: currency, state: 'canceled') }-- before { execute }-- it_behaves_like 'returns 201 HTTP status'-- it 'returns a valid cart JSON response with new order' do- new_order = Spree::Order.find(json_response['data']['id'])- expect(json_response['data']).to be_present- expect(json_response['data']).to have_id(new_order.id.to_s)- expect(json_response['data']).to have_type('cart')- expect(json_response['data']).to have_attribute(:number).with_value(new_order.number)- expect(json_response['data']).to have_attribute(:state).with_value(new_order.state)- expect(json_response['data']).to have_attribute(:payment_state).with_value(new_order.payment_state)- expect(json_response['data']).to have_attribute(:shipment_state).with_value(new_order.shipment_state)- expect(json_response['data']).to have_attribute(:token).with_value(new_order.token)- expect(json_response['data']).to have_attribute(:total).with_value(new_order.total.to_s)- expect(json_response['data']).to have_attribute(:total_minus_store_credits).with_value(new_order.total_minus_store_credits.to_s)- expect(json_response['data']).to have_attribute(:display_total_minus_store_credits).with_value(new_order.display_total_minus_store_credits.to_s)- expect(json_response['data']).to have_attribute(:item_total).with_value(new_order.item_total.to_s)- expect(json_response['data']).to have_attribute(:ship_total).with_value(new_order.ship_total.to_s)- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(new_order.adjustment_total.to_s)- expect(json_response['data']).to have_attribute(:included_tax_total).with_value(new_order.included_tax_total.to_s)- expect(json_response['data']).to have_attribute(:additional_tax_total).with_value(new_order.additional_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_additional_tax_total).with_value(new_order.display_additional_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_included_tax_total).with_value(new_order.display_included_tax_total.to_s)- expect(json_response['data']).to have_attribute(:tax_total).with_value(new_order.tax_total.to_s)- expect(json_response['data']).to have_attribute(:currency).with_value(new_order.currency.to_s)- expect(json_response['data']).to have_attribute(:email).with_value(new_order.email)- expect(json_response['data']).to have_attribute(:display_item_total).with_value(new_order.display_item_total.to_s)- expect(json_response['data']).to have_attribute(:display_ship_total).with_value(new_order.display_ship_total.to_s)- expect(json_response['data']).to have_attribute(:display_adjustment_total).with_value(new_order.display_adjustment_total.to_s)- expect(json_response['data']).to have_attribute(:display_tax_total).with_value(new_order.display_tax_total.to_s)- expect(json_response['data']).to have_attribute(:item_count).with_value(new_order.item_count)- expect(json_response['data']).to have_attribute(:special_instructions).with_value(new_order.special_instructions)- expect(json_response['data']).to have_attribute(:promo_total).with_value(new_order.promo_total.to_s)- expect(json_response['data']).to have_attribute(:display_promo_total).with_value(new_order.display_promo_total.to_s)- expect(json_response['data']).to have_attribute(:display_total).with_value(new_order.display_total.to_s)- expect(json_response['data']).to have_attribute(:pre_tax_item_amount).with_value(new_order.pre_tax_item_amount.to_s)- expect(json_response['data']).to have_attribute(:display_pre_tax_item_amount).with_value(new_order.display_pre_tax_item_amount.to_s)- expect(json_response['data']).to have_attribute(:pre_tax_total).with_value(new_order.pre_tax_total.to_s)- expect(json_response['data']).to have_attribute(:display_pre_tax_total).with_value(new_order.display_pre_tax_total.to_s)- expect(json_response['data']).to have_attribute(:public_metadata).with_value(new_order.public_metadata)- expect(json_response['data']).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments, :promotions)- end-- it 'does not return canceled order' do- expect(json_response['data']).to have_attribute(:state).with_value('cart')- end-- it 'creates the new order without line items' do- expect(Spree::Order.find(json_response['data']['id']).line_items.count).to eq(0)- end- end- end- end-- context 'as a guest user' do- let(:headers) { {} }-- it_behaves_like 'creates an order'- it_behaves_like 'creates an order with different currency'- end- end-- describe 'cart#add_item' do- let(:options) { {} }- let(:params) do- {- variant_id: variant.id,- quantity: 5,- public_metadata: { 'prop1' => 'value1' },- private_metadata: { 'prop2' => 'value2' },- options: options,- include: 'variants'- }- end- let(:execute) { post '/api/v2/storefront/cart/add_item', params: params, headers: headers }-- before do- Spree::PermittedAttributes.line_item_attributes << :cost_price- end-- shared_examples 'adds item' do- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'with success' do- order.reload-- expect(order.line_items.count).to eq(2)- expect(order.line_items.last.variant).to eq(variant)- expect(order.line_items.last.quantity).to eq(5)- expect(order.line_items.last.public_metadata).to eq(params[:public_metadata])- expect(order.line_items.last.private_metadata).to eq(params[:private_metadata])- expect(json_response['included']).to include(have_type('variant').and(have_id(variant.id.to_s)))- end-- context 'with options' do- let(:options) { { cost_price: 1.99 } }-- it 'sets custom attributes values' do- order.reload-- expect(order.line_items.last.cost_price).to eq(1.99)- end- end- end-- shared_examples 'doesnt add item with quantity unnavailble' do- before do- variant.stock_items.first.update(backorderable: false)- params[:quantity] = 11- execute- end-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response[:error]).to eq("Quantity selected of \"#{variant.name} (#{variant.options_text})\" is not available.")- end- end-- shared_examples 'doesnt add item from different store' do- before do- variant.product.stores = [create(:store)]- execute- end-- it 'returns an error' do- expect(response.status).to eq(404)- expect(json_response[:error]).to eq('The resource you were looking for could not be found.')- end- end-- shared_examples 'doesnt add non-existing item' do- before do- variant.destroy- execute- end-- it 'returns an error' do- expect(response.status).to eq(404)- expect(json_response[:error]).to eq('The resource you were looking for could not be found.')- end- end-- shared_examples 'doesnt add item if metadata is not a hash' do- before do- params[:public_metadata] = [1, 2, 3]- execute- end-- it 'return an error' do- expect(response.status).to eq(422)- expect(json_response[:error]).to eq(I18n.t(:invalid_params, scope: 'spree.api.v2.metadata'))- end- end-- shared_examples 'doesnt add item with no price with cart currency' do- let(:variant) { create(:variant, product: product) }- let(:price) { create(:price, currency: 'MKD') }-- before do- variant.default_price = price- variant.save- execute- end-- it 'returns an error' do- expect(json_response[:error]).to eq("#{variant.name} is not available in #{order.currency}")- end- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- context 'with existing order' do- it_behaves_like 'adds item'- it_behaves_like 'doesnt add item with quantity unnavailble'- it_behaves_like 'doesnt add item from different store'- it_behaves_like 'doesnt add non-existing item'- it_behaves_like 'doesnt add item with no price with cart currency'- it_behaves_like 'doesnt add item if metadata is not a hash'- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- context 'with existing order' do- it_behaves_like 'adds item'- it_behaves_like 'doesnt add item with quantity unnavailble'- it_behaves_like 'doesnt add item from different store'- it_behaves_like 'doesnt add non-existing item'- it_behaves_like 'doesnt add item with no price with cart currency'- it_behaves_like 'doesnt add item if metadata is not a hash'- end-- it_behaves_like 'no current order'- end- end-- describe 'cart#remove_line_item' do- let(:execute) { delete "/api/v2/storefront/cart/remove_line_item/#{line_item.id}", headers: headers }-- shared_examples 'removes line item' do- before { execute }-- context 'without line items' do- let!(:line_item) { create(:line_item) }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'containing line item' do- let!(:line_item) { create(:line_item, order: order) }-- it_behaves_like 'returns valid cart JSON'-- it 'removes line item from the cart' do- expect(order.line_items.count).to eq(0)- end- end- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- context 'with existing order' do- it_behaves_like 'removes line item'- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- context 'with existing order' do- it_behaves_like 'removes line item'- end-- it_behaves_like 'no current order'- end- end-- describe 'cart#empty' do- let(:execute) { patch '/api/v2/storefront/cart/empty', headers: headers }-- shared_examples 'emptying the order' do- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'empties the order' do- expect(order.reload.line_items.count).to eq(0)- end- end-- context 'as a signed in user' do- context 'with existing order with line item' do- include_context 'order with a physical line item'-- it_behaves_like 'emptying the order'- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- context 'with existing guest order with line item' do- include_context 'creates guest order with guest token'-- it_behaves_like 'emptying the order'- end-- it_behaves_like 'no current order'- end- end-- describe 'cart#destroy' do- let(:execute) { delete '/api/v2/storefront/cart', headers: headers }-- shared_examples 'destroying order' do- it 'destroys the order' do- expect { execute }.to change { Spree::Order.count }.by(-1)- end- end-- shared_examples '204 status returned' do- before { execute }-- it_behaves_like 'returns 204 HTTP status'- end-- context 'as a signed in user' do- context 'with existing order with line item' do- include_context 'order with a physical line item'-- it_behaves_like 'destroying order'- it_behaves_like '204 status returned'- it_behaves_like 'no current order'- end- end-- context 'as a guest user' do- context 'with existing guest order with line item' do- include_context 'creates guest order with guest token'-- it_behaves_like 'destroying order'- it_behaves_like '204 status returned'- it_behaves_like 'no current order'- end- end- end-- describe 'cart#set_quantity' do- let(:line_item) { create(:line_item, order: order) }- let(:params) { { order: order, line_item_id: line_item.id, quantity: 5 } }- let(:execute) { patch '/api/v2/storefront/cart/set_quantity', params: params, headers: headers }-- shared_examples 'wrong quantity parameter' do- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response[:error]).to eq('Quantity has to be greater than 0')- end- end-- shared_examples 'set quantity' do- context 'non-existing line item' do- before do- params[:line_item_id] = 9999- execute- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with insufficient stock quantity and non-backorderable item' do- before do- line_item.variant.stock_items.first.update(backorderable: false)- execute- end-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response[:error]).to eq("Quantity selected of \"#{line_item.name}\" is not available.")- end- end-- context 'changes the quantity of line item' do- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'successfully changes the quantity' do- expect(line_item.reload.quantity).to eq(5)- end- end-- context '0 passed as quantity' do- before do- params[:quantity] = 0- execute- end-- it_behaves_like 'wrong quantity parameter'- end-- context 'quantity not passed' do- before do- params[:quantity] = nil- execute- end-- it_behaves_like 'wrong quantity parameter'- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'set quantity'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'set quantity'- end- end-- describe 'cart#show' do- let(:params) { {} }-- shared_examples 'showing the cart' do- before do- get '/api/v2/storefront/cart', headers: headers, params: params- end-- it_behaves_like 'returns valid cart JSON'- end-- shared_examples 'showing 404' do- before do- get '/api/v2/storefront/cart', headers: headers- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'without existing order' do- let!(:headers) { headers_bearer }-- it_behaves_like 'showing 404'- end-- context 'with existing user order with line item' do- include_context 'order with a physical line item'-- it_behaves_like 'showing the cart'- end-- context 'with existing guest order' do- include_context 'creates guest order with guest token'-- it_behaves_like 'showing the cart'- end-- context 'for specified currency' do- context 'store default' do- include_context 'creates guest order with guest token'-- it_behaves_like 'showing the cart'-- it 'includes the same currency' do- get '/api/v2/storefront/cart', headers: headers- expect(json_response['data']).to have_attribute(:currency).with_value('USD')- end- end-- context 'passed as a param' do- let(:currency) { 'EUR' }- let(:params) { { currency: currency } }-- include_context 'creates guest order with guest token'-- it_behaves_like 'showing the cart'-- it 'includes the requested currency' do- get '/api/v2/storefront/cart', headers: headers, params: params- expect(json_response['data']).to have_attribute(:currency).with_value('EUR')- end- end-- context 'as a signed user' do- context 'with valid currency param' do- include_context 'order with a physical line item'- it_behaves_like 'showing the cart'-- it 'includes the requested currency' do- get '/api/v2/storefront/cart', headers: headers, params: { currency: 'USD' }- expect(json_response['data']).to have_attribute(:currency).with_value('USD')- end- end-- context 'with invalid currency param' do- include_context 'order with a physical line item'- it_behaves_like 'showing the cart'-- it 'includes the requested currency' do- get '/api/v2/storefront/cart', headers: headers, params: { currency: 'PLN' }-- expect(json_response['data']['attributes']['currency']).to eq store.default_currency- end- end- end- end-- context 'with option: include' do- let(:bill_addr_params) { { include: 'billing_address' } }- let(:ship_addr_params) { { include: 'shipping_address' } }-- include_context 'order with a physical line item'- it_behaves_like 'showing the cart'-- it 'returns included bill_address' do- get '/api/v2/storefront/cart', params: bill_addr_params, headers: headers- expect(json_response[:included][0]).to have_id(order.bill_address_id.to_s)- expect(json_response[:included][0]).to have_type('address')- expect(json_response[:included][0]).to have_attribute(:firstname).with_value(order.bill_address.firstname)- expect(json_response[:included][0]).to have_attribute(:lastname).with_value(order.bill_address.lastname)- expect(json_response[:included][0]).to have_attribute(:address1).with_value(order.bill_address.address1)- expect(json_response[:included][0]).to have_attribute(:address2).with_value(order.bill_address.address2)- expect(json_response[:included][0]).to have_attribute(:city).with_value(order.bill_address.city)- expect(json_response[:included][0]).to have_attribute(:zipcode).with_value(order.bill_address.zipcode)- expect(json_response[:included][0]).to have_attribute(:phone).with_value(order.bill_address.phone)- expect(json_response[:included][0]).to have_attribute(:state_name).with_value(order.bill_address.state_name_text)- expect(json_response[:included][0]).to have_attribute(:company).with_value(order.bill_address.company)- expect(json_response[:included][0]).to have_attribute(:country_name).with_value(order.bill_address.country_name)- expect(json_response[:included][0]).to have_attribute(:country_iso3).with_value(order.bill_address.country_iso3)- expect(json_response[:included][0]).to have_attribute(:state_code).with_value(order.bill_address.state_abbr)- expect(json_response[:included][0]).to have_attribute(:public_metadata).with_value(order.bill_address.public_metadata)- end-- it 'returns included ship_address' do- addr = create(:address)- order.update(ship_address: addr)-- get '/api/v2/storefront/cart', params: ship_addr_params, headers: headers-- expect(json_response[:included][0]).to have_id(order.ship_address_id.to_s)- expect(json_response[:included][0]).to have_type('address')- expect(json_response[:included][0]).to have_attribute(:firstname).with_value(order.ship_address.firstname)- expect(json_response[:included][0]).to have_attribute(:lastname).with_value(order.ship_address.lastname)- expect(json_response[:included][0]).to have_attribute(:address1).with_value(order.ship_address.address1)- expect(json_response[:included][0]).to have_attribute(:address2).with_value(order.ship_address.address2)- expect(json_response[:included][0]).to have_attribute(:city).with_value(order.ship_address.city)- expect(json_response[:included][0]).to have_attribute(:zipcode).with_value(order.ship_address.zipcode)- expect(json_response[:included][0]).to have_attribute(:phone).with_value(order.ship_address.phone)- expect(json_response[:included][0]).to have_attribute(:state_name).with_value(order.ship_address.state_name_text)- expect(json_response[:included][0]).to have_attribute(:company).with_value(order.ship_address.company)- expect(json_response[:included][0]).to have_attribute(:country_name).with_value(order.ship_address.country_name)- expect(json_response[:included][0]).to have_attribute(:country_iso3).with_value(order.ship_address.country_iso3)- expect(json_response[:included][0]).to have_attribute(:state_code).with_value(order.ship_address.state_abbr)- expect(json_response[:included][0]).to have_attribute(:public_metadata).with_value(order.ship_address.public_metadata)- end- end-- context 'with gift card' do- let(:gift_card) { create(:gift_card, amount: 10, store: store, amount_used: 10) }- let(:order) { create(:order_with_line_items, store: store, user: nil, currency: store.default_currency, gift_card: gift_card) }-- before do- get '/api/v2/storefront/cart', headers: headers_order_token, params: { include: 'gift_card' }- end-- it 'should return an order with gift card' do- expect(response.status).to eq(200)- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.display_code)))- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount).with_value('$10.00')))- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount_remaining).with_value('$0.00')))- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount_used).with_value('$10.00')))- end- end- end-- describe 'cart#apply_coupon_code' do- include_context 'coupon codes'-- let(:params) { { coupon_code: coupon_code, include: 'promotions' } }- let(:execute) { patch '/api/v2/storefront/cart/apply_coupon_code', params: params, headers: headers }-- shared_examples 'apply coupon code' do- before { execute }-- context 'with coupon code for free shipping' do- let(:adjustment_value) { -shipment.cost.to_f }- let(:adjustment_value_in_money) { Spree::Money.new(adjustment_value, currency: order.currency) }-- context 'applies coupon code correctly' do- it_behaves_like 'returns valid cart JSON'-- it 'changes the adjustment total' do- expect(json_response['data']).to have_attribute(:promo_total).with_value(adjustment_value.to_s)- expect(json_response['data']).to have_attribute(:display_promo_total).with_value(adjustment_value_in_money.to_s)- end-- it 'includes the promotion in the response' do- expect(json_response['included']).to include(have_type('promotion').and(have_id(promotion.id.to_s)))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:amount).with_value(adjustment_value.to_s)))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:display_amount).with_value(adjustment_value_in_money.to_s)))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:code).with_value(promotion.code)))- end- end-- context 'does not apply the coupon code' do- let!(:coupon_code) { 'zxr' }-- it_behaves_like 'coupon code error'- end- end-- context 'with coupon code for item discount' do- let(:params) { { coupon_code: coupon_code, include: 'promotions,line_items' } }-- let!(:promotion) { create(:promotion, name: '10% off', code: '10off', stores: [store]) }- let!(:promotion_action) { Spree::Promotion::Actions::CreateItemAdjustments.create(promotion_id: promotion.id, calculator: calculator) }- let(:calculator) { Spree::Calculator::PercentOnLineItem.new(preferred_percent: 10) }-- let(:coupon_code) { promotion.code }-- it_behaves_like 'returns valid cart JSON'-- it 'changes the promo totals on order and line item' do- expect(json_response['data']).to have_attribute(:item_total).with_value('10.0')- expect(json_response['data']).to have_attribute(:ship_total).with_value('100.0')- expect(json_response['data']).to have_attribute(:total).with_value('109.0')- expect(json_response['data']).to have_attribute(:promo_total).with_value('-1.0')- expect(json_response['data']).to have_attribute(:display_promo_total).with_value('-$1.00')-- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:price).with_value('10.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_price).with_value('$10.00')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:total).with_value('9.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_total).with_value('$9.00')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:promo_total).with_value('-1.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_promo_total).with_value('-$1.00')))- end-- it 'includes the promotion in the response' do- expect(json_response['included']).to include(have_type('promotion').and(have_id(promotion.id.to_s)))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:amount).with_value('-1.0')))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:display_amount).with_value('-$1.00')))- expect(json_response['included']).to include(have_type('promotion').and(have_attribute(:code).with_value(promotion.code)))- end- end-- context 'without coupon code' do- context 'does not apply the coupon code' do- let!(:coupon_code) { '' }-- it_behaves_like 'coupon code error'- end- end- end-- shared_examples 'apply gift card coupon code' do- before { execute }-- context 'apply gift card' do- subject(:apply_gift_card) { patch '/api/v2/storefront/cart/apply_coupon_code', params: params, headers: headers }-- let(:execute) { nil }- let(:gift_card) { create(:gift_card, amount: 10, store: store) }- let(:coupon_code) { gift_card.code }- let(:params) { { coupon_code: coupon_code, include: 'gift_card' } }-- it 'applies the gift card' do- apply_gift_card- expect(response.status).to eq(200)- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.display_code)))- end- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- context 'with existing order' do- it_behaves_like 'apply coupon code'- it_behaves_like 'apply gift card coupon code'- end-- it_behaves_like 'no current order'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- context 'with existing order' do- it_behaves_like 'apply coupon code'- it_behaves_like 'apply gift card coupon code'- end-- it_behaves_like 'no current order'- end- end-- describe 'cart#remove_coupon_code' do- let(:execute) { delete "/api/v2/storefront/cart/remove_coupon_code/#{coupon_code}?include=promotions,line_items", headers: headers }-- include_context 'coupon codes'-- shared_examples 'remove coupon code' do- context 'with coupon code applied' do- before do- order.coupon_code = promotion.code- Spree::PromotionHandler::Coupon.new(order).apply- order.save!- end-- it 'has applied promotion' do- expect(order.promotions).to include(promotion)- end-- context 'removes coupon code correctly' do- before { execute }-- it 'changes the adjustment total to 0.0' do- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(0.0.to_s)- end-- it 'doesnt includes the promotion in the response' do- expect(json_response['included']).not_to include(have_type('promotion'))- end- end-- context 'tries to remove not-applied promotion' do- let(:coupon_code) { 'something-else' }-- before { execute }-- it_behaves_like 'coupon code error'- end-- context 'tries to remove an empty string' do- let!(:coupon_code) { '' }-- before { execute }-- it 'changes the adjustment total to 0.0' do- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(0.0.to_s)- end-- it 'doesnt includes the promotion in the response' do- expect(json_response['included']).not_to include(have_type('promotion'))- end- end-- context 'tries to remove nil' do- let(:coupon_code) { nil }-- before { execute }-- it 'changes the adjustment total to 0.0' do- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(0.0.to_s)- end-- it 'doesnt includes the promotion in the response' do- expect(json_response['included']).not_to include(have_type('promotion'))- end- end-- context 'removing the gift card' do- let(:gift_card) { create(:gift_card, store: store) }- let(:coupon_code) { gift_card.code }-- before do- order.apply_gift_card(gift_card)- end-- context 'when gift card is applied' do- before { execute }-- it 'changes the adjustment total to 0.0' do- expect(order.reload.gift_card_id).to be_nil- end- end- end- end-- context 'with coupon code for item discount' do- let(:params) { { coupon_code: coupon_code, include: 'promotions,line_items' } }-- let!(:promotion) { create(:promotion, name: '10% off', code: '10off', stores: [store]) }- let!(:promotion_action) { Spree::Promotion::Actions::CreateItemAdjustments.create(promotion_id: promotion.id, calculator: calculator) }- let(:calculator) { Spree::Calculator::PercentOnLineItem.new(preferred_percent: 10) }-- let(:coupon_code) { promotion.code }-- before do- order.coupon_code = promotion.code- Spree::PromotionHandler::Coupon.new(order).apply- order.save!- end-- it 'changes the promo totals on order and line item' do- expect(order.reload.promotions).to include(promotion)- expect(order.promo_total).to eq(-1.0)- expect(order.line_items.first.reload.promo_total).to eq(-1.0)-- execute-- expect(json_response['data']).to have_attribute(:item_total).with_value('10.0')- expect(json_response['data']).to have_attribute(:ship_total).with_value('100.0')- expect(json_response['data']).to have_attribute(:total).with_value('110.0')- expect(json_response['data']).to have_attribute(:promo_total).with_value('0.0')- expect(json_response['data']).to have_attribute(:display_promo_total).with_value('$0.00')-- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:price).with_value('10.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_price).with_value('$10.00')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:total).with_value('10.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_total).with_value('$10.00')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:promo_total).with_value('0.0')))- expect(json_response['included']).to include(have_type('line_item').and(have_attribute(:display_promo_total).with_value('$0.00')))- end- end-- xcontext 'when multiple coupon codes are applied' do- let!(:promotion_with_item_adjustment) do- create(- :promotion_with_item_adjustment,- code: 'line_item_promo'- )- end-- let!(:promotion_with_order_adjustment) do- create(- :promotion_with_order_adjustment,- code: 'order_promo'- )- end-- before do- order.coupon_code = promotion_with_item_adjustment.code- Spree::PromotionHandler::Coupon.new(order).apply- order.coupon_code = promotion_with_order_adjustment.code- Spree::PromotionHandler::Coupon.new(order).apply- order.save!- end-- it 'has applied promotions' do- expect(order.promotions).to include(promotion_with_item_adjustment, promotion_with_order_adjustment)- end-- context 'removes coupon code correctly' do- let!(:coupon_code) { promotion_with_order_adjustment.code }-- before { execute }-- it 'removes only the order promotion' do- expect(json_response['included']).not_to include(have_type('promotion').and(have_id(promotion_with_order_adjustment.id.to_s)))- expect(json_response['included']).to include(have_type('promotion').and(have_id(promotion_with_item_adjustment.id.to_s)))- end- end-- context 'tries to remove an empty string' do- let!(:coupon_code) { '' }-- before { execute }-- it 'removes both promotions' do- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(0.0.to_s)- expect(json_response['included']).not_to include(have_type('promotion').and(have_id(promotion_with_order_adjustment.id.to_s)))- expect(json_response['included']).not_to include(have_type('promotion').and(have_id(promotion_with_item_adjustment.id.to_s)))- end- end-- context 'tries to remove nil' do- let(:coupon_code) { nil }-- before { execute }-- it 'removes both promotions' do- expect(json_response['data']).to have_attribute(:adjustment_total).with_value(0.0.to_s)- expect(json_response['included']).not_to include(have_type('promotion').and(have_id(promotion_with_order_adjustment.id.to_s)))- expect(json_response['included']).not_to include(have_type('promotion').and(have_id(promotion_with_item_adjustment.id.to_s)))- end- end- end-- context 'without coupon code applied' do- context 'tries to remove not-applied promotion' do- before { execute }-- it_behaves_like 'coupon code error'- end- end-- context 'without coupon code applied' do- context 'tries to remove not-applied promotion' do- before { execute }-- it_behaves_like 'coupon code error'- end-- context 'tries to remove nil' do- let(:coupon_code) { nil }-- before { execute }-- it_behaves_like 'returns 422 HTTP status'- end-- context 'tries to remove an empty string' do- let(:coupon_code) { '' }-- before { execute }-- it_behaves_like 'returns 422 HTTP status'- end- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'remove coupon code'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'remove coupon code'- end- end-- describe 'cart#estimate_shipping_rates' do- let(:order) { create(:order, user: user, store: store, currency: currency) }- let(:params) { { country_iso: 'USA' } }- let(:execute) { get '/api/v2/storefront/cart/estimate_shipping_rates', params: params, headers: headers }-- let(:country) { store.default_country || create(:country_us) }- let(:state) { create(:state, country: country, name: 'New York', abbr: 'NY') }- let(:zone) { create(:zone, name: 'US') }- let(:shipping_method) { create(:shipping_method) }- let(:shipping_method_2) { create(:shipping_method) }- let(:address) { create(:address, country: country, state: state) }-- let(:shipment) { order.shipments.first }- let(:shipping_rate) { shipment.selected_shipping_rate }- let(:shipping_rate_2) { shipment.shipping_rates.where(selected: false).first }-- shared_examples 'returns a list of shipments with shipping rates' do- before do- order.shipping_address = address- zone.countries << country- shipping_method.zones = [zone]- shipping_method_2.zones = [zone]- order.create_proposed_shipments- execute- end-- it 'returns valid shipments JSON' do- [{ shipping_method: shipping_method, shipping_rate: shipping_rate }, { shipping_method: shipping_method_2, shipping_rate: shipping_rate_2 }].each do |shipping|- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:name).with_value(shipping[:shipping_method].name)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:shipping_method_id).with_value(shipping[:shipping_method].id.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:cost).with_value(shipping[:shipping_rate].cost.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:tax_amount).with_value(shipping[:shipping_rate].tax_amount.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:selected).with_value(shipping[:shipping_rate].selected)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:final_price).with_value(shipping[:shipping_rate].final_price.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:free).with_value(shipping[:shipping_rate].free?)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:display_final_price).with_value(shipping[:shipping_rate].display_final_price.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:display_cost).with_value(shipping[:shipping_rate].display_cost.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_attribute(:display_tax_amount).with_value(shipping[:shipping_rate].display_tax_amount.to_s)))- expect(json_response['data']).to include(have_type('shipping_rate').and(have_relationship(:shipping_method).with_data({ 'id' => shipping[:shipping_method].id.to_s, 'type' => 'shipping_method' })))- end- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'returns a list of shipments with shipping rates'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'returns a list of shipments with shipping rates'- end- end-- describe 'cart#associate' do- let(:order) { create(:order, user: assigned_user, store: store, currency: currency) }-- before do- patch '/api/v2/storefront/cart/associate', params: { guest_order_token: guest_order_token }, headers: headers- end-- context 'as a signed in user' do- let(:headers) { headers_bearer }-- context 'when order was not assigned' do- let(:assigned_user) { nil }- let(:guest_order_token) { order.token }-- it_behaves_like 'returns valid cart JSON'- end-- context 'when order was already assigned' do- let(:assigned_user) { create(:user) }- let(:guest_order_token) { order.token }-- it_behaves_like 'returns 422 HTTP status'- end-- context 'when order token is invalid' do- let(:assigned_user) { nil }- let(:guest_order_token) { 'invalid' }-- it_behaves_like 'returns 403 HTTP status'- end- end-- context 'as a guest user' do- let(:headers) {}- let(:assigned_user) { nil }- let(:guest_order_token) { order.token }-- it_behaves_like 'returns 403 HTTP status'- end- end-- describe 'cart#change_currency' do- let(:order) { create(:order, store: store, currency: currency) }- let!(:line_item) { create(:line_item, order: order) }- let!(:price) { create(:price, currency: 'EUR', variant: order.line_items.first.variant) }-- before do- patch '/api/v2/storefront/cart/change_currency', params: { currency: currency, new_currency: new_currency, order_token: order.token }, headers: headers- end-- context 'when switching to supported currency' do- let(:new_currency) { 'EUR' }-- it_behaves_like 'returns valid cart JSON'-- it 'sets cart currency to new currency' do- expect(json_response['data']).to have_attribute(:currency).with_value('EUR')- end- end-- context 'when switching to unsupported currency' do- let(:new_currency) { 'XOF' }-- it_behaves_like 'returns 422 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/checkout_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/checkout_spec.rbdeleted file mode 100644index 0c4184b539..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/checkout_spec.rb+++ /dev/null@@ -1,1219 +0,0 @@-require 'spec_helper'--describe 'API V2 Storefront Checkout Spec', type: :request do- let!(:store) { @default_store }- let(:currency) { store.default_currency }- let(:user) { create(:user) }- let(:order) { create(:order, user: user, store: store, currency: currency) }- let(:payment) { create(:payment, amount: order.total, order: order) }- let(:shipment) { create(:shipment, order: order) }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::CartController).to receive(:current_store).and_return(store)- end-- let(:address) do- {- firstname: 'John',- lastname: 'Doe',- address1: '7735 Old Georgetown Road',- city: 'Bethesda',- phone: '3014445002',- zipcode: '20814',- state_id: state.id,- country_iso: country.iso- }- end-- let(:payment_source_attributes) do- {- gateway_payment_profile_id: 'BGS-123',- gateway_customer_profile_id: 'BGS-123',- month: 1.month.from_now.month,- year: 1.month.from_now.year,- name: 'Spree Commerce',- last_digits: '1111'- }- end- let(:payment_params) do- {- order: {- payments_attributes: [- {- payment_method_id: payment_method.id- }- ]- },- payment_source: {- payment_method.id.to_s => payment_source_attributes- }- }- end-- include_context 'API v2 tokens'-- describe 'checkout#next' do- let(:execute) { patch '/api/v2/storefront/checkout/next', headers: headers }-- shared_examples 'perform next' do- context 'without line items' do- before do- order.line_items.delete_all- execute- end-- it 'cannot transition to address without a line item' do- expect(response.status).to eq(422)- expect(json_response['error']).to include(Spree.t(:there_are_no_items_for_this_order))- end- end-- context 'with line_items and email' do- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'can transition an order to the next state' do- expect(order.reload.state).to eq('address')- expect(json_response['data']).to have_attribute(:state).with_value('address')- end- end-- context 'without payment info' do- before do- order.update_column(:state, 'payment')- execute- end-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response['error']).to include(I18n.t('spree.no_payment_found'))- end-- it 'doesnt advance pass payment state' do- expect(order.reload.state).to eq('payment')- end- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'perform next'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'perform next'- end- end-- describe 'checkout#advance' do- subject(:execute) { patch '/api/v2/storefront/checkout/advance', headers: headers }-- shared_examples 'perform advance' do- context 'with payment data' do- before do- order.update_column(:state, 'payment')- payment- execute- end-- it_behaves_like 'returns valid cart JSON'-- it 'advances an order till complete or confirm step' do- expect(order.reload.state).to eq('confirm')- expect(json_response['data']).to have_attribute(:state).with_value('confirm')- end- end-- context 'without payment data' do- let(:order_state) { 'delivery' }-- before do- order.update_column(:state, order_state)- execute- end-- it_behaves_like 'returns valid cart JSON'-- it 'advances up to the payment state' do- expect(order.reload.state).to eq('payment')- expect(json_response['data']).to have_attribute(:state).with_value('payment')- end-- context 'when targeting the complete state' do- subject(:execute) { patch '/api/v2/storefront/checkout/advance', headers: headers, params: { state: 'complete' } }-- before { execute }-- it 'advances up to the payment state' do- expect(response.status).to eq(422)- expect(order.reload.state).to eq('payment')- end-- it 'responds with an error' do- expect(json_response['error']).to eq(Spree.t(:no_payment_found))- end- end-- context 'when on payment state' do- let(:order_state) { 'payment' }-- it 'advances up to the payment state' do- expect(order.reload.state).to eq('payment')- end-- it 'responds with an error' do- expect(response.status).to eq(422)- expect(json_response['error']).to eq(Spree.t(:no_payment_found))- end- end- end-- context 'on a quick checkout' do- subject(:execute) { patch '/api/v2/storefront/checkout/advance', headers: headers, params: { shipping_method_id: shipping_method_2.id } }-- let!(:order) { create(:order_with_line_items, state: 'address', payments: [create(:payment)], user: user, store: store, currency: currency) }-- let!(:shipping_rate_1) { create(:shipping_rate, shipment: shipment, selected: true, shipping_method: shipping_method_1, cost: 0) }- let!(:shipping_rate_2) { create(:shipping_rate, shipment: shipment, selected: false, shipping_method: shipping_method_2, cost: 20) }-- let(:shipment) { order.shipments.first }- let(:shipping_method_1) { create(:shipping_method, name: 'Standard') }- let(:shipping_method_2) { create(:shipping_method, name: 'Express') }-- before do- allow(controller).to receive(:check_if_quick_checkout).and_return(true)- end-- it 'advances with a new shipping method' do- execute-- expect(response.status).to eq(200)- expect(order.reload.shipping_method.id).to eq(shipping_method_2.id)- end- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'perform advance'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'perform advance'- end- end-- describe 'checkout#complete' do- let(:execute) { patch '/api/v2/storefront/checkout/complete', headers: headers }-- shared_examples 'perform complete' do- before do- order.update_column(:state, 'confirm')- end-- context 'with payment data' do- before do- payment- shipment- execute- end-- it_behaves_like 'returns valid cart JSON'-- it 'completes an order' do- expect(order.reload.state).to eq('complete')- expect(order.completed_at).not_to be_nil- expect(json_response['data']).to have_attribute(:state).with_value('complete')- end- end-- context 'without payment data' do- before { execute }-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response['error']).to include(I18n.t('spree.no_payment_found'))- end- end-- it_behaves_like 'no current order'- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'perform complete'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'perform complete'- end- end-- order_contexts = ['order with a physical line item',- 'order with a digital line item',- 'order with a physical and digital line item'].freeze-- order_contexts.each do |order_context|- describe "checkout#update (#{order_context})" do- let!(:country_zone) { create(:zone, name: 'CountryZone') }- let!(:state) { create(:state) }- let!(:country) { state.country }- let!(:stock_location) { create(:stock_location) }-- let!(:shipping_method) { create(:shipping_method, zones: [country_zone]) }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }-- let(:execute) { patch '/api/v2/storefront/checkout', params: params, headers: headers }-- include_context order_context-- before do- allow_any_instance_of(Spree::PaymentMethod).to receive(:source_required?).and_return(false)- allow_any_instance_of(Spree::Order).to receive_messages(confirmation_required?: true)- allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: true)- end-- shared_examples 'perform update' do- context 'addresses' do- let(:params) do- {- order: {- bill_address_attributes: address,- ship_address_attributes: address- }- }- end-- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'updates addresses' do- order.reload- expect(order.bill_address).not_to be_nil- expect(order.ship_address).not_to be_nil- expect(order.bill_address.firstname).to eq address[:firstname]- expect(order.bill_address.lastname).to eq address[:lastname]- expect(order.bill_address.address1).to eq address[:address1]- expect(order.bill_address.city).to eq address[:city]- expect(order.bill_address.phone).to eq address[:phone]- expect(order.bill_address.zipcode).to eq address[:zipcode]- expect(order.bill_address.state_id).to eq address[:state_id]- expect(order.bill_address.country.iso).to eq address[:country_iso]- end- end-- context 'shipment' do- let!(:default_selected_shipping_rate_id) { shipment.selected_shipping_rate_id }- let(:new_selected_shipping_rate_id) { Spree::ShippingRate.last.id }- let!(:shipping_method) { shipment.shipping_method }- let!(:second_shipping_method) { create(:shipping_method, name: 'Fedex') }-- let(:params) do- {- order: {- shipments_attributes: [- { selected_shipping_rate_id: new_selected_shipping_rate_id, id: shipment.id }- ]- }- }- end-- before do- shipment- shipment.add_shipping_method(second_shipping_method)- execute- end-- it_behaves_like 'returns valid cart JSON'-- it 'updates shipment' do- shipment.reload- expect(shipment.shipping_rates.count).to eq(2)- expect(shipment.selected_shipping_rate_id).to eq(new_selected_shipping_rate_id)- expect(shipment.selected_shipping_rate_id).not_to eq(default_selected_shipping_rate_id)- expect(shipment.shipping_method).to eq(second_shipping_method)- end- end-- context 'payment' do- context 'payment method' do- let(:params) do- {- order: {- payments_attributes: [- {- payment_method_id: payment_method.id- }- ]- }- }- end-- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'updates payment method' do- expect(order.payments).not_to be_empty- expect(order.payments.first.payment_method_id).to eq payment_method.id- end- end-- context 'payment source' do- let(:params) { payment_params }-- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'updates payment method with source' do- expect(order.payments).not_to be_empty- expect(order.payments.last.source.name).to eq('Spree Commerce')- expect(order.payments.last.source.last_digits).to eq('1111')- end- end-- context 'when the gateway rejects the payment source' do- let(:params) { payment_params }-- before do- allow_any_instance_of(Spree::Order).to receive(:update_from_params).and_raise(Spree::Core::GatewayError.new('Card declined'))- execute- end-- it_behaves_like 'returns 422 HTTP status'- end- end-- context 'special instructions' do- let(:params) do- {- order: {- special_instructions: "Don't drop it"- }- }- end-- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'updates the special instructions' do- expect(order.reload.special_instructions).to eq("Don't drop it")- end-- it 'returns updated special instructions' do- expect(json_response['data']).to have_attribute(:special_instructions).with_value("Don't drop it")- end- end-- context 'email' do- let(:params) do- {- order: {- email: '[email protected]'- }- }- end-- before { execute }-- it_behaves_like 'returns valid cart JSON'-- it 'updates email' do- expect(order.reload.email).to eq('[email protected]')- end-- it 'returns updated email' do- expect(json_response['data']).to have_attribute(:email).with_value('[email protected]')- end- end-- context 'with invalid params' do- let(:params) do- {- order: {- email: 'wrong_email'- }- }- end-- before do- order.update_column(:state, 'payment')- execute- end-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Email is invalid')- end-- it 'returns validation errors' do- expect(json_response['errors']).to eq('email' => ['is invalid'])- end- end-- context 'without order' do- let(:params) { {} }-- it_behaves_like 'no current order'- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'perform update'- end-- context 'as a signed in user' do- include_context order_context-- it_behaves_like 'perform update'- end- end- end-- describe 'checkout#update address ownership validation (IDOR protection)' do- let!(:state) { create(:state) }- let!(:country) { state.country }- let(:other_user) { create(:user_with_addresses) }- let(:other_user_address) { other_user.bill_address }- let(:execute) { patch '/api/v2/storefront/checkout', params: params, headers: headers }-- context 'as a signed in user' do- include_context 'creates order with line item'-- context 'when attempting to use another user\'s address via bill_address_attributes' do- let(:params) do- {- order: {- bill_address_attributes: { id: other_user_address.id }- }- }- end-- before { execute }-- it 'returns 422 error' do- expect(response.status).to eq(422)- end-- it 'does not associate the other user\'s address with the order' do- expect(order.reload.bill_address_id).not_to eq(other_user_address.id)- end-- it 'returns an error message' do- expect(json_response['error']).to be_present- end- end-- context 'when attempting to use another user\'s address via ship_address_attributes' do- let(:params) do- {- order: {- ship_address_attributes: { id: other_user_address.id }- }- }- end-- before { execute }-- it 'returns 422 error' do- expect(response.status).to eq(422)- end-- it 'does not associate the other user\'s address with the order' do- expect(order.reload.ship_address_id).not_to eq(other_user_address.id)- end- end-- context 'when using own address' do- let(:user) { create(:user_with_addresses) }- let(:user_address) { user.bill_address }- let(:params) do- {- order: {- bill_address_attributes: { id: user_address.id }- }- }- end-- before { execute }-- it 'returns success' do- expect(response.status).to eq(200)- end- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- context 'when attempting to use another user\'s address' do- let(:params) do- {- order: {- bill_address_attributes: { id: other_user_address.id }- }- }- end-- before { execute }-- it 'returns 422 error' do- expect(response.status).to eq(422)- end-- it 'does not associate the other user\'s address with the order' do- expect(order.reload.bill_address_id).not_to eq(other_user_address.id)- end- end- end- end-- describe 'checkout#add_store_credit' do- let(:order_total) { 500.00 }- let(:params) { { order_token: order.token } }- let(:execute) { post '/api/v2/storefront/checkout/add_store_credit', params: params, headers: headers }-- before do- create(:store_credit_payment_method, stores: [store])- execute- end-- context 'for guest or user without store credit' do- let!(:order) { create(:order, total: order_total, store: store) }-- it_behaves_like 'returns 422 HTTP status'- end-- context 'for user with store credits' do- let!(:store_credit) { create(:store_credit, amount: order_total, store: store) }- let!(:order) { create(:order, user: store_credit.user, total: order_total, store: store) }-- shared_examples 'valid payload' do |amount|- it 'returns StoreCredit payment' do- expect(json_response['data']).to have_relationship(:payments)- payment = Spree::Payment.find(json_response['data']['relationships']['payments']['data'][0]['id'])- expect(payment.amount).to eq amount- expect(payment.payment_method.class).to eq Spree::PaymentMethod::StoreCredit- end- end-- context 'with no amount param' do- it_behaves_like 'valid payload', 500.0- end-- context 'with amount params requested' do- let(:requested_amount) { 300.0 }- let(:params) { { order_token: order.token, amount: requested_amount } }-- it_behaves_like 'valid payload', 300.0- end-- context 'with option include' do- let!(:payment) { Spree::Payment.all.first }-- context 'payments.source' do- let(:execute) { post '/api/v2/storefront/checkout/add_store_credit?include=payments.source', params: params, headers: headers }-- it 'return relationship with store_credit' do- expect(json_response['included'][0]).to have_type('store_credit')-- expect(json_response['included'][0]).to have_attribute(:amount).with_value(payment.source.amount.to_s)- expect(json_response['included'][0]).to have_attribute(:amount_used).with_value(payment.source.amount_used.to_s)- expect(json_response['included'][0]).to have_attribute(:created_at)-- expect(json_response['included'][0]).to have_relationship(:category)- expect(json_response['included'][0]).to have_relationship(:store_credit_events)- expect(json_response['included'][0]).to have_relationship(:credit_type)- end- end-- context 'payments.payment_method' do- let(:execute) { post '/api/v2/storefront/checkout/add_store_credit?include=payments.payment_method', params: params, headers: headers }-- it 'return relationship with payment_method' do- expect(json_response['included'][0]).to have_type('payment_method')-- expect(json_response['included'][0]).to have_attribute(:type).with_value(payment.payment_method.type)- expect(json_response['included'][0]).to have_attribute(:name).with_value(payment.payment_method.name)- expect(json_response['included'][0]).to have_attribute(:description).with_value(payment.payment_method.description)-- expect(json_response['included'][1]).to have_relationship(:source)- expect(json_response['included'][1]).to have_relationship(:payment_method)- end- end- end- end- end-- describe 'checkout#remove_store_credit' do- let(:order_total) { 500.00 }- let(:params) { { order_token: order.token, include: 'payments', fields: { payment: 'state' } } }- let(:execute) { post '/api/v2/storefront/checkout/remove_store_credit', params: params, headers: headers }- let!(:store_credit) { create(:store_credit, amount: order_total, user: user) }-- before do- create(:store_credit_payment_method, stores: [store])- Spree::Checkout::AddStoreCredit.call(order: order)- execute- end-- it 'returns no valid StoreCredit payment' do- expect(json_response['included'].empty?).to eq true- end- end-- describe 'checkout#payment_methods' do- let(:execute) { get '/api/v2/storefront/checkout/payment_methods', headers: headers }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }- let(:payment_methods) { order.collect_frontend_payment_methods }-- shared_examples 'returns a list of available payment methods' do- before { execute }-- it 'returns valid payment methods JSON' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'][0]).to have_id(payment_method.id.to_s)- expect(json_response['data'][0]).to have_type('payment_method')- expect(json_response['data'][0]).to have_attribute(:name).with_value(payment_method.name)- expect(json_response['data'][0]).to have_attribute(:description).with_value(payment_method.description)- expect(json_response['data'][0]).to have_attribute(:type).with_value(payment_method.type)- expect(json_response['data'][0]).to have_attribute(:preferences).with_value(payment_method.public_preferences.as_json)- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'returns a list of available payment methods'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'returns a list of available payment methods'- end- end-- describe 'checkout#create_payment' do- let(:params) do- {- payment_method_id: payment_method.id,- amount: order.total,- source_attributes: {- gateway_payment_profile_id: '12345',- cc_type: 'visa',- last_digits: '1111',- name: 'John',- month: '12',- year: '2021'- }- }- end- let(:execute) { post '/api/v2/storefront/checkout/create_payment?include=payments', headers: headers, params: params }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }- let(:payment_source) { payment_method.payment_source_class.last }- let(:payment) { order.payments.last }-- shared_examples 'creates a payment' do- before { execute }-- it 'returns new payment' do- expect(response.status).to eq(201)- expect(json_response['data']).to have_relationship(:payments).with_data([{ 'id' => payment.id.to_s, 'type' => 'payment' }])- expect(json_response['included'][0]).to have_id(payment.id.to_s)- expect(json_response['included'][0]).to have_type('payment')- expect(json_response['included'][0]).to have_attribute(:amount).with_value(order.total.to_s)- expect(json_response['included'][0]).to have_jsonapi_attributes(:amount, :response_code, :number, :cvv_response_code, :cvv_response_message, :payment_method_id, :payment_method_name, :state)- expect(json_response['included'][0]).to have_relationship(:payment_method).with_data({ 'id' => payment_method.id.to_s, 'type' => 'payment_method' })- end- end-- shared_examples 'creates a payment source' do- let(:execute) { post '/api/v2/storefront/checkout/create_payment?include=payments.source', headers: headers, params: params }-- before { execute }-- it 'returns new payment source' do- expect(json_response['included'][0]).to have_id(payment_source.id.to_s)- expect(json_response['included'][0]).to have_type('credit_card')- expect(json_response['included'][0]).to have_relationship(:payment_method).with_data({ 'id' => payment_method.id.to_s, 'type' => 'payment_method' })- expect(json_response['included'][0]).to have_attribute(:last_digits).with_value('1111')- expect(json_response['included'][0]).to have_attribute(:name).with_value('John')- expect(json_response['included'][0]).to have_attribute(:year).with_value(2021)- expect(json_response['included'][0]).to have_attribute(:month).with_value(12)- end-- it 'creates new payment source record' do- expect { change(payment_method.payment_source_class, :count).by(1) }- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'creates a payment'- it_behaves_like 'creates a payment source'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- context 'new payment source' do- it_behaves_like 'creates a payment'- it_behaves_like 'creates a payment source'-- it 'assigns new payment source to the signed in user' do- expect { execute }.to change(user.credit_cards, :count).by(1)- expect(payment_source.user).to eq(user)- end- end-- context 'existing payment source' do- let!(:payment_source) { create(:credit_card, user: user, payment_method: payment_method) }-- let(:params) do- {- payment_method_id: payment_method.id,- source_id: payment_source.id- }- end-- it_behaves_like 'creates a payment'-- it 'does not create new payment source record' do- expect { execute }.not_to change(payment_method.payment_source_class, :count)- end- end- end- end-- describe 'checkout#shipping_rates' do- let(:execute) { get '/api/v2/storefront/checkout/shipping_rates', headers: headers }-- let(:country) { store.default_country || create(:country_us) }- let(:state) { create(:state, country: country, name: 'New York', abbr: 'NY') }- let(:zone) { create(:zone, name: 'US') }- let(:shipping_method) { create(:shipping_method) }- let(:shipping_method_2) { create(:shipping_method) }- let(:address) { create(:address, country: country, state: state) }-- let(:shipment) { order.shipments.first }- let(:shipping_rate) { shipment.selected_shipping_rate }- let(:shipping_rate_2) { shipment.shipping_rates.where(selected: false).first }-- shared_examples 'returns a list of shipments with shipping rates' do- before do- order.shipping_address = address- order.save!- zone.countries << country- shipping_method.zones = [zone]- shipping_method_2.zones = [zone]- order.create_proposed_shipments- execute- order.reload- end-- it 'returns valid shipments JSON' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'].size).to eq(order.shipments.count)- expect(json_response['data'][0]).to have_id(shipment.id.to_s)- expect(json_response['data'][0]).to have_type('shipment')- expect(json_response['data'][0]).to have_relationships(:shipping_rates)- expect(json_response['included']).to be_present- expect(json_response['included'].size).to eq(shipment.shipping_rates.count + 2)- [{ shipping_method: shipping_method, shipping_rate: shipping_rate }, { shipping_method: shipping_method_2, shipping_rate: shipping_rate_2 }].each do |shipping|- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:name).with_value(shipping[:shipping_method].name)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:shipping_method_id).with_value(shipping[:shipping_method].id.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_relationship(:shipping_method).with_data({ 'id' => shipping[:shipping_method].id.to_s, 'type' => 'shipping_method' })))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_id(shipping[:shipping_rate].id.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:cost).with_value(shipping[:shipping_rate].cost.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:tax_amount).with_value(shipping[:shipping_rate].tax_amount.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:selected).with_value(shipping[:shipping_rate].selected)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:final_price).with_value(shipping[:shipping_rate].final_price.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:free).with_value(shipping[:shipping_rate].free?)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:display_final_price).with_value(shipping[:shipping_rate].display_final_price.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:display_cost).with_value(shipping[:shipping_rate].display_cost.to_s)))- expect(json_response['included']).to include(have_type('shipping_rate').and(have_attribute(:display_tax_amount).with_value(shipping[:shipping_rate].display_tax_amount.to_s)))- end- expect(json_response['included']).to include(have_type('stock_location').and(have_id(shipment.stock_location_id.to_s)))- expect(json_response['included']).to include(have_type('stock_location').and(have_attribute(:name).with_value(shipment.stock_location.name)))- expect(json_response['included']).to include(have_type('line_item').and(have_id(shipment.line_items.first.id.to_s)))- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'returns a list of shipments with shipping rates'- end-- context 'as a signed in user' do- include_context 'order with a physical line item'-- it_behaves_like 'returns a list of shipments with shipping rates'- end- end-- describe 'checkout#select_shipping_method' do- let(:headers) { headers_bearer }- let(:params) do- {- shipping_method_id: shipping_method_2.id- }- end- let(:zone) { create(:zone_with_country) }-- let(:country) { create(:country) }- let(:order) { create(:order_with_totals, store: store, user: user, ship_address: create(:address, user: user, country: country)) }- let(:shipping_category) { order.products.first.shipping_category }- let!(:shipping_method) do- create(:shipping_method, zones: [zone], shipping_categories: [shipping_category]) do |shipping_method|- shipping_method.calculator.preferred_amount = 10- shipping_method.calculator.save- end- end- let!(:shipping_method_2) do- create(:shipping_method, zones: [zone], shipping_categories: [shipping_category]) do |shipping_method|- shipping_method.calculator.preferred_amount = 15- shipping_method.calculator.save- end- end- let!(:shipping_method_3) do- create(:shipping_method, zones: [create(:zone)], shipping_categories: [shipping_category]) do |shipping_method|- shipping_method.calculator.preferred_amount = 5- shipping_method.calculator.save- end- end- let(:shipment) { order.shipments.first }- let(:selected_shipping_rate) { shipment.selected_shipping_rate }- let(:execute) { patch '/api/v2/storefront/checkout/select_shipping_method?include=shipments', headers: headers, params: params }-- before do- zone.countries << country- # making sure our store is in the geo zone supported by shipping method- store.update(checkout_zone: zone)- # generate shipping rates- get '/api/v2/storefront/checkout/shipping_rates', headers: headers- end-- context 'one shipment' do- context 'valid shipping method' do- before { execute }-- it 'sets selected shipping method for shipment' do- expect(json_response['included'][0]).to have_id(shipment.id.to_s)- expect(json_response['included'][0]).to have_type('shipment')- expect(selected_shipping_rate).to be_present- expect(json_response['included'][0]).to have_relationship(:selected_shipping_rate).with_data({ 'id' => selected_shipping_rate.id.to_s, 'type' => 'shipping_rate' })- expect(selected_shipping_rate.shipping_method).to eq(shipping_method_2)- end- end-- context 'missing shipping method' do- let(:params) do- {- shipping_method_id: shipping_method_3.id- }- end-- before { execute }-- it_behaves_like 'returns 422 HTTP status'- end- end- end-- orders_requiring_delivery = ['order with a physical line item', 'order with a physical and digital line item'].freeze-- orders_requiring_delivery.each do |physical_goods_context|- describe "full checkout flow (#{physical_goods_context})" do- let!(:country) { create(:country) }- let(:state) { create(:state, country: country) }- let!(:shipping_method) do- create(:shipping_method).tap do |shipping_method|- shipping_method.zones = [zone]- end- end- let!(:zone) { create(:zone) }- let!(:zone_member) { create(:zone_member, zone: zone, zoneable: country) }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }-- let(:customer_params) do- {- order: {- email: '[email protected]',- bill_address_attributes: address,- ship_address_attributes: address- }- }- end-- let(:shipment_params) do- {- order: {- shipments_attributes: [- { selected_shipping_rate_id: shipping_rate_id, id: shipment_id }- ]- }- }- end-- let(:shipping_rate_id) do- json_response['data'].first['relationships']['shipping_rates']['data'].first['id']- end- let(:shipment_id) { json_response['data'].first['id'] }-- shared_examples 'transitions through checkout from start to finish' do- before do- zone.countries << country- shipping_method.zones = [zone]- end-- it 'completes checkout' do- # we need to set customer information (email, billing & shipping address)- patch '/api/v2/storefront/checkout', params: customer_params, headers: headers- expect(response.status).to eq(200)-- # getting back shipping rates- get '/api/v2/storefront/checkout/shipping_rates', headers: headers- expect(response.status).to eq(200)-- # selecting shipping method- patch '/api/v2/storefront/checkout', params: shipment_params, headers: headers- expect(response.status).to eq(200)-- # getting back list of available payment methods- get '/api/v2/storefront/checkout/payment_methods', headers: headers- expect(response.status).to eq(200)- expect(json_response['data'].first['id']).to eq(payment_method.id.to_s)-- # creating a CC for selected payment method- patch '/api/v2/storefront/checkout', params: payment_params, headers: headers- expect(response.status).to eq(200)-- # complete the checkout- patch '/api/v2/storefront/checkout/complete', headers: headers- expect(response.status).to eq(200)- expect(order.reload.completed_at).not_to be_nil- expect(order.state).to eq('complete')- expect(order.payments.valid.first.payment_method).to eq(payment_method)- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'transitions through checkout from start to finish'- end-- context 'as a signed in user' do- include_context physical_goods_context-- it_behaves_like 'transitions through checkout from start to finish'- end- end- end-- describe 'full checkout flow digital' do- let!(:country) { create(:country) }- let(:state) { create(:state, country: country) }- let!(:shipping_method) do- create(:shipping_method).tap do |shipping_method|- shipping_method.zones = [zone]- end- end- let!(:zone) { create(:zone) }- let!(:zone_member) { create(:zone_member, zone: zone, zoneable: country) }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }-- let(:customer_params) do- {- order: {- email: '[email protected]',- bill_address_attributes: address,- ship_address_attributes: address- }- }- end-- let(:shipment_params) do- {- order: {- shipments_attributes: [- { selected_shipping_rate_id: shipping_rate_id, id: shipment_id }- ]- }- }- end-- let(:shipping_rate_id) do- json_response['data'].first['relationships']['shipping_rates']['data'].first['id']- end- let(:shipment_id) { json_response['data'].first['id'] }-- shared_examples 'transitions through checkout from start to finish' do- before do- zone.countries << country- shipping_method.zones = [zone]- end-- it 'completes checkout skipping delivery stage' do- # we need to set customer information (email, billing & shipping address)- patch '/api/v2/storefront/checkout', params: customer_params, headers: headers- expect(response.status).to eq(200)-- # getting back list of available payment methods- get '/api/v2/storefront/checkout/payment_methods', headers: headers- expect(response.status).to eq(200)- expect(json_response['data'].first['id']).to eq(payment_method.id.to_s)-- # creating a CC for selected payment method- patch '/api/v2/storefront/checkout', params: payment_params, headers: headers- expect(response.status).to eq(200)-- # complete the checkout- patch '/api/v2/storefront/checkout/complete', headers: headers- expect(response.status).to eq(200)- expect(order.reload.completed_at).not_to be_nil- expect(order.state).to eq('complete')- expect(order.payments.valid.first.payment_method).to eq(payment_method)- end- end-- context 'as a guest user' do- include_context 'creates guest order with guest token'-- it_behaves_like 'transitions through checkout from start to finish'- end-- context 'as a signed in user' do- include_context 'order with a digital line item'-- it_behaves_like 'transitions through checkout from start to finish'- end- end-- describe 'checkout#validate_order_for_payment' do- let(:order_state) { 'payment' }-- before do- order.update!(state: order_state)- end-- shared_examples 'validating the order' do- before do- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers- end-- it_behaves_like 'returns valid cart JSON'- end-- shared_examples 'showing 404' do- before do- order.destroy!- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers- end-- it_behaves_like 'returns 404 HTTP status'- end-- context 'when order has line items that were removed' do- include_context 'order with a physical line item'-- let!(:product) { order.line_items.first.product }-- before do- product.update!(status: 'draft')-- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers- end-- it_behaves_like 'returns valid cart JSON'-- it 'returns an error' do- expect(json_response['meta']['messages']).to eq(["#{product.name} was removed because it was discontinued"])- end- end-- context 'when order is not on the payment step' do- include_context 'order with a physical line item'-- let(:order_state) { 'address' }-- before do- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers- end-- it_behaves_like 'returns valid cart JSON'-- it 'returns an error' do- expect(json_response['meta']['messages']).to eq(['Cart changed'])- end- end-- context 'without existing order' do- let!(:headers) { headers_bearer }-- it_behaves_like 'showing 404'- end-- context 'with existing user order with line item' do- include_context 'order with a physical line item'-- it_behaves_like 'validating the order'- end-- context 'with existing guest order' do- include_context 'creates guest order with guest token'-- it_behaves_like 'validating the order'- end-- context 'with skip state validation' do- include_context 'order with a physical line item'-- before do- order.update_column(:state, 'address')- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers, params: { skip_state: true }- end-- it 'returns a valid cart' do- expect(json_response['data']).to have_id(order.id.to_s)- expect(response.status).to eq(200)- end- end-- context 'without skip state validation' do- include_context 'order with a physical line item'-- before do- order.update_column(:state, 'address')- post '/api/v2/storefront/checkout/validate_order_for_payment', headers: headers- end-- it 'returns an error' do- expect(response.status).to eq(422)- expect(json_response['meta']['messages']).to eq(['Cart changed'])- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/countries_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/countries_spec.rbdeleted file mode 100644index d886b3488b..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/countries_spec.rb+++ /dev/null@@ -1,127 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Countries spec', type: :request do- let(:store) { @default_store }- let(:default_country) { store.default_country || create(:country_us) }- let!(:country) { create(:country) }- let!(:states) { create_list(:state, 2, country: country) }-- shared_examples 'returns valid country resource JSON' do- it 'returns a valid country resource JSON response' do- expect(response.status).to eq(200)-- expect(json_response['data']).to have_type('country')- expect(json_response['data']).to have_relationships(:states)-- expect(json_response['data']).to have_attribute(:iso)- expect(json_response['data']).to have_attribute(:iso3)- expect(json_response['data']).to have_attribute(:iso_name)- expect(json_response['data']).to have_attribute(:name)- expect(json_response['data']).to have_attribute(:default)- expect(json_response['data']).to have_attribute(:states_required)- expect(json_response['data']).to have_attribute(:zipcode_required)- end- end-- describe 'countries#index' do- context 'general' do- let!(:countries_list) { create_list(:country, 238) }-- before { get '/api/v2/storefront/countries' }-- it 'returns all countries' do- expect(json_response['data'].size).to eq(Spree::Country.count)- expect(json_response['data'][0]).to have_type('country')- expect(json_response['data'][0]).not_to have_relationships(:states)- end- end-- context 'with shipping country filtering' do- let!(:new_country) { create(:country) }- let!(:zone) { create(:zone_with_country) }- let!(:shipping_method) { create(:shipping_method) }- let(:shippable_url) { '/api/v2/storefront/countries?filter[shippable]=true' }-- def shippable_country_count- Spree::Country.joins(zones: :shipping_methods).distinct.count- end-- it 'returns countries that the current store ships to' do- get shippable_url- expect(json_response['data'].size).to eq(shippable_country_count)- end-- it 'does not return country second time if it appears in multiple zones' do- zone.countries << country- shipping_method.zones << zone- get shippable_url- expect(json_response['data'].size).to eq(shippable_country_count)- end-- it 'returns countries from multiple shipping methods' do- new_shipping_method = create(:shipping_method)- new_shipping_method.zones.first.countries << new_country- get shippable_url- expect(json_response['data'].pluck(:id)).to include(new_country.id.to_s)- end- end- end-- describe 'country#show' do- context 'by iso' do- before do- get "/api/v2/storefront/countries/#{country.iso}"- end-- it_behaves_like 'returns valid country resource JSON'-- it 'returns country by iso' do- expect(json_response['data']).to have_id(country.id.to_s)- expect(json_response['data']).to have_attribute(:iso).with_value(country.iso)- expect(json_response['data']).to have_attribute(:iso3).with_value(country.iso3)- expect(json_response['data']).to have_attribute(:iso_name).with_value(country.iso_name)- expect(json_response['data']).to have_attribute(:name).with_value(country.name)- expect(json_response['data']).to have_attribute(:default).with_value(country == store.default_country)- expect(json_response['data']).to have_attribute(:states_required).with_value(country.states_required)- expect(json_response['data']).to have_attribute(:zipcode_required).with_value(country.zipcode_required)- end- end-- context 'by iso3' do- before do- get "/api/v2/storefront/countries/#{country.iso3}"- end-- it_behaves_like 'returns valid country resource JSON'-- it 'returns country by iso3' do- expect(json_response['data']).to have_id(country.id.to_s)- expect(json_response['data']).to have_attribute(:iso3).with_value(country.iso3)- end- end-- context 'by "default"' do- before do- get '/api/v2/storefront/countries/default'- end-- it_behaves_like 'returns valid country resource JSON'-- it 'returns default country' do- expect(json_response['data']).to have_id(default_country.id.to_s)- expect(json_response['data']).to have_attribute(:iso).with_value(default_country.iso)- expect(json_response['data']).to have_attribute(:default).with_value(true)- end- end-- context 'with specified options' do- before { get "/api/v2/storefront/countries/#{country.iso}?include=states" }-- it 'returns country with included states' do- expect(json_response['data']).to have_id(country.id.to_s)- expect(json_response['included']).to include(have_type('state').and(have_attribute(:abbr).with_value(states.first.abbr)))- expect(json_response['included']).to include(have_type('state').and(have_attribute(:name).with_value(states.first.name)))- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/order_status_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/order_status_spec.rbdeleted file mode 100644index 9dd2f4de5a..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/order_status_spec.rb+++ /dev/null@@ -1,54 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 OrderStatus spec', type: :request do- let(:store) { @default_store }- let!(:order) { create(:order, state: 'complete', completed_at: Time.current, store: store) }- let(:store_2) { create(:store) }- let(:order_2) { create(:order, state: 'complete', completed_at: Time.current, store: store_2) }-- include_context 'API v2 tokens'-- describe '#show' do- context 'with existing Order number' do- context 'as a guest user without token' do- before { get "/api/v2/storefront/order_status/#{order.number}" }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'as a guest user with blank token' do- let(:headers_order_token) { { 'X-Spree-Order-Token' => '' } }-- before { get "/api/v2/storefront/order_status/#{order.number}", headers: headers_order_token }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'as a guest user with invalid token' do- let(:headers_order_token) { { 'X-Spree-Order-Token' => 'WRONG' } }-- before { get "/api/v2/storefront/order_status/#{order.number}", headers: headers_order_token }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'as a guest user with valid token' do- before { get "/api/v2/storefront/order_status/#{order.number}", headers: headers_order_token }-- it_behaves_like 'returns valid cart JSON'- end- end-- context 'with non-existing Order number' do- before { get '/api/v2/storefront/order_status/1' }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with Order from different Store' do- before { get "/api/v2/storefront/order_status/#{order_2.number}", headers: headers_order_token }-- it_behaves_like 'returns 404 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/policies_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/policies_spec.rbdeleted file mode 100644index 3c0e8c3ed8..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/policies_spec.rb+++ /dev/null@@ -1,105 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Policies spec', type: :request do- let(:store) { Spree::Store.default }- let(:other_store) { create(:store, name: 'Other Store') }- let!(:policy) { store.policies.first }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::PoliciesController).to receive(:current_store).and_return(store)- end-- describe 'policies#index' do- let!(:other_store_policy) { create(:policy, slug: 'other-store-policy', owner: other_store) }-- before { get '/api/v2/storefront/policies' }-- it 'returns policies for current store' do- expect(json_response['data'].count).to eq(4)- policy_names = json_response['data'].map { |p| p['attributes']['name'] }- expect(policy_names).to include('Privacy Policy', 'Terms of Service', 'Returns Policy', 'Shipping Policy')- expect(policy_names).not_to include('My Policy') # other store policy- end- end-- describe 'policies#show' do- context 'with slug param' do- before { get "/api/v2/storefront/policies/#{policy.slug}" }-- it 'returns policy with attributes' do- expect(json_response['data']['id']).to eq(policy.id.to_s)- expect(json_response['data']['type']).to eq('policy')- expect(json_response['data']['attributes']['name']).to eq(policy.name)- expect(json_response['data']['attributes']['slug']).to eq(policy.slug)- expect(json_response['data']['attributes']['body']).to eq(policy.body.to_plain_text)- expect(json_response['data']['attributes']['body_html']).to eq(policy.body.to_s)- expect(json_response['data']['attributes']['created_at']).to be_present- expect(json_response['data']['attributes']['updated_at']).to be_present- end- end-- context 'with id param' do- before { get "/api/v2/storefront/policies/#{policy.id}" }-- it 'returns policy with attributes' do- expect(response.status).to eq(200)- expect(json_response['data']['id']).to eq(policy.id.to_s)- end- end-- context 'with locale set to pl' do- let!(:localized_policy) do- policy = create(:policy, owner: store, slug: 'localized-policy', name: 'Privacy Policy EN')-- I18n.with_locale(:pl) do- policy.name = 'Polityka Prywatności'- policy.body = 'To jest polityka prywatności'- policy.save!- end-- policy- end-- before do- store.update!(supported_locales: 'en,pl')- get "/api/v2/storefront/policies/#{localized_policy.slug}?locale=pl"- end-- after do- I18n.locale = :en- store.update!(supported_locales: 'en')- end-- it 'returns policy with translated attributes' do- expect(json_response['data']).to have_attribute(:name).with_value('Polityka Prywatności')- expect(json_response['data']).to have_attribute(:body).with_value('To jest polityka prywatności')- end- end-- context 'with invalid slug param' do- before { get '/api/v2/storefront/policies/non-existent-policy' }-- it 'returns error' do- expect(json_response['error']).to eq('The resource you were looking for could not be found.')- end- end-- context 'with invalid id param' do- before { get '/api/v2/storefront/policies/999999' }-- it 'returns error' do- expect(json_response['error']).to eq('The resource you were looking for could not be found.')- end- end-- context 'accessing policy from different store' do- let(:other_store_policy) { create(:policy, owner: other_store, slug: 'other-policy') }-- before { get "/api/v2/storefront/policies/#{other_store_policy.slug}" }-- it 'returns error when policy belongs to different store' do- expect(json_response['error']).to eq('The resource you were looking for could not be found.')- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/post_categories_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/post_categories_spec.rbdeleted file mode 100644index 71b511261b..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/post_categories_spec.rb+++ /dev/null@@ -1,84 +0,0 @@-require 'spec_helper'--describe 'API V2 Storefront Post Categories Spec', type: :request do- let!(:store) { @default_store }- let!(:admin_user) { create(:admin_user) }- let!(:post_categories) { create_list(:post_category, 3, store: store) }- let!(:post_category_with_posts) { create(:post_category, store: store) }- let!(:published_posts) { create_list(:post, 2, :published, store: store, author: admin_user, post_category: post_category_with_posts) }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::PostCategoriesController).to receive(:current_store).and_return(store)- end-- describe 'post_categories#index' do- context 'with no params' do- before { get '/api/v2/storefront/post_categories' }-- it 'returns all post categories' do- expect(response.status).to eq(200)- expect(json_response['data'].count).to be >= 4- expect(json_response['data'].first).to have_type('post_category')- end-- it 'returns post categories with correct attributes' do- category_data = json_response['data'].first['attributes']- expect(category_data).to include('title', 'slug', 'created_at', 'updated_at', 'description')- end-- it 'does not include posts by default' do- expect(json_response['data'].first).not_to have_relationships(:posts)- end- end-- end-- describe 'post_categories#show' do- let(:category) { post_categories.first }-- context 'with valid id' do- before { get "/api/v2/storefront/post_categories/#{category.id}" }-- it 'returns the post category' do- expect(response.status).to eq(200)- expect(json_response['data']).to have_type('post_category')- expect(json_response['data']['attributes']['title']).to eq(category.title)- end-- it 'includes posts relationship' do- expect(json_response['data']).to have_relationships(:posts)- end- end-- context 'with friendly id (slug)' do- before { get "/api/v2/storefront/post_categories/#{category.slug}" }-- it 'returns the category by slug' do- expect(response.status).to eq(200)- expect(json_response['data']['attributes']['title']).to eq(category.title)- end- end-- context 'with category that has posts' do- before { get "/api/v2/storefront/post_categories/#{post_category_with_posts.id}" }-- it 'returns the category with published posts only' do- expect(response.status).to eq(200)- expect(json_response['data']).to have_relationships(:posts)-- if json_response['included']- posts_data = json_response['included'].select { |item| item['type'] == 'post' }- expect(posts_data.count).to eq(2)- end- end- end-- context 'with invalid id' do- before { get '/api/v2/storefront/post_categories/invalid-id' }-- it 'returns 404' do- expect(response.status).to eq(404)- end- end- end-end\ No newline at end of filediff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/posts_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/posts_spec.rbdeleted file mode 100644index 2744befeb9..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/posts_spec.rb+++ /dev/null@@ -1,172 +0,0 @@-require 'spec_helper'--describe 'API V2 Storefront Posts Spec', type: :request do- let(:store) { @default_store }- let!(:admin_user) { create(:admin_user) }- let!(:post_category) { create(:post_category, store: store) }- let!(:published_posts) { create_list(:post, 3, :published, store: store, author: admin_user, post_category: post_category) }- let!(:unpublished_post) { create(:post, store: store, author: admin_user, published_at: nil) }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::PostsController).to receive(:current_store).and_return(store)- end-- describe 'posts#index' do- context 'with no params' do- before do- allow_any_instance_of(Spree::Api::V2::Storefront::PostsController).to receive(:current_store).and_return(store)- get '/api/v2/storefront/posts'- end-- it 'returns only published posts' do- expect(response.status).to eq(200)- expect(json_response['data'].count).to eq(3)- expect(json_response['data'].first).to have_type('post')- end-- it 'returns posts with correct attributes' do- post_data = json_response['data'].first['attributes']- expect(post_data).to include(- 'title', 'slug', 'published_at', 'meta_title', 'meta_description',- 'created_at', 'updated_at', 'excerpt', 'content', 'description',- 'shortened_description', 'author_name', 'post_category_title', 'tags'- )- end-- it 'includes post category relationship' do- expect(json_response['data'].first).to have_relationships(:post_category)- end- end-- context 'with filtering by category' do- let!(:another_category) { create(:post_category, store: store) }- let!(:posts_in_another_category) { create_list(:post, 2, :published, store: store, author: admin_user, post_category: another_category) }-- before { get "/api/v2/storefront/posts?filter[category_ids]=#{post_category.id}" }-- it 'returns only posts from specified category' do- expect(response.status).to eq(200)- expect(json_response['data'].count).to eq(3)- json_response['data'].each do |post_data|- expect(post_data['relationships']['post_category']['data']['id']).to eq(post_category.id.to_s)- end- end- end-- context 'with search query' do- let!(:searchable_post) { create(:post, :published, title: 'Special Search Title', store: store, author: admin_user) }-- before { get '/api/v2/storefront/posts?q=Special' }-- it 'returns posts matching search query' do- expect(response.status).to eq(200)- expect(json_response['data'].count).to eq(1)- expect(json_response['data'].first['attributes']['title']).to eq('Special Search Title')- end- end-- context 'with sorting' do- let!(:oldest_post) { create(:post, :published, title: 'Oldest Post', published_at: 3.days.ago, store: store, author: admin_user, post_category: post_category) }- let!(:newest_post) { create(:post, :published, title: 'Newest Post', published_at: 1.hour.ago, store: store, author: admin_user, post_category: post_category) }- let!(:middle_post) { create(:post, :published, title: 'Middle Post', published_at: 1.day.ago, store: store, author: admin_user, post_category: post_category) }-- context 'sorting by published_at ascending' do- before { get '/api/v2/storefront/posts?sort=published_at' }-- it 'returns posts sorted by published date ascending' do- expect(response.status).to eq(200)- published_dates = json_response['data'].map { |post| DateTime.parse(post['attributes']['published_at']) }- expect(published_dates).to eq(published_dates.sort)- end- end-- context 'sorting by published_at descending' do- before { get '/api/v2/storefront/posts?sort=-published_at' }-- it 'returns posts sorted by published date descending' do- expect(response.status).to eq(200)- published_dates = json_response['data'].map { |post| DateTime.parse(post['attributes']['published_at']) }- expect(published_dates).to eq(published_dates.sort.reverse)- end- end-- context 'sorting by title ascending' do- before { get '/api/v2/storefront/posts?sort=title' }-- it 'returns posts sorted by title ascending' do- expect(response.status).to eq(200)- titles = json_response['data'].map { |post| post['attributes']['title'] }- expect(titles).to eq(titles.sort)- end- end-- context 'sorting by title descending' do- before { get '/api/v2/storefront/posts?sort=-title' }-- it 'returns posts sorted by title descending' do- expect(response.status).to eq(200)- titles = json_response['data'].map { |post| post['attributes']['title'] }- expect(titles).to eq(titles.sort.reverse)- end- end- end-- context 'with tags filtering' do- let!(:tagged_post) { create(:post, :published, tag_list: ['ruby', 'rails'], store: store, author: admin_user) }-- before { get '/api/v2/storefront/posts?filter[tags]=ruby,rails' }-- it 'returns posts with specified tags' do- expect(response.status).to eq(200)- expect(json_response['data'].any? { |post| post['attributes']['tags'].include?('ruby') }).to be true- end- end- end-- describe 'posts#show' do- let(:post) { published_posts.first }-- context 'with valid id' do- before { get "/api/v2/storefront/posts/#{post.id}" }-- it 'returns the post' do- expect(response.status).to eq(200)- expect(json_response['data']).to have_type('post')- expect(json_response['data']['attributes']['title']).to eq(post.title)- end-- it 'includes all post attributes' do- post_attributes = json_response['data']['attributes']- expect(post_attributes).to include(- 'title', 'slug', 'published_at', 'excerpt', 'content',- 'author_name', 'post_category_title', 'tags'- )- end- end-- context 'with friendly id (slug)' do- before { get "/api/v2/storefront/posts/#{post.slug}" }-- it 'returns the post by slug' do- expect(response.status).to eq(200)- expect(json_response['data']['attributes']['title']).to eq(post.title)- end- end-- context 'with unpublished post id' do- before { get "/api/v2/storefront/posts/#{unpublished_post.id}" }-- it 'returns 404 for unpublished posts' do- expect(response.status).to eq(404)- end- end-- context 'with invalid id' do- before { get '/api/v2/storefront/posts/invalid-id' }-- it 'returns 404' do- expect(response.status).to eq(404)- end- end- end-end\ No newline at end of filediff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/products_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/products_spec.rbdeleted file mode 100644index 99ebc2db86..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/products_spec.rb+++ /dev/null@@ -1,1243 +0,0 @@-require 'spec_helper'--describe 'API V2 Storefront Products Spec', type: :request do- let(:store) { @default_store }- let!(:products) { create_list(:product, 5, stores: [store]) }- let(:taxonomy) { store.taxonomies.first || create(:taxonomy, store: store) }- let(:taxon) { taxonomy.root }- let(:product_with_taxon) { create(:product, taxons: [taxon], stores: [store]) }- let(:product_with_name) { create(:product, name: 'Test Product', stores: [store]) }- let(:product_with_price) { create(:product, price: 13.44, stores: [store]) }- let!(:option_type) { create(:option_type, name: 'test option type') }- let!(:option_value) { create(:option_value, option_type: option_type) }- let(:product_with_option) { create(:product, name: 'Product with Option', option_types: [option_type], stores: [store]) }- let!(:variant) { create(:variant, product: product_with_option, option_values: [option_value]) }- let(:product) { create(:product, stores: [store]) }- let!(:deleted_product) { create(:product, deleted_at: Time.current - 1.day, stores: [store]) }- let!(:discontinued_product) { create(:product, status: 'archived', discontinue_on: Time.current - 1.day, stores: [store]) }- let!(:not_available_product) { create(:product, status: 'draft', stores: [store]) }- let!(:in_stock_product) { create(:product_in_stock, stores: [store]) }- let!(:not_backorderable_product) { create(:product_in_stock, :without_backorder, stores: [store]) }- let!(:property) { create(:property) }- let!(:new_property) { create(:property) }- let!(:product_with_property) { create(:product, stores: [store]) }- let!(:product_property) { create(:product_property, property: new_property, product: product_with_property, value: 'Some Value') }- let!(:product_property2) { create(:product_property, property: property, product: product_with_property, value: 'Some Value 2') }-- # We need to make sure that the default locale is reset before and after every test case- before do- I18n.default_locale = :en- allow(Spree::Api::Config).to receive(:[]).and_call_original- allow(Spree::Api::Config).to receive(:[]).with(:api_v2_per_page_limit).and_return(4)- allow_any_instance_of(Spree::Api::V2::Storefront::ProductsController).to receive(:current_store).and_return(store)- end-- after { I18n.locale = :en }-- describe 'products#index' do- context 'with no params' do- before { get '/api/v2/storefront/products' }-- it 'returns all products' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].first).to have_type('product')- end- end-- context 'when product associated with two stores' do- let!(:new_store_taxonomy) { create(:taxonomy, store: store) }- let(:store2) { create(:store) }- let(:taxonomy2) { create(:taxonomy, store: store2) }- let!(:taxon2) { taxonomy2.root }-- before do- product_with_taxon.stores << store2- product_with_taxon.taxons << taxon2- end-- shared_examples 'should not return not related taxon' do- it do- expect(json_response['data'][0]).not_to have_relationship(:taxons).with_data([{ 'id' => new_store_taxonomy.id.to_s, 'type' => 'taxon' }])- end- end-- context 'when current store is store' do- before { get "/api/v2/storefront/products?filter[ids]=#{product_with_taxon.id}" }-- it 'returns only store taxons ralated to product', :aggregate_failures do- expect(json_response['data'][0]).to have_relationship(:taxons).with_data([{ 'id' => taxon.id.to_s, 'type' => 'taxon' }])- expect(json_response['data'][0]).not_to have_relationship(:taxons).with_data([{ 'id' => taxon2.id.to_s, 'type' => 'taxon' }])- end-- it_behaves_like 'should not return not related taxon'- end-- context 'when current store is store2' do- before do- allow_any_instance_of(Spree::Api::V2::Storefront::ProductsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/products?filter[ids]=#{product_with_taxon.id}"- end-- it 'returns only store2 taxons ralated to product', :aggregate_failures do- expect(json_response['data'][0]).to have_relationship(:taxons).with_data([{ 'id' => taxon2.id.to_s, 'type' => 'taxon' }])- expect(json_response['data'][0]).not_to have_relationship(:taxons).with_data([{ 'id' => taxon.id.to_s, 'type' => 'taxon' }])- end-- it_behaves_like 'should not return not related taxon'- end- end-- context 'current store' do- let(:store_2) { create(:store) }- let!(:product_from_another_store) { create(:product, stores: [store_2]) }-- before { get '/api/v2/storefront/products' }-- it 'returns products from this store only' do- expect(json_response['data'].count).to eq store.products.available.count- product_ids = json_response['data'].map(&:first).map(&:last)-- expect(product_ids).not_to include(product_from_another_store.id)- expect(product_ids).to eq(store.products.available.ids.map(&:to_s))- end- end-- context 'with specified ids' do- before { get "/api/v2/storefront/products?filter[ids]=#{products.first.id}" }-- it 'returns products with specified ids' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(products.first.id.to_s)- end- end-- context 'with specified skus' do- before { get "/api/v2/storefront/products?filter[skus]=#{products.first.default_variant.sku}" }-- it 'returns products with specified ids' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(products.first.id.to_s)- end- end-- context 'with specified price range' do- before { get "/api/v2/storefront/products?filter[price]=#{product_with_price.price.to_f},#{product_with_price.price.to_f + 0.04}" }-- it 'returns products with specified price' do- expect(json_response['data'].first).to have_id(product_with_price.id.to_s)- expect(json_response['data'].first).to have_attribute(:price).with_value(product_with_price.price.to_f.to_s)- end- end-- context 'with specified taxon_ids' do- before { get "/api/v2/storefront/products?filter[taxons]=#{product_with_taxon.taxons.first.id}" }-- it 'returns products with specified taxons' do- expect(json_response['data'].first).to have_id(product_with_taxon.id.to_s)- end- end-- context 'with specified name' do- before { get "/api/v2/storefront/products?filter[name]=#{product_with_name.name}" }-- it 'returns products with specified name' do- expect(json_response['data'].first).to have_id(product_with_name.id.to_s)- expect(json_response['data'].first).to have_attribute(:name).with_value(product_with_name.name)- end- end-- context 'with specified options' do- context 'with no locale set' do- before do- get "/api/v2/storefront/products?filter[options][#{option_type.name}]=#{option_value.name}&include=option_types,variants.option_values"- end-- it 'returns products with specified options' do- expect(json_response['data'].first).to have_id(product_with_option.id.to_s)- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(option_type.name)))- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(option_value.name)))- end- end-- context 'with locale set to polish' do- # generate translations for default store- let!(:store) do- default_store = create(:store, default_locale: 'en', supported_locales: 'en,pl')-- Mobility.with_locale(:pl) do- default_store.name = 'Spree Sklep Testowy'- default_store.mail_from_address = '[email protected]'- default_store.customer_support_email = '[email protected]'- default_store.new_order_notifications_email = '[email protected]'- end-- default_store.save- default_store- end-- # generate translated resources- let!(:option_type_localized) do- option_type = create(:option_type)- presentation = option_type.presentation-- Mobility.with_locale(:pl) { option_type.update!(presentation: "#{presentation} PL") }-- option_type- end-- let!(:option_value_localized) do- option_value = create(:option_value, option_type: option_type_localized)- presentation = option_value.presentation-- Mobility.with_locale(:pl) { option_value.update!(presentation: "#{presentation} PL") }-- option_value- end-- let!(:product_localized) do- product = create(:product, option_types: [option_type_localized], stores: [store])- Mobility.with_locale(:pl) { product.update!(name: 'Produkt Superowy') }-- product- end-- let!(:variant_localized) { create(:variant, product: product_localized, option_values: [option_value_localized]) }-- before do- get "/api/v2/storefront/products?filter[options][#{option_type_localized.name}]=#{option_value_localized.name}&include=option_types,variants.option_values&locale=pl"- end-- it 'returns products with specified options in polish' do- expect(json_response['data'].first).to have_id(product_localized.id.to_s)- expect(json_response['data'].first).to have_attribute(:name).with_value('Produkt Superowy')- expect(json_response['data'].first).to have_attribute(:localized_slugs).with_value(- 'en' => product_localized.slug_en,- 'pl' => product_localized.slug_pl- )-- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(option_type_localized.name)))- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:presentation).with_value(option_type_localized.presentation_pl)))-- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(option_value_localized.name)))- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:presentation).with_value(option_value_localized.presentation_pl)))- end- end- end-- context 'with specified tags' do- let!(:product_1) { create(:product, tag_list: ['tag_1', 'tag_2']) }- let!(:product_2) { create(:product, tag_list: ['tag_2']) }- let!(:product_3) { create(:product, tag_list: ['tag_3']) }-- before do- get "/api/v2/storefront/products?filter[tags]=#{tags_list}"- end-- context 'when filtering by tag_1/tag_2 tags' do- let(:tags_list) { 'tag_1,tag_2' }-- it 'returns products with specified tags' do- expect(json_response['data']).to include(have_id(product_1.id.to_s))- expect(json_response['data']).to include(have_id(product_2.id.to_s))- expect(json_response['data']).not_to include(have_id(product_3.id.to_s))- end- end-- context 'when filtering by tag_2/tag_3 tags' do- let(:tags_list) { 'tag_2,tag_3' }-- it 'returns products with specified tags' do- expect(json_response['data']).to include(have_id(product_1.id.to_s))- expect(json_response['data']).to include(have_id(product_2.id.to_s))- expect(json_response['data']).to include(have_id(product_3.id.to_s))- end- end-- context 'when filtering by tag_3 tags' do- let(:tags_list) { 'tag_3' }-- it 'returns products with specified tags' do- expect(json_response['data']).not_to include(have_id(product_1.id.to_s))- expect(json_response['data']).not_to include(have_id(product_2.id.to_s))- expect(json_response['data']).to include(have_id(product_3.id.to_s))- end- end-- context 'when filtering by non-existent tags' do- let(:tags_list) { 'tag_4,tag5' }-- it 'returns products with specified tags' do- expect(json_response['data']).not_to include(have_id(product_1.id.to_s))- expect(json_response['data']).not_to include(have_id(product_2.id.to_s))- expect(json_response['data']).not_to include(have_id(product_3.id.to_s))- end- end- end-- context 'with multiple specified options' do- let!(:color) { create(:option_type, :color) }- let!(:green_color) { create(:option_value, option_type: color, name: 'green') }- let!(:white_color) { create(:option_value, option_type: color, name: 'white') }-- let!(:size) { Spree::OptionType.find_by(name: 'size') || create(:option_type, :size) }- let!(:s_size) { create(:option_value, option_type: size, name: 's') }- let!(:m_size) { create(:option_value, option_type: size, name: 'm') }-- let(:product_1) { create(:product, option_types: [color, size], stores: [store]) }- let!(:variant_1) { create(:variant, product: product_1, option_values: [white_color, m_size]) }-- let(:product_2) { create(:product, option_types: [color, size], stores: [store]) }- let!(:variant_2_1) { create(:variant, product: product_2, option_values: [green_color, s_size]) }- let!(:variant_2_2) { create(:variant, product: product_2, option_values: [white_color, s_size]) }-- context 'for filters with products' do- let(:options_filter) do- [- "filter[options][#{color.name}]=#{white_color.name}",- "filter[options][#{size.name}]=#{m_size.name}"- ].join('&')- end-- before { get "/api/v2/storefront/products?#{options_filter}&include=option_types,variants.option_values" }-- it 'returns products with specified options' do- expect(json_response['data']).to include(have_id(product_1.id.to_s))- expect(json_response['data']).not_to include(have_id(product_2.id.to_s))-- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(color.name)))- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(white_color.name)))-- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(size.name)))- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(m_size.name)))- end- end-- context 'for excluding filters' do- let(:options_filter) do- [- "filter[options][#{color.name}]=#{green_color.name}",- "filter[options][#{size.name}]=#{m_size.name}"- ].join('&')- end-- before { get "/api/v2/storefront/products?#{options_filter}&include=option_types,variants.option_values" }-- it 'returns no products' do- expect(json_response['data']).to be_empty- end- end- end-- # TODO: we should use property names and values instead of filter params- context 'with specified properties' do- xcontext 'using proper filter params' do- before { get "/api/v2/storefront/products?filter[properties][#{property.filter_param}]=#{product_property.filter_param}&include=product_properties" }-- it 'returns products with specified properties' do- expect(json_response['data'].first).to have_id(product_with_property.id.to_s)- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:name).with_value(property.name)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:value).with_value(product_property.value)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:filter_param).with_value(product_property.filter_param)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:show_property).with_value(product_property.show_property)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:position).with_value(product_property.position)))- end- end-- xcontext 'using property names and values' do- before { get "/api/v2/storefront/products?filter[properties][#{property.name}]=#{product_property.value}&include=product_properties" }-- it 'returns products with specified properties' do- expect(json_response['data'].first).to have_id(product_with_property.id.to_s)- end- end-- context 'with locale set to polish' do- let!(:store) do- default_store = create(:store)- default_store.default_locale = 'en'- default_store.supported_locales = 'en,pl'- default_store.save- default_store- end-- let!(:product_localized) do- product = create(:product, stores: [store])- Mobility.with_locale(:pl) { product.update!(name: 'Produkt Superowy') }-- product- end-- let!(:property_localized) do- property = create(:property)- presentation = option_type.presentation-- Mobility.with_locale(:pl) { property.update!(presentation: "#{presentation} PL") }-- property- end-- let!(:product_property_localized) do- product_property = create(:product_property, property: property_localized, product: product_localized)- value = product_property.value-- Mobility.with_locale(:pl) { product_property.update!(value: "#{value} PL") }-- product_property- end-- before do- get "/api/v2/storefront/products?filter[properties][#{property_localized.name}]=#{product_property_localized.value_pl}&include=product_properties&locale=pl"- end-- it 'returns products with specified properties in polish' do- expect(json_response['data'].first).to have_id(product_localized.id.to_s)- expect(json_response['data'].first).to have_attribute(:name).with_value('Produkt Superowy')- expect(json_response['data'].first).to have_attribute(:localized_slugs).with_value(- 'en' => product_localized.slug_en,- 'pl' => product_localized.slug_pl- )-- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:name).with_value(property_localized.name)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:description).with_value(property_localized.presentation_pl)))-- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:value).with_value(product_property_localized.value_pl)))- expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:filter_param).with_value(product_property_localized.filter_param)))- end- end- end-- context 'with specified multiple filters' do- before { get "/api/v2/storefront/products?filter[name]=#{product_with_name.name}&filter[price]=#{product_with_name.price.to_f - 0.02},#{product_with_name.price.to_f + 0.02}" }-- it 'returns products with specified name and price' do- expect(json_response['data'].count).to eq 1- expect(json_response['data'].first).to have_id(product_with_name.id.to_s)- end- end-- context 'with included deleted' do- before { get '/api/v2/storefront/products?filter[show_deleted]=true' }-- it 'returns products with deleted products' do- expect(json_response['data'].count).to eq 10- expect(json_response['data'].pluck(:id)).to include(deleted_product.id.to_s)- end- end-- context 'with included discontinued' do- before { get '/api/v2/storefront/products?filter[show_discontinued]=true' }-- it 'returns products with discontinued products' do- expect(json_response['data'].count).to eq 11- expect(json_response['data'].pluck(:id)).to include(discontinued_product.id.to_s)- end- end-- context 'with included discontinued and deleted' do- before do- get '/api/v2/storefront/products?filter[show_deleted]=true&filter[show_discontinued]=true'- end-- it 'returns available, deleted and discontinued products' do- expect(json_response['data'].count).to eq 12- expect(json_response['data'].pluck(:id)).to include(deleted_product.id.to_s, discontinued_product.id.to_s)- end- end-- context 'with show only stock' do- before do- get '/api/v2/storefront/products?filter[in_stock]=true'- end-- it 'returns products in stock' do- expect(json_response['data'].count).to eq 2- expect(json_response['data'].pluck(:id)).to include(in_stock_product.id.to_s, not_backorderable_product.id.to_s)- end- end-- context 'with show only backorderable' do- before do- get '/api/v2/storefront/products?filter[backorderable]=true'- end-- it 'returns products in stock' do- expect(json_response['data'].count).to eq 8- expect(json_response['data'].pluck(:id)).not_to include(not_backorderable_product.id.to_s)- end- end-- context 'with show only purchasable' do- before do- get '/api/v2/storefront/products?filter[purchasable]=true'- end-- it 'returns only purchasable products' do- expect(json_response['data'].count).to eq 9- expect(json_response['data'].pluck(:id)).to include(in_stock_product.id.to_s, not_backorderable_product.id.to_s)- end- end-- context 'sort products' do- context 'sorting by price' do- context 'ascending order' do- before { get '/api/v2/storefront/products?sort=price' }-- it 'returns products sorted by price' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.joins(variants_including_master: :prices).select("#{store.products.table_name}.*, #{Spree::Price.table_name}.amount").distinct.order("#{Spree::Price.table_name}.amount").map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/storefront/products?sort=-price' }-- it 'returns products sorted by price with descending order' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.joins(variants_including_master: :prices).select("#{store.products.table_name}.*, #{Spree::Price.table_name}.amount").distinct.order("#{Spree::Price.table_name}.amount DESC").map(&:id).map(&:to_s)- end- end- end-- context 'sorting by name' do- let(:store) { create(:store, supported_locales: 'en,pl') }-- after { I18n.locale = :en }-- context 'A-Z' do- let(:request_path) { '/api/v2/storefront/products?sort=name' }-- before { get request_path }-- it 'returns products sorted by name' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available.order(:name).map(&:id).map(&:to_s)- end-- context 'when using another locale' do- let(:request_path) { '/api/v2/storefront/products?sort=name&locale=pl' }-- it 'returns products sorted by name' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available.- select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_pl.name").- order(:name).map(&:id).map(&:to_s)- end- end- end-- context 'Z-A' do- let(:request_path) { '/api/v2/storefront/products?sort=-name' }-- before { get request_path }-- it 'returns products sorted by name with descending order' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(name: :desc).map(&:id).map(&:to_s)- end-- context 'when using another locale' do- let(:request_path) { '/api/v2/storefront/products?sort=-name&locale=pl' }-- it 'returns products sorted by name' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available.- select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_pl.name").- order(name: :desc).map(&:id).map(&:to_s)- end- end- end- end-- context 'sorting by updated_at' do- context 'ascending order' do- before { get '/api/v2/storefront/products?sort=updated_at' }-- it 'returns products sorted by updated_at' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(:updated_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/storefront/products?sort=-updated_at' }-- it 'returns products sorted by updated_at with descending order' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(updated_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by created_at' do- context 'ascending order' do- before { get '/api/v2/storefront/products?sort=created_at' }-- it 'returns products sorted by created_at' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(:created_at).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/storefront/products?sort=-created_at' }-- it 'returns products sorted by created_at with descending order' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(created_at: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by available_on' do- before { store.products.each_with_index { |p, i| p.update(status: 'active', available_on: Time.current - i.days) } }-- context 'ascending order' do- before { get '/api/v2/storefront/products?sort=available_on' }-- it 'returns products sorted by available_on' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(:available_on).map(&:id).map(&:to_s)- end- end-- context 'descending order' do- before { get '/api/v2/storefront/products?sort=-available_on' }-- it 'returns products sorted by available_on with descending order' do- expect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available.order(available_on: :desc).map(&:id).map(&:to_s)- end- end- end-- context 'sorting by sku' do- shared_examples 'returning products in ascending sku order' do- before { get "/api/v2/storefront/products?sort=sku#{params}" }-- it 'returns products sorted by master variant sku' do- expect(skus_array).to eq(skus_array.sort)- expect(json_response['data'].count).to eq(store.products.available.count)- expect(json_response['data'].map { |p| p['attributes']['sku'] }).to eq(available_products_with_master.map(&:sku).sort)- end- end-- shared_examples 'returning products in descending sku order' do- before { get "/api/v2/storefront/products?sort=-sku#{params}" }-- it 'returns products sorted by master variant sku with descending order' do- expect(skus_array).to eq(skus_array.sort.reverse)- expect(json_response['data'].count).to eq(store.products.available.count)- expect(json_response['data'].map { |p| p['attributes']['sku'] }).to eq(available_products_with_master.map(&:sku).sort.reverse)- end- end-- let(:skus_array) { json_response['data'].map { |p| p['attributes']['sku'] } }- let(:available_products_with_master) { products + [product_with_option, in_stock_product, not_backorderable_product, product_with_property] }- let(:params) { '' }-- it_behaves_like 'returning products in ascending sku order'- it_behaves_like 'returning products in descending sku order'-- context 'with variants' do- let(:params) { '&include=variants' }-- it_behaves_like 'returning products in ascending sku order'- it_behaves_like 'returning products in descending sku order'- end-- context 'with updated_at sort' do- let(:params) { ',updated_at' }- let!(:time) { Time.current }-- context 'when updated_at date is same for each product' do- before { store.products.update_all(updated_at: time) }-- it_behaves_like 'returning products in ascending sku order'- it_behaves_like 'returning products in descending sku order'- end-- context 'when updated_at date is different for each product' do- shared_examples 'returns products in ascending updated_at order' do- it 'returns products in ascending updated_at order' do- expect(json_response['data'].count).to eq(store.products.available.count)- expect(json_response['data'].map { |p| p['attributes']['sku'] }).to eq(available_products_with_master.sort { |a, b| a.updated_at <=> b.updated_at }.map(&:sku))- end- end-- before { available_products_with_master.each_with_index { |p, i| p.update(updated_at: time - i.day) } }-- context 'when sku sort order direction is ascending' do- before { get "/api/v2/storefront/products?sort=sku#{params}" }--- it_behaves_like 'returns products in ascending updated_at order'- end-- context 'when sku sort order direction is descending' do- before { get "/api/v2/storefront/products?sort=-sku#{params}" }--- it_behaves_like 'returns products in ascending updated_at order'- end- end- end- end-- context 'sorting by both price and sku' do- let(:skus_array) { json_response['data'].map { |p| p['attributes']['sku'] } }-- before { get '/api/v2/storefront/products?sort=-sku,price' }-- it do- expect(skus_array).to eq(skus_array.sort.reverse)- expect(json_response['data'].count).to eq(store.products.available.count)- end- end- end-- context 'paginate products' do- context 'with specified pagination params' do- context 'when per_page is between 1 and default value' do- before { get '/api/v2/storefront/products?page=1&per_page=2' }-- it 'returns the default number of products' do- expect(json_response['data'].count).to eq 2- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq 2- expect(json_response['meta']['total_count']).to eq store.products.available.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/products?page=1&per_page=2')- expect(json_response['links']['next']).to include('/api/v2/storefront/products?page=2&per_page=2')- expect(json_response['links']['prev']).to include('/api/v2/storefront/products?page=1&per_page=2')- end- end-- context 'when per_page is above the default value' do- before { get '/api/v2/storefront/products?page=1&per_page=10' }-- it 'returns the default number of products' do- expect(json_response['data'].count).to eq 9- end- end-- context 'when per_page is less than 0' do- before { get '/api/v2/storefront/products?page=1&per_page=-1' }-- it 'returns the default number of products' do- expect(json_response['data'].count).to eq 9- end- end-- context 'when per_page is equal 0' do- before { get '/api/v2/storefront/products?page=1&per_page=0' }-- it 'returns the default number of products' do- expect(json_response['data'].count).to eq 9- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/storefront/products' }-- it 'returns specified amount products' do- expect(json_response['data'].count).to eq store.products.available.count- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).to eq store.products.available.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/products')- expect(json_response['links']['next']).to include('/api/v2/storefront/products?page=1')- expect(json_response['links']['prev']).to include('/api/v2/storefront/products?page=1')- end- end- end-- context 'return filter metadata' do- let!(:option_type2) { create(:option_type) }- let!(:option_type2_value1) { create(:option_value, option_type: option_type2) }- let!(:option_type2_value2) { create(:option_value, option_type: option_type2) }-- let(:product_with_option_type2) { create(:product, option_types: [option_type2], stores: [store]) }- let!(:product_with_option_type2_variant1) { create(:variant, product: product_with_option_type2, option_values: [option_type2_value1]) }- let!(:product_with_option_type2_variant2) { create(:variant, product: product_with_option_type2, option_values: [option_type2_value2]) }-- let!(:property2) { create(:property, :filterable) }- let!(:property3) { create(:property, :filterable) }- let!(:product_property2) { create(:product_property, property: property2, product: product_with_property, value: 'A property') }- let!(:product2_property2) { create(:product_property, property: property2, product: product_with_option_type2, value: 'Test') }- let!(:product2_property3) { create(:product_property, property: property3, product: product_with_option_type2, value: 'Test') }-- let!(:unused_option_type) { create(:option_type) }- let!(:unused_option_value) { create(:option_value) }-- let(:option_type1_response) do- {- id: option_type.id,- name: option_type.name,- presentation: option_type.presentation,- option_values: [- {- id: option_value.id,- name: option_value.name,- presentation: option_value.presentation,- position: option_value.position- }- ]- }- end-- let(:option_type2_response) do- {- id: option_type2.id,- name: option_type2.name,- presentation: option_type2.presentation,- option_values: [- {- id: option_type2_value1.id,- name: option_type2_value1.name,- presentation: option_type2_value1.presentation,- position: option_type2_value1.position- },- {- id: option_type2_value2.id,- name: option_type2_value2.name,- presentation: option_type2_value2.presentation,- position: option_type2_value2.position- }- ]- }- end-- let(:property2_response) do- {- id: property2.id,- name: property2.name,- presentation: property2.presentation,- values: [- {- value: product_property2.value,- filter_param: product_property2.filter_param,- },- {- value: product2_property2.value,- filter_param: product2_property2.filter_param,- }- ]- }- end-- let(:property3_response) do- {- id: property3.id,- name: property3.name,- presentation: property3.presentation,- values: [- {- value: product2_property3.value,- filter_param: product2_property3.filter_param- }- ]- }- end-- context 'when no filters are applied' do- before { get '/api/v2/storefront/products' }-- it 'returns list of available filters for all products' do- expect(json_response['meta']['filters']['option_types'].count).to eq 2- expect(json_response['meta']['filters']['option_types']).to contain_exactly(option_type1_response, option_type2_response)- expect(json_response['meta']['filters']['product_properties'].count).to eq 2- expect(json_response['meta']['filters']['product_properties']).to contain_exactly(property2_response, property3_response)- end- end-- context 'when filter by option type is applied' do- before { get "/api/v2/storefront/products?filter[options][#{option_type.name}]=#{option_value.name}" }-- it 'returns list of all available filters for products' do- expect(json_response['meta']['filters']['option_types'].count).to eq 2- expect(json_response['meta']['filters']['option_types']).to contain_exactly(option_type1_response, option_type2_response)- expect(json_response['meta']['filters']['product_properties'].count).to eq 2- expect(json_response['meta']['filters']['product_properties']).to contain_exactly(property2_response, property3_response)- end- end-- context 'when filter by product property is applied' do- before do- get "/api/v2/storefront/products?filter[properties][#{property.filter_param}]=#{product_property.filter_param}"- end-- it 'returns list of all available filters for products' do- expect(json_response['meta']['filters']['option_types'].count).to eq 2- expect(json_response['meta']['filters']['option_types']).to contain_exactly(option_type1_response, option_type2_response)- expect(json_response['meta']['filters']['product_properties'].count).to eq 2- expect(json_response['meta']['filters']['product_properties']).to contain_exactly(property2_response, property3_response)- end- end-- context 'when filter by taxon is applied' do- let(:product_with_taxon_and_options) { create(:product, taxons: [taxon], option_types: [option_type2], stores: [store]) }- let!(:product_with_taxon_and_options_property) { create(:product_property, property: property3, product: product_with_taxon_and_options, value: 'Test') }- let!(:product_with_taxon_and_options_variant1) { create(:variant, product: product_with_taxon_and_options, option_values: [option_type2_value1]) }- let!(:product_with_taxon_and_options_variant2) { create(:variant, product: product_with_taxon_and_options, option_values: [option_type2_value2]) }-- before { get "/api/v2/storefront/products?filter[taxons]=#{taxon.id}" }-- it 'returns list of available filters for given taxon' do- expect(json_response['meta']['filters']['option_types'].count).to eq 1- expect(json_response['meta']['filters']['option_types']).to contain_exactly(option_type2_response)- expect(json_response['meta']['filters']['product_properties'].count).to eq 1- expect(json_response['meta']['filters']['product_properties']).to contain_exactly(property3_response)- end- end-- context 'when filter by multiple taxons is applied' do- let(:product_with_taxon_and_options) { create(:product, taxons: [taxon], option_types: [option_type2], stores: [store]) }- let!(:product_with_taxon_and_options_property) { create(:product_property, property: property3, product: product_with_taxon_and_options, value: 'Test') }- let!(:product_with_taxon_and_options_variant1) { create(:variant, product: product_with_taxon_and_options, option_values: [option_type2_value1]) }- let!(:product_with_taxon_and_options_variant2) { create(:variant, product: product_with_taxon_and_options, option_values: [option_type2_value2]) }-- let(:taxonomy2) { create(:taxonomy, store: store) }- let(:taxon2) { taxonomy2.root }- let(:product_with_taxon2_and_options) { create(:product, taxons: [taxon2], option_types: [option_type2], stores: [store]) }- let!(:product_with_taxon2_and_options_property) { create(:product_property, property: property3, product: product_with_taxon2_and_options, value: 'Test') }- let!(:product_with_taxon2_and_options_variant1) { create(:variant, product: product_with_taxon2_and_options, option_values: [option_value]) }-- before { get "/api/v2/storefront/products?filter[taxons]=#{taxon.id},#{taxon2.id}" }-- it 'returns list of available filters for given taxons' do- expect(json_response['meta']['filters']['option_types'].count).to eq 2- expect(json_response['meta']['filters']['option_types']).to contain_exactly(option_type1_response, option_type2_response)- expect(json_response['meta']['filters']['product_properties'].count).to eq 1- expect(json_response['meta']['filters']['product_properties']).to contain_exactly(property3_response)- end- end- end-- context 'fetch products by curency param' do- let(:store) { create(:store, supported_currencies: 'USD,EUR,GBP') }-- context 'with default currency' do- before { get '/api/v2/storefront/products?currency=USD' }-- it 'returns products' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'][0]['attributes']['currency']).to eq 'USD'- expect(json_response['data'].count).to eq store.products.available.count- end- end-- context 'with supported currency' do- let(:product) { products.first }- let(:currency) { 'EUR' }-- before do- product.master.prices.create(currency: currency, amount: 99.90, compare_at_amount: 129.90)- get "/api/v2/storefront/products?currency=#{currency}&include=default_variant"- end-- it 'returns products with prices in that currency' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'].count).to eq(1)- expect(json_response['data'][0]['id']).to eq(product.id.to_s)- expect(json_response['data'][0]['attributes']['currency']).to eq currency- expect(json_response['data'][0]['attributes']['price']).to eq('99.9')- expect(json_response['data'][0]['attributes']['display_price']).to eq('€99.90')- expect(json_response['data'][0]['attributes']['compare_at_price']).to eq('129.9')- expect(json_response['data'][0]['attributes']['display_compare_at_price']).to eq('€129.90')- expect(json_response['included'][0]['id']).to eq(product.default_variant_id.to_s)- expect(json_response['included'][0]['type']).to eq('variant')- expect(json_response['included'][0]['attributes']['price']).to eq('99.9')- expect(json_response['included'][0]['attributes']['display_price']).to eq('€99.90')- expect(json_response['included'][0]['attributes']['compare_at_price']).to eq('129.9')- expect(json_response['included'][0]['attributes']['display_compare_at_price']).to eq('€129.90')- end- end-- context 'without supported currency' do- before { get '/api/v2/storefront/products?currency=PLN' }-- it 'returns results with default currency' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'][0]['attributes']['currency']).to eq 'USD'- expect(json_response['data'][0]['attributes']['display_price']).to match('$')- end- end- end-- # Regression test for SD-1439 ambiguous column name: count_on_hand- context 'with multiple params' do- before do- get '/api/v2/storefront/products?filter[backorderable]=true'\- '&filter[ids]=130'\- '&filter[in_stock]=true'\- '&filter[name]=rails'\- '&filter[options][tshirt-color]=Red'\- '&filter[price]=10,100'\- '&filter[properties][brand-name]=alpha'\- '&filter[purchasable]=true'\- '&filter[show_deleted]=true'\- '&filter[show_discontinued]=true'\- '&filter[skus]=SKU-123,SKU-345'\- '&filter[taxons]=1,2,3,4,5,6,7,8,9,10,11'\- '&image_transformation[quality]=anim consequat fugiat sed'\- '&image_transformation[size]=100x50'\- '&include=default_variant,variants,option_types,product_properties,taxons,images,primary_variant'\- '&page=1'\- '&per_page=25'\- '&sort=-updated_at,price,-name,created_at,-available_on,sku'- end--- end- end-- describe 'products#show' do- context 'with supported currency param' do- before { get "/api/v2/storefront/products/#{product.slug}?currency=USD" }---- it 'return product with supported currency' do- expect(json_response['data']).not_to be_empty- expect(json_response['data']['id']).to eq(product.id.to_s)- expect(json_response['data']['attributes']['currency']).to eq('USD')- end- end-- context 'with supported currency but without prices in that currency' do- let(:store) { create(:store, supported_currencies: 'USD,EUR,GBP') }-- before do- get "/api/v2/storefront/products/#{product.slug}?currency=EUR&include=default_variant"- end-- it 'returns empty prices' do- expect(json_response['data']).not_to be_empty- expect(json_response['data']['id']).to eq(product.id.to_s)- expect(json_response['data']['attributes']['currency']).to eq('EUR')- expect(json_response['data']['attributes']['price']).to be_nil- expect(json_response['data']['attributes']['display_price']).to be_nil- expect(json_response['data']['attributes']['compare_at_price']).to be_nil- expect(json_response['data']['attributes']['display_compare_at_price']).to be_nil- expect(json_response['included'][0]['id']).to eq(product.default_variant_id.to_s)- expect(json_response['included'][0]['type']).to eq('variant')- expect(json_response['included'][0]['attributes']['currency']).to eq('EUR')- expect(json_response['included'][0]['attributes']['price']).to be_nil- expect(json_response['included'][0]['attributes']['display_price']).to be_nil- expect(json_response['included'][0]['attributes']['compare_at_price']).to be_nil- expect(json_response['included'][0]['attributes']['display_compare_at_price']).to be_nil- end- end-- context 'without supported currency param' do- before { get "/api/v2/storefront/products/#{product.slug}?currency=PLN" }-- it 'fallbacks to default currency' do- expect(json_response['data']).not_to be_empty- expect(json_response['data']['id']).to eq(product.id.to_s)- expect(json_response['data']['attributes']['currency']).to eq('USD')- end- end-- context 'with non-existing product' do- before { get '/api/v2/storefront/products/example' }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with existing product' do- before { get "/api/v2/storefront/products/#{product.slug}" }-- it 'returns a valid JSON response' do- expect(json_response['data']).to have_id(product.id.to_s)-- expect(json_response['data']).to have_type('product')-- expect(json_response['data']).to have_attribute(:name).with_value(product.name)- expect(json_response['data']).to have_attribute(:description).with_value(product.description)- expect(json_response['data']).to have_attribute(:price).with_value(product.price.to_s)- expect(json_response['data']).to have_attribute(:currency).with_value(product.currency)- expect(json_response['data']).to have_attribute(:display_price).with_value(product.display_price.to_s)- expect(json_response['data']).to have_attribute(:available_on).with_value(product.available_on.as_json)- expect(json_response['data']).to have_attribute(:slug).with_value(product.slug)- expect(json_response['data']).to have_attribute(:meta_description).with_value(product.meta_description)- expect(json_response['data']).to have_attribute(:meta_keywords).with_value(product.meta_keywords)- expect(json_response['data']).to have_attribute(:updated_at).with_value(product.updated_at.as_json)- expect(json_response['data']).to have_attribute(:purchasable).with_value(product.purchasable?)- expect(json_response['data']).to have_attribute(:in_stock).with_value(product.in_stock?)- expect(json_response['data']).to have_attribute(:backorderable).with_value(product.backorderable?)- expect(json_response['data']).to have_attribute(:sku).with_value(product.sku)- expect(json_response['data']).to have_attribute(:public_metadata).with_value(product.public_metadata)-- expect(json_response['data']).to have_relationships(- :variants, :option_types, :product_properties, :default_variant- )- end- end-- context 'with product from another store' do- let(:store_2) { create(:store) }- let(:product_from_another_store) { create(:product, stores: [store_2]) }-- before { get "/api/v2/storefront/products/#{product_from_another_store.slug}" }-- it_behaves_like 'returns 404 HTTP status'- end-- context 'with localized_slugs' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:product_with_slug) { create(:product, stores: [store2], slug: 'test-slug-en') }- let!(:translation1) { product_with_slug.translations.create(slug: 'test-slug-pl', locale: 'pl') }- let!(:translation2) { product_with_slug.translations.create(slug: 'test-slug-es', locale: 'es') }-- let(:expected_result) do- {- en: 'test-slug-en',- pl: 'test-slug-pl',- es: 'test-slug-es'- }- end-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::ProductsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/products/#{product_with_slug.id}"- end-- it 'returns translated slugs' do- expect(json_response['data']['attributes']['localized_slugs']).to match(expected_result)- end- end-- context 'with slug fallback to default locale' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let!(:product_with_slug) { create(:product, stores: [store2], slug: default_locale_slug) }- let(:default_locale_slug) { 'test-slug-en' }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::ProductsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/products/#{default_locale_slug}?locale=pl"- end-- it 'finds the product' do- expect(json_response['data']['id']).to eq(product_with_slug.id.to_s)- end- end-- context 'with slug in translated locale' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:product_with_slug) { create(:product, stores: [store2], slug: default_locale_slug) }- let!(:translation2) { product_with_slug.translations.create(slug: translated_slug, locale: 'es') }- let(:default_locale_slug) { 'test-slug-en' }- let(:translated_slug) { 'test-slug-es' }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::ProductsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/products/#{translated_slug}?locale=es"- end-- it 'finds the product' do- expect(json_response['data']['id']).to eq(product_with_slug.id.to_s)- end- end-- context 'with old slug' do- before do- old_slug = product.slug- product.update(slug: 'new-slug')- expect(product.reload.slug).to eq 'new-slug'- get "/api/v2/storefront/products/#{old_slug}"- end-- it 'still finds the product' do- expect(json_response['data']['id']).to eq(product.id.to_s)- end- end-- context 'with product image data' do- shared_examples 'returns product image data' do- it 'returns product image data' do- expect(json_response['data']['relationships']['images'].count).to eq(1)- expect(json_response['included'].count).to eq(1)- expect(json_response['included'].first['type']).to eq('image')- end- end-- let!(:image) { create(:image, viewable: product.master) }- let(:image_json_data) { json_response['included'].first['attributes'] }-- before { get "/api/v2/storefront/products/#{product.slug}?include=images#{image_transformation_params}" }-- context 'when no image transformation params are passed' do- let(:image_transformation_params) { '' }-- it_behaves_like 'returns product image data'-- it 'returns product image' do- expect(image_json_data['transformed_url']).to be_nil- end- end-- context 'when product image json returned' do- let(:image_transformation_params) { '&image_transformation[size]=100x50&image_transformation[quality]=50' }-- it_behaves_like 'returns product image data'-- it 'returns product image' do- expect(image_json_data['transformed_url']).not_to be_nil- end- end- end-- # Regression test for SD-1462 - shouldn't use master variant if there are any non master variants- context 'with variants' do- let(:variant) { create(:variant, product: product) }- let(:request) { get "/api/v2/storefront/products/#{product.slug}" }-- describe 'purchasable attribute value' do- before do- product.master.stock_items.update_all(backorderable: true)- variant.stock_items.update_all(backorderable: false)- request- end-- it 'uses variants purchasability only' do- expect(json_response['data']['attributes']['backorderable']).to eq(false)- end- end-- describe 'backorderable attribute value' do- before do- product.master.stock_items.update_all(backorderable: true)- variant.stock_items.update_all(backorderable: false)- request- end-- it 'uses variants backorderability only' do- expect(json_response['data']['attributes']['backorderable']).to eq(false)- end- end-- describe 'in_stock attribute value' do- before do- product.master.stock_items.update_all(count_on_hand: 10)- variant.stock_items.update_all(count_on_hand: 0)- request- end-- it 'uses variants #in_stock? only' do- expect(json_response['data']['attributes']['in_stock']).to eq(false)- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rbdeleted file mode 100644index 9ec8efa76c..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb+++ /dev/null@@ -1,44 +0,0 @@-require 'spec_helper'--describe 'API v2 JSON API Sparse Fields Spec', type: :request do- let(:store) { @default_store }- let!(:product) { create(:product_with_option_types, stores: [store]) }-- shared_examples 'no sparse fields requested' do- it 'returns all attributes' do- expect(json_response['data']['attributes']).to be_present- expect(json_response['data']['attributes'].count > 3).to eq true- end- end-- context 'without fields param' do- before { get "/api/v2/storefront/products/#{product.id}" }-- it_behaves_like 'no sparse fields requested'- end-- context 'with empty fields param' do- before { get "/api/v2/storefront/products/#{product.id}?fields=" }-- it_behaves_like 'no sparse fields requested'- end-- context 'with proper fields param' do- before { get "/api/v2/storefront/products/#{product.id}?fields[product]=name,price,currency" }-- it 'filters resource attributes' do- expect(json_response['data']['attributes']).to be_present- expect(json_response['data']['attributes'].keys).to contain_exactly('name', 'price', 'currency')- end- end-- context 'with included resources' do- before { get "/api/v2/storefront/products/#{product.id}?include=option_types&fields[option_type]=name,presentation" }-- it 'filters resource attributes' do- expect(json_response['included']).to be_present- expect(json_response['included']).to include(have_type('option_type'))- expect(json_response['included'].first['attributes'].keys).to contain_exactly('name', 'presentation')- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/stores_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/stores_spec.rbdeleted file mode 100644index 62ee0a7ff1..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/stores_spec.rb+++ /dev/null@@ -1,118 +0,0 @@-require 'spec_helper'--describe 'Storefront API v2 Stores spec', type: :request do- let(:store) { @default_store }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::StoresController).to receive(:current_store).and_return(store)- end-- describe 'stores#show' do- context 'with code param' do- before { get "/api/v2/storefront/stores/#{store.code}" }-- it 'return store with attributes' do- expect(json_response['data']).to have_attribute(:name).with_value(store.name)- expect(json_response['data']).to have_attribute(:url).with_value(store.url)- expect(json_response['data']).to have_attribute(:meta_description).with_value(store.meta_description)- expect(json_response['data']).to have_attribute(:meta_keywords).with_value(store.meta_keywords)- expect(json_response['data']).to have_attribute(:seo_title).with_value(store.seo_title)- expect(json_response['data']).to have_attribute(:default_currency).with_value(store.default_currency)- expect(json_response['data']).to have_attribute(:default).with_value(store.default)- expect(json_response['data']).to have_attribute(:supported_currencies).with_value(store.supported_currencies)- expect(json_response['data']).to have_attribute(:facebook).with_value(store.facebook)- expect(json_response['data']).to have_attribute(:twitter).with_value(store.twitter)- expect(json_response['data']).to have_attribute(:instagram).with_value(store.instagram)- expect(json_response['data']).to have_attribute(:default_locale).with_value(store.default_locale)- expect(json_response['data']).to have_attribute(:supported_locales).with_value(store.supported_locales)- expect(json_response['data']).to have_attribute(:description).with_value(store.description)- expect(json_response['data']).to have_attribute(:address).with_value(store.address)- expect(json_response['data']).to have_attribute(:contact_phone).with_value(store.contact_phone)-- expect(json_response['data']).to have_relationship(:default_country)- expect(json_response['data']).to have_relationship(:default_country).with_data('id' => store.default_country_id.to_s, 'type' => 'country')- end-- describe 'favicon_path attribute' do- context 'with favicon attached' do- let!(:store) { create(:store, :with_favicon) }-- it 'returns store favicon path' do- expect(json_response.dig(:data, :attributes, :favicon_path)).to end_with('thinking-cat.jpg')- end- end- end- end-- context 'with locale set to pl' do- let!(:store) do- localized_store = create(:store, default_country: create(:country))- localized_store.supported_locales = 'en,pl'- localized_store.save-- Mobility.with_locale(:pl) do- localized_store.update(- name: 'Test Store PL',- meta_description: 'Meta Desc PL',- meta_keywords: 'meta, keywords, pl',- seo_title: 'SEO Title PL'- )- end-- localized_store- end-- before do- get "/api/v2/storefront/stores/#{store.code}?locale=pl"- end-- after do- I18n.locale = :en- store.update!(supported_locales: 'en')- end-- it 'return store with translated attributes' do- expect(json_response['data']).to have_attribute(:name).with_value('Test Store PL')- expect(json_response['data']).to have_attribute(:meta_description).with_value('Meta Desc PL')- expect(json_response['data']).to have_attribute(:meta_keywords).with_value('meta, keywords, pl')- expect(json_response['data']).to have_attribute(:seo_title).with_value('SEO Title PL')- end- end-- context 'with invalid code param' do- before { get '/api/v2/storefront/stores/XX' }-- it 'return error' do- expect(json_response['error']).to eq('The resource you were looking for could not be found.')- end- end-- describe 'stores#current_store' do- before do- get "/api/v2/storefront/store"- end-- it 'returns store with attributes' do- expect(json_response['data']).to have_attribute(:name).with_value(store.name)- expect(json_response['data']).to have_attribute(:url).with_value(store.url)- expect(json_response['data']).to have_attribute(:meta_description).with_value(store.meta_description)- expect(json_response['data']).to have_attribute(:meta_keywords).with_value(store.meta_keywords)- expect(json_response['data']).to have_attribute(:seo_title).with_value(store.seo_title)- expect(json_response['data']).to have_attribute(:default_currency).with_value(store.default_currency)- expect(json_response['data']).to have_attribute(:default).with_value(store.default)- expect(json_response['data']).to have_attribute(:supported_currencies).with_value(store.supported_currencies)- expect(json_response['data']).to have_attribute(:facebook).with_value(store.facebook)- expect(json_response['data']).to have_attribute(:twitter).with_value(store.twitter)- expect(json_response['data']).to have_attribute(:instagram).with_value(store.instagram)- expect(json_response['data']).to have_attribute(:default_locale).with_value(store.default_locale)- expect(json_response['data']).to have_attribute(:supported_locales).with_value(store.supported_locales)- expect(json_response['data']).to have_attribute(:description).with_value(store.description)- expect(json_response['data']).to have_attribute(:address).with_value(store.address)- expect(json_response['data']).to have_attribute(:contact_phone).with_value(store.contact_phone)-- expect(json_response['data']).to have_relationship(:default_country)- expect(json_response['data']).to have_relationship(:default_country).with_data('id' => store.default_country_id.to_s, 'type' => 'country')- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/taxons_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/taxons_spec.rbdeleted file mode 100644index 2078246afb..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/taxons_spec.rb+++ /dev/null@@ -1,303 +0,0 @@-require 'spec_helper'--describe 'Taxons Spec', type: :request do- let!(:store) { @default_store }- let!(:taxonomy) { store.taxonomies.first }- let!(:taxons) { create_list(:taxon, 2, taxonomy: taxonomy, parent: taxonomy.root) }-- before do- store.update_column(:supported_locales, 'en,pl,es')- allow(Spree::Api::Config).to receive(:[]).and_call_original- allow(Spree::Api::Config).to receive(:[]).with(:api_v2_per_page_limit).and_return(2)- end-- after { I18n.locale = :en }-- shared_examples 'returns valid taxon resource JSON' do- it 'returns a valid taxon resource JSON response' do- expect(response.status).to eq(200)-- expect(json_response['data']).to have_type('taxon')- expect(json_response['data']).to have_relationships(:parent, :taxonomy, :children, :products, :image)- end- end-- describe 'taxons#index' do- context 'with no params' do- before { get '/api/v2/storefront/taxons' }-- it 'returns all taxons' do- expect(json_response['data'].size).to eq(store.taxons.count)- expect(json_response['data'][0]).to have_type('taxon')- expect(json_response['data'][0]).to have_relationships(:parent, :taxonomy, :children, :image)- expect(json_response['data'][0]).not_to have_relationships(:produts)- end- end-- context 'with locale set to pl' do- let!(:store) do- store = taxonomy.store- store.supported_locales = 'en,pl'- store.save- store- end-- let!(:taxonomy) do- taxonomy_localized = create(:taxonomy)- taxonomy_root_localized = taxonomy_localized.root-- name = taxonomy_localized.name-- Mobility.with_locale(:pl) do- taxonomy_localized.update!(name: "Localized Taxonomy PL")- taxonomy_root_localized.update!(name: "Localized Taxonomy PL", pretty_name: "Localized Taxonomy PL")- end-- taxonomy_localized- end-- let!(:taxons) do- taxons_localized = create_list(:taxon, 2, taxonomy: taxonomy, parent: taxonomy.root)- taxons_localized.each_with_index do |taxon, index|- name = taxon.name- Mobility.with_locale(:pl) { taxon.update!(name: "Localized Taxon #{index + 1} PL", pretty_name: "Localized Taxon #{index + 1} PL") }- end-- taxons_localized- end-- before { get '/api/v2/storefront/taxons?locale=pl' }-- # FIXME: this test fails on CI but works locally- xit 'returns all taxons' do- expect(json_response['data'].size).to eq(3)-- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value("Localized Taxonomy PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:pretty_name).with_value("Localized Taxonomy PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:permalink).with_value('localized-taxonomy-pl')))-- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value("Localized Taxon 1 PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:pretty_name).with_value("Localized Taxonomy PL -> Localized Taxon 1 PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:permalink).with_value('localized-taxonomy-pl/localized-taxon-1-pl')))-- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value("Localized Taxon 2 PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:pretty_name).with_value("Localized Taxonomy PL -> Localized Taxon 2 PL")))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:permalink).with_value('localized-taxonomy-pl/localized-taxon-2-pl')))- end- end-- context 'by roots' do- before { get '/api/v2/storefront/taxons?filter[roots]=true' }-- it 'returns taxons by roots' do- expect(json_response['data'].size).to eq(store.taxons.where(parent: nil).count)- expect(json_response['data'][0]).to have_type('taxon')- expect(json_response['data'][0]).to have_id(store.taxonomies.first.root.id.to_s)- expect(json_response['data'][0]).to have_relationship(:parent).with_data(nil)- expect(json_response['data'][0]).to have_relationships(:parent, :taxonomy, :children, :image)- end- end-- context 'by parent' do- before { get "/api/v2/storefront/taxons?filter[parent_id]=#{taxonomy.root.id}" }-- it 'returns children taxons by parent' do- expect(json_response['data'].size).to eq(2)- expect(json_response['data'][0]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')- expect(json_response['data'][1]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')- end- end-- context 'by parent permalink' do- let!(:taxonomy_3) { create(:taxonomy, store: taxonomy.store) }- let!(:taxon_3) { create(:taxon, taxonomy: taxonomy_3, parent: taxonomy_3.root) }-- let(:request_path) { "/api/v2/storefront/taxons?filter[parent_permalink]=#{taxonomy.root.permalink}" }-- before do- taxonomy_root_name = taxonomy.root.name- taxon_1_name = taxons[0].name- taxon_2_name = taxons[1].name-- Mobility.with_locale(:pl) do- taxonomy.root.update!(name: "#{taxonomy_root_name}_pl")- taxons[0].update!(name: "#{taxon_1_name}_pl")- taxons[1].update!(name: "#{taxon_2_name}_pl")- end-- get request_path- end-- it 'returns children taxons by parent' do- expect(json_response['data'].size).to eq(2)- expect(json_response['data'][0]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')- expect(json_response['data'][1]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')- end-- context 'with another locale' do- let(:request_path) { "/api/v2/storefront/taxons?filter[parent_permalink]=#{taxonomy.root.permalink_pl}&locale=pl" }-- it 'returns children taxons by parent' do- expect(json_response['data'].size).to eq(2)-- expect(json_response['data'][0]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')- expect(json_response['data'][1]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')-- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value(taxons[0].name_pl)))- expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value(taxons[1].name_pl)))- end- end- end-- context 'by taxonomy' do- before { get "/api/v2/storefront/taxons?filter[taxonomy_id]=#{taxonomy.id}" }-- it 'returns taxons by taxonomy' do- expect(json_response['data'].size).to eq(taxonomy.taxons.count)- expect(json_response['data'][0]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')- expect(json_response['data'][1]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')- expect(json_response['data'][2]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')- end- end-- context 'by ids' do- before { get "/api/v2/storefront/taxons?filter[ids]=#{taxons.map(&:id).join(',')}" }-- it 'returns taxons by ids' do- expect(json_response['data'].size).to eq(2)- expect(json_response['data'].pluck(:id).sort).to eq(taxons.map(&:id).map(&:to_s).sort)- end- end-- context 'by name' do- before { get "/api/v2/storefront/taxons?filter[name]=#{taxons.last.name}" }-- it 'returns taxons by name' do- expect(json_response['data'].size).to eq(1)- expect(json_response['data'].last['attributes']['name']).to eq(taxons.last.name)- end- end- end-- describe 'taxons#show' do- let(:taxon) { taxons.first }-- context 'by id' do- before do- get "/api/v2/storefront/taxons/#{taxon.id}"- end-- it_behaves_like 'returns valid taxon resource JSON'-- it 'returns taxon by id' do- expect(json_response['data']).to have_id(taxon.id.to_s)- expect(json_response['data']).to have_attribute(:name).with_value(taxon.name)- end- end-- context 'by permalink' do- before do- get "/api/v2/storefront/taxons/#{store.taxons.first.permalink}"- end-- it_behaves_like 'returns valid taxon resource JSON'-- it 'returns taxon by permalink' do- expect(json_response['data']).to have_id(store.taxons.first.id.to_s)- expect(json_response['data']).to have_attribute(:name).with_value(store.taxons.first.name)- end- end-- context 'with localized_slugs' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }- let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, permalink: 'test_slug_en') }- let!(:translations) { taxon_with_slug.translations.create([{ permalink: 'test_slug_pl', locale: 'pl' }, { permalink: 'test_slug_es', locale: 'es' } ])}-- let(:expected_slugs) do- {- en: 'categories/test-slug-en',- pl: 'categories/test-slug-pl',- es: 'categories/test-slug-es'- }- end-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::TaxonsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/taxons/#{taxon_with_slug.id}"- end-- it 'returns translated slugs' do- expect(json_response['data']['attributes']['localized_slugs']).to match(expected_slugs)- end- end-- context 'with fallback to default locale' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }- let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, name: 'test slug en', permalink: default_locale_slug) }- let(:default_locale_slug) { 'test-slug-en' }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::TaxonsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/taxons/categories/#{default_locale_slug}?locale=es"- end-- it 'finds the taxon' do- expect(json_response['data']['id']).to eq(taxon_with_slug.id.to_s)- end- end-- context 'with slug in translated locale' do- let(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }- let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, permalink: default_locale_slug) }- let!(:translations) { taxon_with_slug.translations.create([ { name: 'test slug en', permalink: translated_slug, locale: 'es' } ]) }- let(:default_locale_slug) { 'test_slug_en' }- let(:translated_slug) { 'test-slug-es' }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::TaxonsController).to receive(:current_store).and_return(store2)- get "/api/v2/storefront/taxons/categories/#{translated_slug}?locale=es"- end-- it 'finds the taxon' do- expect(json_response['data']['id']).to eq(taxon_with_slug.id.to_s)- end- end-- context 'with taxon image data' do- shared_examples 'returns taxon image data' do- it 'returns taxon image data' do- expect(json_response['included'].count).to eq(1)- expect(json_response['included'].first['type']).to eq('taxon_image')- end- end-- let!(:image) { create(:taxon_image, viewable: taxon) }- let(:image_json_data) { json_response['included'].first['attributes'] }-- before { get "/api/v2/storefront/taxons/#{taxon.id}?include=image#{taxon_image_transformation_params}" }-- context 'when no image transformation params are passed' do- let(:taxon_image_transformation_params) { '' }-- it_behaves_like 'returns taxon image data'-- it 'returns taxon image' do- expect(image_json_data['transformed_url']).to be_nil- end- end-- context 'when taxon image json returned' do- let(:taxon_image_transformation_params) { '&taxon_image_transformation[size]=100x50&taxon_image_transformation[quality]=50' }-- it_behaves_like 'returns taxon image data'-- it 'returns taxon image' do- expect(image_json_data['transformed_url']).not_to be_nil- end- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/variants_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/variants_spec.rbdeleted file mode 100644index 34ac1f5693..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/variants_spec.rb+++ /dev/null@@ -1,59 +0,0 @@-require 'spec_helper'--RSpec.describe 'API V2 Storefront Variants Spec', type: :request do- describe 'GET /api/v2/storefront/products/:id/variants' do- let!(:color) { create(:option_type, :color) }- let!(:green_color) { create(:option_value, option_type: color, name: 'green', presentation: 'Green') }- let!(:white_color) { create(:option_value, option_type: color, name: 'white', presentation: 'White') }-- let!(:size) { Spree::OptionType.find_by(name: 'size') || create(:option_type, :size) }- let!(:s_size) { create(:option_value, option_type: size, name: 's', presentation: 'S') }- let!(:m_size) { create(:option_value, option_type: size, name: 'm', presentation: 'M') }-- let!(:product) { create(:product_in_stock, option_types: [color, size]) }-- let!(:variant_1) { create(:variant, product: product, option_values: [green_color, s_size]) }- let!(:variant_2) { create(:variant, product: product, option_values: [green_color, m_size]) }- let!(:variant_3) { create(:variant, product: product, option_values: [white_color, s_size]) }- let!(:variant_4) { create(:variant, product: product, option_values: [white_color, m_size]) }-- let!(:other_product) { create(:product_in_stock, option_types: [color]) }-- let!(:other_variant_1) { create(:variant, product: other_product, option_values: [green_color]) }- let!(:other_variant_2) { create(:variant, product: other_product, option_values: [white_color]) }-- context 'with no params' do- before { get "/api/v2/storefront/products/#{product.id}/variants" }-- it 'returns all product variants including master' do- expect(json_response['data'].count).to eq(5)-- expect(json_response['data']).to include(have_type('variant').and(have_id(product.master.id.to_s)))- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_1.id.to_s)))- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_2.id.to_s)))- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_3.id.to_s)))- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_4.id.to_s)))- end- end-- context 'with specified option name and value' do- before { get "/api/v2/storefront/products/#{product.id}/variants?filter[options][color]=white" }-- it 'returns product variants with the specified option' do- expect(json_response['data'].count).to eq(2)-- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_3.id.to_s)))- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_4.id.to_s)))- end- end-- context 'with multiple options' do- before { get "/api/v2/storefront/products/#{product.id}/variants?filter[options][color]=white&filter[options][size]=m" }-- it 'returns product variants with the specified options' do- expect(json_response['data'].count).to eq(1)- expect(json_response['data']).to include(have_type('variant').and(have_id(variant_4.id.to_s)))- end- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/api/v2/storefront/wishlists_spec.rb b/legacy_api_v2/spec/requests/spree/api/v2/storefront/wishlists_spec.rbdeleted file mode 100644index ffe495af81..0000000000--- a/legacy_api_v2/spec/requests/spree/api/v2/storefront/wishlists_spec.rb+++ /dev/null@@ -1,598 +0,0 @@-require 'spec_helper'--RSpec.describe Spree::Api::V2::Storefront::WishlistsController, type: :request do- let(:store) { @default_store }- let(:other_store) { create(:store) }-- let(:wishlist) { create(:wishlist, store: store) }- let(:user) { wishlist.user }- let(:other_user) { create(:user) }-- before do- allow_any_instance_of(Spree::Api::V2::Storefront::WishlistsController).to receive(:current_store).and_return(store)- end-- include_context 'API v2 tokens'-- describe '#default' do- context 'no wishlist' do- it 'must create a new default wishlist' do- expect { get '/api/v2/storefront/wishlists/default', headers: headers_bearer }.to change { Spree::Wishlist.count }.from(0).to(2)- end- end-- context 'has default wishlist' do- before do- wishlist.update(is_default: true)- wishlist.save- wishlist.reload- end-- after do- wishlist.update(is_default: false)- wishlist.save- wishlist.reload- end-- it 'must return the existing default wishlist' do- expect { get '/api/v2/storefront/wishlists/default', headers: headers_bearer }.not_to change { Spree::Wishlist.count }- end- end-- context 'has default wishlist in another store' do- before do- wishlist.update(is_default: true, store: other_store)- wishlist.save- wishlist.reload- end-- after do- wishlist.update(is_default: false, store: store)- wishlist.save- wishlist.reload- end-- it 'creates a new default wishlist for the current store' do- expect { get '/api/v2/storefront/wishlists/default', headers: headers_bearer }.to change { Spree::Wishlist.count }.from(1).to(2)- end- end- end-- describe '#index' do- let!(:wishlists) { create_list(:wishlist, 30, user: user, store: store) }-- it 'must return a list of wishlists paged' do- get '/api/v2/storefront/wishlists', headers: headers_bearer-- expect(response).to have_http_status(:ok)- expect(json_response['data'].count).to eq (25)- end-- it 'can request different pages' do- get '/api/v2/storefront/wishlists?page=2', headers: headers_bearer-- expect(response).to have_http_status(:ok)- expect(json_response['data'].count).to eq (6)- end-- it 'can control paging size' do- get '/api/v2/storefront/wishlists?page=2&per_page=10', headers: headers_bearer-- expect(response).to have_http_status(:ok)- expect(json_response['data'].count).to eq (10)- end- end-- describe '#show' do- let!(:wishlist_private) { create(:wishlist, user: other_user, is_private: true, store: store) }- let!(:wishlist_public) { create(:wishlist, user: other_user, is_private: false, store: store) }-- let!(:wished_item) do- wishlist.wished_items.create({ variant: create(:variant) })- end-- it 'returns wishlist details' do- get "/api/v2/storefront/wishlists/#{wishlist.token}?include=wished_items", headers: headers_bearer-- expect(response).to have_http_status(:ok)- expect(json_response['data']['attributes']['token']).to eq (wishlist.token)- expect(json_response['data']['attributes']['name']).to eq (wishlist.name)- expect(json_response['data']['attributes']['is_private']).to eq (wishlist.is_private?)- expect(json_response['data']['attributes']['is_default']).to eq (wishlist.is_default?)- expect(json_response['data']['attributes']['variant_included']).to be false- expect(json_response['data']['relationships']['wished_items']['data'].first['id']).to eq(wished_item.id.to_s)- end-- it 'returns is_variant_included true when the variant is already added to the wishlist' do- get "/api/v2/storefront/wishlists/#{wishlist.token}?is_variant_included=#{wished_item.variant_id}", headers: headers_bearer-- expect(response).to have_http_status(:ok)- expect(json_response['data']['attributes']['variant_included']).to be true- end-- context 'when a request is sent by random user with no auth' do- it 'returns 403 when wishlist is set to is_private: true' do- get "/api/v2/storefront/wishlists/#{wishlist_private.token}"- expect(response).to have_http_status(:forbidden)- end-- it 'returns 200 when wishlist is set to is_private: false' do- get "/api/v2/storefront/wishlists/#{wishlist_public.token}"-- expect(response).to have_http_status(:ok)- expect(json_response['data']['attributes']['token']).to eq (wishlist_public.token)- expect(json_response['data']['attributes']['name']).to eq (wishlist_public.name)- end- end- end-- describe '#create' do- it 'can create a new wishlist' do- post '/api/v2/storefront/wishlists', headers: headers_bearer, params: {- wishlist: {- name: 'fathers day',- is_private: '1',- is_default: '1'- }- }- expect(user.wishlists.count).to eq(2)- expect(user.wishlists.last.name).to eq('fathers day')- end-- it 'must require a name to create a wishlist' do- post '/api/v2/storefront/wishlists', headers: headers_bearer, params: {- wishlist: {- bad_name: 'fathers day'- }- }- expect(response.status).to eq(422)- expect(json_response['error']).not_to be_empty- expect(json_response['error']).to eq "Name can't be blank"- end- end-- describe '#update' do- it 'must permit updating of the wishlist name' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}", headers: headers_bearer, params: {- wishlist: {- name: 'books'- }- }- expect(response.status).to eq(200)- user.wishlists.reload- expect(user.wishlists.first.name).to eq('books')- end- end-- describe '#destroy' do- it 'must permite destroying a wishlist' do- delete "/api/v2/storefront/wishlists/#{user.wishlists.first.token}", headers: headers_bearer- expect(response.status).to eq (204)- expect(user.wishlists.count).to eq (0)- end- end-- describe '#add_item' do- let!(:variant) { create(:variant) }-- it 'must allow creation of a wished_item' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- variant_id: variant.id.to_s,- quantity: 3- }- expect(response.status).to eq(200)- user.wishlists.reload-- expect(json_response['data']['type']).to eql ('wished_item')- expect(json_response['data']['attributes']['quantity']).to eql (3)- expect(json_response['data']['attributes']['price']).to eql ('19.99')- expect(json_response['data']['attributes']['total']).to eql ('59.97')- expect(json_response['data']['attributes']['display_price']).to eql ('$19.99')- expect(json_response['data']['attributes']['display_total']).to eql ('$59.97')- expect(json_response['data']['relationships']['variant']['data']['id']).to eql (variant.id.to_s)- expect(json_response['data']['relationships']['variant']['data']['type']).to eql ('variant')- end-- context 'when a variant is already in the wishlist' do- let!(:set_variant) { create(:variant) }- let!(:wi) { create(:wished_item, wishlist: user.wishlists.first, variant: set_variant, quantity: 1) }-- it 'return the existing wished_item - quantity attribute passed in' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- variant_id: set_variant.id.to_s,- quantity: 1- }-- expect(response.status).to eq(200)- user.wishlists.reload-- expect(json_response['data']['id']).to eql (wi.id.to_s)- expect(json_response['data']['attributes']['quantity']).to eql (1)- end-- it 'return the existing wished_item - quantity attribute ommited' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- variant_id: set_variant.id.to_s- }-- expect(response.status).to eq(200)- user.wishlists.reload-- expect(json_response['data']['id']).to eql (wi.id.to_s)- expect(json_response['data']['attributes']['quantity']).to eql (1)- end- end-- it 'must permit creation of a wished_item when omitting the quantity attribute' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- variant_id: variant.id.to_s- }- expect(response.status).to eq(200)- user.wishlists.reload- expect(json_response['data']['attributes']['quantity']).to eql (1)- end-- it 'must not permit the creation of a new wished_item without the variant_id attribute' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- bad_variant_id: variant.id.to_s- }- expect(response.status).to eq(422)- end-- it 'must not permit the creattion of a new wished_item with a quantity of 0' do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_item", headers: headers_bearer,- params: {- variant_id: variant.id.to_s,- quantity: 0- }- expect(response.status).to eq(422)- end- end-- describe '#set_item_quantity' do- let!(:wished_item) do- wishlist.wished_items.create({ variant: create(:variant) })- end-- it 'must allow setting the quantity when an integer value is passed in' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/set_item_quantity/#{wishlist.wished_items.first.id}",- headers: headers_bearer,- params: {- quantity: 17- }-- expect(response.status).to eq(200)- expect(json_response['data']['attributes']['quantity']).to eql (17)- end-- it 'must allow setting the quantity when an integer value is passed in' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/set_item_quantity/#{wishlist.wished_items.first.id}",- headers: headers_bearer,- params: {- quantity: '18'- }-- expect(response.status).to eq(200)- expect(json_response['data']['attributes']['quantity']).to eql (18)- end-- it 'must return error 422 if a random string is passed in as the quantity value' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/set_item_quantity/#{wishlist.wished_items.first.id}",- headers: headers_bearer,- params: {- quantity: 'some string'- }-- expect(response.status).to eq(422)- end-- it 'must return error 422 if 0 is passed in as the quantity value' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/set_item_quantity/#{wishlist.wished_items.first.id}",- headers: headers_bearer,- params: {- quantity: 0- }-- expect(response.status).to eq(422)- end-- it 'must return error 422 if "0" is passed in as the quantity value' do- patch "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/set_item_quantity/#{wishlist.wished_items.first.id}",- headers: headers_bearer,- params: {- quantity: '0'- }-- expect(response.status).to eq(422)- end- end-- describe '#remove_item' do- let!(:wished_item) do- wishlist.wished_items.create({ variant: create(:variant) })- end-- it 'must permit deletion of a wishlist' do- delete "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/remove_item/#{wishlist.wished_items.first.id}", headers: headers_bearer-- expect(response.status).to eq(200)- expect(json_response['data']['type']).to eql ('wished_item')- end-- context 'user not authorised to access this action' do- it 'can not delete an item from another users wishlist' do- delete "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/remove_item/#{wishlist.wished_items.first.id}"-- expect(response.status).to eq(403)- end- end- end-- describe '#add_items' do- subject(:post_add_item) do- post "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/add_items", headers: headers_bearer, params: params- end-- let!(:variant) { create(:variant) }- let!(:wished_item) { nil }- let!(:wished_item_1) { nil }- let!(:wished_item_2) { nil }- let!(:wished_item_3) { nil }-- before { post_add_item }-- let(:params) do- {- wished_items: [- { variant_id: variant.id.to_s, quantity: 3 }- ]- }- end-- it 'returns wishlist in response' do- expect(json_response['data']['type']).to eql ('wishlist')- expect(json_response['data']['id']).to eql wishlist.id.to_s-- expect(json_response['data']['attributes']['token']).to eq wishlist.token- expect(json_response['data']['attributes']['name']).to eq wishlist.name- expect(json_response['data']['attributes']['is_private']).to be true- expect(json_response['data']['attributes']['is_default']).to be false- expect(json_response['data']['attributes']['variant_included']).to be false-- expect(json_response['data']['relationships']['wished_items']).not_to be_empty- end-- it 'creates wished item' do- expect(user.wishlists.reload.first.wished_items.take.quantity).to eq 3- end-- context 'when many variants are passed' do- let(:params) do- {- wished_items: [- { variant_id: variant.id.to_s, quantity: 1 },- { variant_id: variant_1.id.to_s, quantity: 2 },- { variant_id: variant_2.id.to_s, quantity: 3 },- { variant_id: variant_3.id.to_s, quantity: 4 }- ]- }- end- let(:variant_1) { create(:variant) }- let(:variant_2) { create(:variant) }- let(:variant_3) { create(:variant) }-- it 'creates many wished items' do- expect(user.wishlists.reload.first.wished_items.count).to eq 4- end-- context 'when some variants are already in the wishlist' do- let!(:wished_item_1) { create(:wished_item, wishlist: user.wishlists.first, variant: variant_1, quantity: 1) }- let!(:wished_item_2) { create(:wished_item, wishlist: user.wishlists.first, variant: variant_2, quantity: 1) }- let!(:wished_item_3) { create(:wished_item, wishlist: user.wishlists.first, variant: variant_3, quantity: 1) }-- it 'updates them accordingly' do- expect(wished_item_1.reload.quantity).to eq 2- expect(wished_item_2.reload.quantity).to eq 3- expect(wished_item_3.reload.quantity).to eq 4- end- end-- context 'when some of params is invalid' do- let(:params) do- {- wished_items: [- { variant_id: variant.id.to_s, quantity: 1 },- { variant_id: create(:variant).id.to_s, quantity: 0 }- ]- }- end-- it 'does not create any wished item' do- expect(user.wishlists.reload.first.wished_items).to be_empty- end- end- end-- context 'when a variant is already in the wishlist' do- let!(:wished_item) { create(:wished_item, wishlist: user.wishlists.first, variant: wished_variant, quantity: 2) }- let(:wished_variant) { create(:variant) }-- context 'when quantity is passed' do- let(:params) do- {- wished_items: [- { variant_id: wished_variant.id.to_s, quantity: 3 }- ]- }- end-- it_behaves_like 'returns 200 HTTP status'-- it 'updates quantity' do- expect(wished_item.reload.quantity).to eq 3- end- end-- context 'when quantity is not passed' do- let(:params) do- {- wished_items: [- { variant_id: wished_variant.id.to_s }- ]- }- end-- it_behaves_like 'returns 200 HTTP status'-- it 'updates quantity to 1' do- expect(wished_item.reload.quantity).to eq 1- end- end-- context 'when passed quantity is 0' do- let(:params) do- {- wished_items: [- { variant_id: wished_variant.id.to_s, quantity: 0 }- ]- }- end-- it 'does not create wished item' do- expect(user.wishlists.reload.first.wished_items.count).to eq 1- end-- it 'returns error message' do- expect(response.status).to eq(422)- expect(json_response['error']).to eq 'Quantity must be greater than 0'- end- end- end-- context 'when quantity is not passed' do- let(:params) do- {- wished_items: [- { variant_id: variant.id.to_s }- ]- }- end-- it_behaves_like 'returns 200 HTTP status'-- it 'creates wished item with quantity 1' do- expect(user.wishlists.reload.first.wished_items.count).to eq 1- expect(user.wishlists.first.wished_items.take.quantity).to eq 1- end- end-- context 'when variant_id is not passed' do- let(:params) do- {- wished_items: [- { quantity: 3 }- ]- }- end-- it_behaves_like 'returns 422 HTTP status'-- it 'does not create wished item' do- expect(user.wishlists.reload.first.wished_items).to be_empty- end- end-- context 'when passed quantity is 0' do- let(:params) do- {- wished_items: [- { variant_id: variant.id.to_s, quantity: 0 }- ]- }- end-- it 'does not create wished item' do- expect(user.wishlists.reload.first.wished_items).to be_empty- end-- it 'returns error message' do- expect(response.status).to eq(422)- expect(json_response['error']).to eq 'Quantity must be greater than 0'- end- end- end-- describe '#remove_items' do- subject(:remove_items) do- delete "/api/v2/storefront/wishlists/#{user.wishlists.first.token}/remove_items", params: { wished_items_ids: wished_items_ids }, headers: headers_bearer- end-- let!(:wished_item_1) { create(:wished_item, wishlist: user.wishlists.first, variant: create(:variant), quantity: 1) }- let!(:wished_item_2) { create(:wished_item, wishlist: user.wishlists.first, variant: create(:variant), quantity: 2) }- let!(:wished_item_3) { create(:wished_item, wishlist: user.wishlists.first, variant: create(:variant), quantity: 3) }- let!(:wished_item_4) { create(:wished_item, wishlist: user.wishlists.first, variant: create(:variant), quantity: 4) }-- context 'when wished item is removed' do- before { remove_items }-- let(:wished_items_ids) { [wished_item_2.id] }-- it 'returns wishlist in response' do- expect(json_response['data']['type']).to eql ('wishlist')- expect(json_response['data']['id']).to eql wishlist.id.to_s-- expect(json_response['data']['attributes']['token']).to eq wishlist.token- expect(json_response['data']['attributes']['name']).to eq wishlist.name- expect(json_response['data']['attributes']['is_private']).to be true- expect(json_response['data']['attributes']['is_default']).to be false- expect(json_response['data']['attributes']['variant_included']).to be false-- expect(json_response['data']['relationships']['wished_items']).not_to be_empty- end-- context 'when there is one wished item to remove' do- it_behaves_like 'returns 200 HTTP status'-- it 'removes wished item' do- expect(wishlist.wished_items).to match_array([wished_item_1, wished_item_3, wished_item_4])- end- end-- context 'when there are many wished items to remove' do- let(:wished_items_ids) { [wished_item_2.id, wished_item_3.id] }-- it_behaves_like 'returns 200 HTTP status'-- it 'removes wished items' do- expect(wishlist.wished_items).to match_array([wished_item_1, wished_item_4])- end- end- end-- context 'when wished item is not removed' do- let(:wished_items_ids) { [wished_item_2.id] }-- before do- allow_any_instance_of(ActiveRecord::RecordNotDestroyed).to receive_message_chain(:record, :errors, :full_messages, :to_sentence).and_return('some error')- allow_any_instance_of(Spree::WishedItem).to receive(:destroy!).and_raise(ActiveRecord::RecordNotDestroyed)- remove_items- end-- it_behaves_like 'returns 422 HTTP status'- end-- context 'user not authorised to access this action' do- let(:headers_bearer) { {} }- let(:wished_items_ids) { [wished_item_2.id] }-- before { remove_items }-- it_behaves_like 'returns 403 HTTP status'- end- end-enddiff --git a/legacy_api_v2/spec/requests/spree/oauth/token_spec.rb b/legacy_api_v2/spec/requests/spree/oauth/token_spec.rbdeleted file mode 100644index 8286d92902..0000000000--- a/legacy_api_v2/spec/requests/spree/oauth/token_spec.rb+++ /dev/null@@ -1,195 +0,0 @@-require 'spec_helper'-require 'digest'--describe 'Spree OAuth', type: :request do- let!(:user) { create(:user, email: '[email protected]', password: 'secret', password_confirmation: 'secret') }- let(:token) { Spree::OauthAccessToken.active_for(user).last }- let(:client_secret) { 'secret' }- let(:client) { create(:oauth_application, secret: client_secret) }-- describe 'get token' do- shared_examples 'does not return a token' do- it do- expect(response.status).to eq(400)- expect(json_response[:error]).to eq('invalid_grant')- end- end-- shared_examples 'returns a token' do- it 'with all required attributes' do- expect(response.status).to eq(200)- expect(json_response).to have_attributes(%w[access_token token_type expires_in created_at])- expect(json_response['token_type']).to eq('Bearer')- end-- it 'returns non encrypted token and stores encrypted version in the database' do- expect(Digest::SHA256.hexdigest(json_response['access_token'])).to eq(token.token)- end- end-- context 'with client credentials' do- context 'with valid credentials' do- let(:token) { Spree::OauthAccessToken.where(application: client).last }-- let(:params) do- {- client_id: client.uid,- client_secret: client_secret,- grant_type: 'client_credentials',- scope: 'admin'- }- end-- before { post '/spree_oauth/token', params: params }-- it_behaves_like 'returns a token'-- it 'creates new application token' do- expect(token.resource_owner_id).to be_nil- expect(token.resource_owner_type).to be_nil- expect(token.application).to eq(client)- expect(token.scopes).to eq(['admin'])- end- end-- context 'without client secret' do- let(:params) do- {- client_id: client.uid,- grant_type: 'client_credentials'- }- end-- before { post '/spree_oauth/token', params: params }-- it { expect(response.status).to eq(401) }- end- end-- context 'by password' do- context 'with client' do- before do- allow(Spree.user_class).to receive(:find_for_database_authentication).with(hash_including(:email)) { user }- allow(user).to receive(:valid_for_authentication?).and_return(true)- allow(user).to receive(:active_for_authentication?).and_return(true)- end-- context 'with valid credentials' do- let(:params) do- {- client_id: client.uid,- client_secret: client_secret,- grant_type: 'password',- username: user.email,- password: 'secret',- scope: 'admin'- }- end-- before { post '/spree_oauth/token', params: params }-- it_behaves_like 'returns a token'-- it 'creates new user token tied to application' do- expect(token.resource_owner_id).to eq(user.id)- expect(token.resource_owner_type).to eq('Spree::LegacyUser')- expect(token.application).to eq(client)- expect(token.scopes).to eq(['admin'])- end- end-- context 'with invalid client credentials' do- let(:params) do- {- client_id: client.uid,- grant_type: 'password',- username: user.email,- password: 'secret',- scope: 'admin'- }- end-- before { post '/spree_oauth/token', params: params }-- it { expect(response.status).to eq(401) }- end- end-- context 'without client, with scopes' do- let(:params) do- {- grant_type: 'password',- username: user.email,- password: 'secret',- scope: 'admin'- }- end-- before do- allow(Spree.user_class).to receive(:find_for_database_authentication).with(hash_including(:email)) { user }- allow(user).to receive(:valid_for_authentication?).and_return(true)- allow(user).to receive(:active_for_authentication?).and_return(true)- post '/spree_oauth/token', params: params- end-- it_behaves_like 'returns a token'-- it 'creates new user token' do- expect(token.resource_owner_id).to eq(user.id)- expect(token.resource_owner_type).to eq('Spree::LegacyUser')- expect(token.scopes).to eq(['admin'])- end- end-- context 'with confirmation' do- before do- module Spree- module Auth- class Config- def self.[](key)- {- confirmable: true- }[key]- end-- def self.[]=(key)- end- end- end- end-- allow(Spree.user_class).to receive(:find_for_database_authentication).with(hash_including(:email)) { user }- allow(user).to receive(:valid_for_authentication?).and_return(true)- allow(user).to receive(:active_for_authentication?).and_return(active_value)- post '/spree_oauth/token?grant_type=password&[email protected]&password=secret'- end-- context 'when the user is confirmed' do- let(:active_value) { true }-- it 'creates new user token' do- expect(token.resource_owner_id).to eq(user.id)- expect(token.resource_owner_type).to eq('Spree::LegacyUser')- end-- it_behaves_like 'returns a token'- end-- context 'when the user is not confirmed' do- let(:active_value) { false }-- it_behaves_like 'does not return a token'- end- end-- context 'user does not exist' do- before do- allow(Spree.user_class).to receive(:find_for_database_authentication).with(hash_including(:email)) { nil }- post '/spree_oauth/token?grant_type=password&[email protected]&password=secret'- end-- it_behaves_like 'does not return a token'- end- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/address_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/address_serializer_spec.rbdeleted file mode 100644index 7c2015bd73..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/address_serializer_spec.rb+++ /dev/null@@ -1,65 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::AddressSerializer do- subject { described_class.new(address).serializable_hash }-- let(:user) { create(:user) }- let(:address) { create(:address, user: user) }-- it do- expect(subject).to eq(- {- data: {- id: address.id.to_s,- type: :address,- attributes: {- firstname: address.firstname,- lastname: address.lastname,- address1: address.address1,- address2: address.address2,- city: address.city,- zipcode: address.zipcode,- phone: address.phone,- state_name: address.state_name,- alternative_phone: address.alternative_phone,- company: address.company,- created_at: address.created_at,- updated_at: address.updated_at,- deleted_at: address.deleted_at,- label: address.label,- quick_checkout: false,- latitude: address.latitude,- longitude: address.longitude,- public_metadata: {},- private_metadata: {}- },- relationships: {- country: {- data: {- id: address.country_id.to_s,- type: :country- }- },- state: {- data: {- id: address.state_id.to_s,- type: :state- }- },- user: {- data: {- id: user.id.to_s,- type: :user- }- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/adjustment_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/adjustment_serializer_spec.rbdeleted file mode 100644index 7d6e69005c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/adjustment_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::AdjustmentSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:tax_adjustment, order: create(:order)) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rbdeleted file mode 100644index c8ce92115a..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/asset_serializer_spec.rb+++ /dev/null@@ -1,48 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::AssetSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:viewable) { create(:variant) }- let(:type) { :asset }- let(:resource) { create(type, viewable: viewable) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- viewable_type: resource.viewable_type,- attachment_height: resource.attachment_height,- attachment_file_size: resource.attachment_file_size,- position: resource.position,- attachment_content_type: resource.attachment_content_type,- attachment_file_name: resource.attachment_file_name,- type: resource.type,- attachment_updated_at: resource.attachment_updated_at,- alt: resource.alt,- created_at: resource.created_at,- updated_at: resource.updated_at,- public_metadata: resource.public_metadata,- private_metadata: resource.private_metadata- },- relationships: {- viewable: {- data: {- id: viewable.id.to_s,- type: :variant- }- },- metafields: {- data: []- }- },- type: type- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/country_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/country_serializer_spec.rbdeleted file mode 100644index f7e1fa6365..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/country_serializer_spec.rb+++ /dev/null@@ -1,45 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::CountrySerializer do- subject { described_class.new(country) }-- let(:country) { create(:country, states: create_list(:state, 2)) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: country.id.to_s,- type: :country,- attributes: {- iso_name: country.iso_name,- iso: country.iso,- iso3: country.iso3,- name: country.name,- numcode: country.numcode,- states_required: country.states_required,- created_at: country.created_at,- updated_at: country.updated_at,- zipcode_required: country.zipcode_required- },- relationships: {- states: {- data: [- {- id: country.states.first.id.to_s,- type: :state- },- {- id: country.states.second.id.to_s,- type: :state- }- ]- }- },- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rbdeleted file mode 100644index ccf04c0bfa..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/credit_card_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::CreditCardSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:credit_card) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rbdeleted file mode 100644index d6acc123d6..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/customer_return_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::CustomerReturnSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:customer_return) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rbdeleted file mode 100644index 7dd799d42f..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_link_serializer_spec.rb+++ /dev/null@@ -1,41 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::DigitalLinkSerializer do- subject { described_class.new(digital_link).serializable_hash }-- let(:digital_link) { create(:digital_link) }-- it do- expect(subject).to eq(- {- data: {- id: digital_link.id.to_s,- type: :digital_link,- attributes: {- access_counter: 0,- token: digital_link.token- },- relationships: {- digital: {- data: {- id: digital_link.digital.id.to_s,- type: :digital- }- },- line_item: {- data: {- id: digital_link.line_item.id.to_s,- type: :line_item- }- }- }- }- }- )- end-- it { expect(subject[:data][:id]).to be_kind_of(String) }- it { expect(subject[:data][:type]).to be(:digital_link) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rbdeleted file mode 100644index 29fe754504..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/digital_serializer_spec.rb+++ /dev/null@@ -1,38 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::DigitalSerializer do- subject { described_class.new(digital).serializable_hash }-- let(:digital) { create(:digital) }-- it do- expect(subject).to eq(- {- data: {- id: digital.id.to_s,- type: :digital,- attributes: {- byte_size: digital.attachment.byte_size.to_i,- content_type: digital.attachment.content_type.to_s,- filename: digital.attachment.filename.to_s,- url: Rails.application.routes.url_helpers.polymorphic_url(digital.attachment, only_path: true)- },- relationships: {- variant: {- data: {- id: digital.variant.id.to_s,- type: :variant- }- }- }- }- }- )- end-- it { expect(subject[:data][:id]).to be_kind_of(String) }- it { expect(subject[:data][:type]).to be(:digital) }- it { expect(subject[:data][:attributes][:url]).to include('thinking-cat.jpg') }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/image_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/image_serializer_spec.rbdeleted file mode 100644index 22fd885b12..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/image_serializer_spec.rb+++ /dev/null@@ -1,38 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ImageSerializer do- subject { described_class.new(image) }-- let(:variant) { create(:variant) }- let(:image) { create(:image, viewable: variant) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: image.id.to_s,- type: :image,- attributes: {- styles: image.styles,- position: image.position,- alt: image.alt,- created_at: image.created_at,- updated_at: image.updated_at,- transformed_url: image.generate_url(size: ''),- original_url: image.original_url- },- relationships: {- viewable: {- data: {- id: variant.id.to_s,- type: :variant- }- }- },- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rbdeleted file mode 100644index df3a31866b..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/inventory_unit_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::InventoryUnitSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:inventory_unit) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rbdeleted file mode 100644index cdcc05db87..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/line_item_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::LineItemSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:line_item) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/log_entry_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/log_entry_serializer_spec.rbdeleted file mode 100644index 673431b3de..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/log_entry_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::LogEntrySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:log_entry) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/metafield_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/metafield_serializer_spec.rbdeleted file mode 100644index d6f1668e61..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/metafield_serializer_spec.rb+++ /dev/null@@ -1,64 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::MetafieldSerializer do- let(:product) { create(:product) }-- subject { described_class.new(Spree::Metafield.find(metafield.id)) }-- context 'with ShortText type' do- let(:metafield_definition) { create(:metafield_definition, namespace: 'custom', key: 'test_field', metafield_type: 'Spree::Metafields::ShortText') }- let(:metafield) { create(:metafield, metafield_definition: metafield_definition, value: 'Test Value', resource: product) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: metafield.id.to_s,- type: :metafield,- attributes: {- name: metafield.name,- type: metafield.type,- display_on: metafield.display_on,- key: 'custom.test_field',- value: 'Test Value'- }- }- }- )- end- end-- context 'with Number type' do- let(:metafield_definition) { create(:metafield_definition, namespace: 'custom', key: 'test_field', metafield_type: 'Spree::Metafields::Number') }- let(:metafield) { create(:metafield, metafield_definition: metafield_definition, value: '123.45', resource: product, type: 'Spree::Metafields::Number') }-- it do- expect(subject.serializable_hash[:data][:attributes][:value]).to be_kind_of(BigDecimal)- expect(subject.serializable_hash[:data][:attributes][:value]).to eq(BigDecimal('123.45'))- end- end-- context 'with Json type' do- let(:metafield_definition) { create(:metafield_definition, namespace: 'custom', key: 'test_field', metafield_type: 'Spree::Metafields::Json') }- let(:metafield) { create(:metafield, metafield_definition: metafield_definition, value: '{"key": "value", "number": 42, "nested": {"foo": "bar"}}', resource: product, type: 'Spree::Metafields::Json') }- subject { described_class.new(Spree::Metafield.find(metafield.id)) }-- it do- expect(subject.serializable_hash[:data][:attributes][:value]).to be_kind_of(Hash)- expect(subject.serializable_hash[:data][:attributes][:value]).to eq({ 'key' => 'value', 'number' => 42, 'nested' => { 'foo' => 'bar' } })- end- end-- context 'with Json array type' do- let(:metafield_definition) { create(:metafield_definition, namespace: 'custom', key: 'test_field', metafield_type: 'Spree::Metafields::Json') }- let(:metafield) { create(:metafield, metafield_definition: metafield_definition, value: '[1, 2, 3, "test"]', resource: product, type: 'Spree::Metafields::Json') }- subject { described_class.new(Spree::Metafield.find(metafield.id)) }-- it do- expect(subject.serializable_hash[:data][:attributes][:value]).to be_kind_of(Array)- expect(subject.serializable_hash[:data][:attributes][:value]).to eq([1, 2, 3, 'test'])- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rbdeleted file mode 100644index d676129ee0..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_type_serializer_spec.rb+++ /dev/null@@ -1,47 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::OptionTypeSerializer do- subject { described_class.new(option_type).serializable_hash }-- let(:option_type) { create(:option_type, option_values: create_list(:option_value, 2)) }-- it do- expect(subject).to eq(- {- data: {- id: option_type.id.to_s,- type: :option_type,- attributes: {- name: option_type.name,- presentation: option_type.presentation,- position: option_type.position,- created_at: option_type.created_at,- updated_at: option_type.updated_at,- filterable: option_type.filterable,- public_metadata: {},- private_metadata: {}- },- relationships: {- option_values: {- data: [- {- id: option_type.option_values.first.id.to_s,- type: :option_value- },- {- id: option_type.option_values.second.id.to_s,- type: :option_value- }- ]- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rbdeleted file mode 100644index 1710215590..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/option_value_serializer_spec.rb+++ /dev/null@@ -1,41 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::OptionValueSerializer do- subject { described_class.new(option_value).serializable_hash }-- let(:option_value) { create(:option_value) }-- it do- expect(subject).to eq(- {- data: {- id: option_value.id.to_s,- type: :option_value,- attributes: {- position: option_value.position,- name: option_value.name,- presentation: option_value.presentation,- display_presentation: option_value.display_presentation,- created_at: option_value.created_at,- updated_at: option_value.updated_at,- public_metadata: {},- private_metadata: {}- },- relationships: {- option_type: {- data: {- id: option_value.option_type.id.to_s,- type: :option_type- }- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/order_promotion_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/order_promotion_serializer_spec.rbdeleted file mode 100644index 2d41a9baee..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/order_promotion_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::OrderPromotionSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:order_promotion) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rbdeleted file mode 100644index 7d1861e0ed..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_capture_event_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PaymentCaptureEventSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:payment_capture_event) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_method_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_method_serializer_spec.rbdeleted file mode 100644index 40a29209cf..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_method_serializer_spec.rb+++ /dev/null@@ -1,51 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PaymentMethodSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let!(:store) { @default_store }- let(:resource) { create(:credit_card_payment_method) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: resource.id.to_s,- type: :payment_method,- attributes: {- name: resource.name,- description: resource.description,- auto_capture: nil,- active: resource.active,- type: resource.type,- position: resource.position,- display_on: resource.display_on,- deleted_at: resource.deleted_at,- created_at: resource.created_at,- updated_at: resource.updated_at,- preferences: {- dummy_key: 'PUBLICKEY123',- dummy_secret_key: 'SECRETKEY123'- },- public_metadata: {},- private_metadata: {}- },- relationships: {- stores: {- data: [- {- id: store.id.to_s,- type: :store- }- ]- }- }- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rbdeleted file mode 100644index 7a5218f67c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/payment_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PaymentSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:payment) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/price_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/price_serializer_spec.rbdeleted file mode 100644index eea579821c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/price_serializer_spec.rb+++ /dev/null@@ -1,39 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PriceSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:currency) { 'USD' }- let(:variant) { create(:variant) }- let(:resource) { variant.price_in(currency) }- let(:type) { :price }-- it do- expect(subject).to(- eq(- data: {- id: resource.id.to_s,- type: type,- attributes: {- amount: resource.amount,- currency: resource.currency,- deleted_at: resource.deleted_at,- created_at: resource.created_at,- updated_at: resource.updated_at,- compare_at_amount: resource.compare_at_amount,- display_compare_at_price: resource.display_compare_at_price.to_s,- display_amount: resource.display_amount.to_s,- display_price: resource.display_price.to_s,- display_compare_at_amount: resource.display_compare_at_amount.to_s,- display_compare_at_price_including_vat_for: resource.display_compare_at_price_including_vat_for({}).to_s,- display_price_including_vat_for: resource.display_price_including_vat_for({}).to_s- }- }- )- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_property_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_property_serializer_spec.rbdeleted file mode 100644index e9fbe9c833..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_property_serializer_spec.rb+++ /dev/null@@ -1,28 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ProductPropertySerializer do- subject { described_class.new(product_property) }-- let(:product_property) { create(:product_property) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: product_property.id.to_s,- type: :product_property,- attributes: {- value: product_property.value,- position: product_property.position,- show_property: product_property.show_property,- filter_param: product_property.filter_param,- created_at: product_property.created_at,- updated_at: product_property.updated_at- }- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_serializer_spec.rbdeleted file mode 100644index 730ad52354..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/product_serializer_spec.rb+++ /dev/null@@ -1,161 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ProductSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(product, params: serializer_params).serializable_hash }-- let(:store) { @default_store }- let(:taxonomy) { store.taxonomies.first }- let!(:images) { create_list(:image, 2) }- let(:product) do- create(- :product_in_stock,- name: 'Test Product',- variants_including_master: [create(:variant, images: images), create(:variant)],- option_types: create_list(:option_type, 2),- product_properties: create_list(:product_property, 2),- taxons: create_list(:taxon, 2, taxonomy: taxonomy),- tax_category: create(:tax_category),- stores: [store]- )- end- let(:serializable_hash) do- {- data: {- id: product.id.to_s,- type: :product,- attributes: {- name: product.name,- description: product.description,- available_on: product.available_on,- make_active_at: product.make_active_at,- status: product.status,- deleted_at: product.deleted_at,- slug: product.slug,- meta_description: product.meta_description,- meta_keywords: product.meta_keywords,- created_at: product.created_at,- updated_at: product.updated_at,- promotionable: product.promotionable,- meta_title: product.meta_title,- discontinue_on: product.discontinue_on,- purchasable: product.purchasable?,- in_stock: product.in_stock?,- backorderable: product.backorderable?,- available: product.available?,- currency: currency,- price: BigDecimal(10),- display_price: '$10.00',- compare_at_price: BigDecimal(15),- display_compare_at_price: '$15.00',- variant_count: product.variant_count,- classification_count: product.classification_count,- total_image_count: product.total_image_count,- public_metadata: {},- private_metadata: {}- },- relationships: {- tax_category: {- data: {- id: product.tax_category.id.to_s,- type: :tax_category- }- },- primary_variant: {- data: {- id: product.master.id.to_s,- type: :variant- }- },- default_variant: {- data: {- id: product.default_variant.id.to_s,- type: :variant- }- },- variants: {- data: [- {- id: product.variants.first.id.to_s,- type: :variant- },- {- id: product.variants.second.id.to_s,- type: :variant- }- ]- },- option_types: {- data: [- {- id: product.option_types.first.id.to_s,- type: :option_type- },- {- id: product.option_types.second.id.to_s,- type: :option_type- }- ]- },- product_properties: {- data: [- {- id: product.product_properties.first.id.to_s,- type: :product_property- },- {- id: product.product_properties.second.id.to_s,- type: :product_property- }- ]- },- taxons: {- data: [- {- id: product.taxons.first.id.to_s,- type: :taxon- },- {- id: product.taxons.second.id.to_s,- type: :taxon- }- ]- },- images: {- data: [- {- id: product.variant_images.first.id.to_s,- type: :image- },- {- id: product.variant_images.second.id.to_s,- type: :image- }- ]- },- metafields: {- data: []- }- }- }- }- end-- before do- product.reload- product.master.prices.first_or_create!(currency: currency, amount: 10, compare_at_amount: 15)- end-- context 'without a store in the params' do- subject { described_class.new(product, params: serializer_params.merge(store: nil)).serializable_hash }-- it 'returns all the product taxons' do- expect(subject).to eq(serializable_hash)- end- end-- it { expect(subject).to eq(serializable_hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_action_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_action_serializer_spec.rbdeleted file mode 100644index 118eab7182..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_action_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PromotionActionSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { Spree::PromotionAction.create(promotion: create(:promotion), type: 'Spree::Promotion::Actions::FreeShipping') }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_category_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_category_serializer_spec.rbdeleted file mode 100644index 925445d42d..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_category_serializer_spec.rb+++ /dev/null@@ -1,44 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PromotionCategorySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:promotion_category, name: '2021 Promotions', code: '2021-PROMOS') }- let!(:promtion_a) { create(:promotion, promotion_category: resource)}- let!(:promtion_b) { create(:promotion, promotion_category: resource)}-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: resource.id.to_s,- type: :promotion_category,- attributes: {- name: resource.name,- code: resource.code,- created_at: resource.created_at,- updated_at: resource.updated_at- },- relationships: {- promotions: {- data: [- {- id: resource.promotions.first.id.to_s,- type: :promotion- },- {- id: resource.promotions.second.id.to_s,- type: :promotion- }- ]- }- }- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_rule_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_rule_serializer_spec.rbdeleted file mode 100644index 55d5a0dbab..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_rule_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PromotionRuleSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:promotion_rule) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rbdeleted file mode 100644index 055d90c2cc..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/promotion_serializer_spec.rb+++ /dev/null@@ -1,78 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PromotionSerializer do- subject { described_class.new(resource, params: serializer_params).serializable_hash }- include_context 'API v2 serializers params'-- let(:promotion_category) { create(:promotion_category) }- let(:promotion_rule) { create(:promotion_rule) }- let(:resource) { create(:promotion_with_item_adjustment, promotion_category: promotion_category, promotion_rules: [promotion_rule]) }-- it do- expect(subject).to eq(- {- data: {- id: resource.id.to_s,- type: :promotion,- attributes: {- description: resource.description,- expires_at: resource.expires_at,- starts_at: resource.starts_at,- name: resource.name,- type: resource.type,- usage_limit: resource.usage_limit,- match_policy: resource.match_policy,- code: resource.code,- advertise: resource.advertise,- path: resource.path,- public_metadata: {},- private_metadata: {},- created_at: resource.created_at,- updated_at: resource.updated_at,- multi_codes: resource.multi_codes,- code_prefix: resource.code_prefix,- number_of_codes: resource.number_of_codes,- kind: resource.kind- },- relationships: {- promotion_category: {- data: {- id: resource.promotion_category.id.to_s,- type: :promotion_category- },- },- promotion_rules: {- data: [- {- id: resource.promotion_rules.first.id.to_s,- type: :promotion_rule- }- ]- },- promotion_actions: {- data: [- {- id: resource.promotion_actions.first.id.to_s,- type: :promotion_action- }- ]- },- stores: {- data: [- {- id: resource.stores.first.id.to_s,- type: :store- }- ]- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/property_serializer_spec.rbdeleted file mode 100644index 312bd09c4a..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb+++ /dev/null@@ -1,35 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PropertySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:type) { :property }- let(:resource) { create(type) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- type: type,- attributes: {- name: resource.name,- presentation: resource.presentation,- created_at: resource.created_at,- updated_at: resource.updated_at,- filterable: resource.filterable,- kind: "short_text",- filter_param: resource.filter_param,- kind: resource.kind,- display_on: resource.display_on,- position: resource.position,- public_metadata: resource.public_metadata,- private_metadata: resource.private_metadata- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rbdeleted file mode 100644index 61f8127831..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/prototype_serializer_spec.rb+++ /dev/null@@ -1,51 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::PrototypeSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:property) { create(:property) }- let(:option_type) { create(:option_type) }- let(:resource) { create(type, properties: [property], option_types: [option_type], taxons: [taxon]) }- let(:taxon) { create(:taxon) }- let(:type) { :prototype }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- name: resource.name,- created_at: resource.created_at,- updated_at: resource.updated_at,- public_metadata: resource.public_metadata,- private_metadata: resource.private_metadata- },- relationships: {- properties: {- data: [{- id: property.id.to_s,- type: :property- }]- },- option_types: {- data: [{- id: option_type.id.to_s,- type: :option_type- }]- },- taxons: {- data: [{- id: taxon.id.to_s,- type: :taxon- }]- }- },- type: type- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rbdeleted file mode 100644index 807a0f29c1..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb+++ /dev/null@@ -1,26 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::RefundReasonSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:type) { :refund_reason }- let(:resource) { create(type) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- name: resource.name,- active: resource.active,- mutable: resource.mutable,- created_at: resource.created_at,- updated_at: resource.updated_at- },- type: type- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rbdeleted file mode 100644index 231f1c190e..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/refund_serializer_spec.rb+++ /dev/null@@ -1,33 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::RefundSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:refund, amount: 5.0, refunder: create(:user)) }-- it_behaves_like 'an ActiveJob serializable hash'-- context 'with included relationships' do- subject do- described_class.new(resource, include: described_class.relationships_to_serialize.keys).serializable_hash- end-- it 'serializes the refund' do- expect(subject[:data][:id]).to eq(resource.id.to_s)- expect(subject[:data][:type]).to eq(:refund)-- expect(subject[:data][:relationships]).to include(- refunder: {- data: {- id: resource.refunder_id.to_s,- type: :admin_user- }- }- )-- expect(subject[:included]).to include(hash_including(id: resource.refunder_id.to_s))- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rbdeleted file mode 100644index c9361e7397..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb+++ /dev/null@@ -1,19 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReimbursementCreditSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:type) { :reimbursement_credit }- let(:resource) { create(type, creditable: create(:store_credit)) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- type: type- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rbdeleted file mode 100644index d657c7f951..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb+++ /dev/null@@ -1,71 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReimbursementSerializer do- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let(:reimbursement_credit) { create(:reimbursement_credit, creditable: create(:store_credit)) }- let(:payment) { create(:payment, state: 'completed') }- let(:type) { :reimbursement }- let(:refund) { create(:refund, amount: payment.credit_allowed - 1) }- let(:user) { create(:admin_user) }- let(:resource) { create(type, refunds: [refund], credits: [reimbursement_credit], performed_by: user) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- number: resource.number,- reimbursement_status: resource.reimbursement_status,- total: resource.total,- created_at: resource.created_at,- updated_at: resource.updated_at,- display_total: resource.display_total.to_s,- },- relationships: {- order: {- data: {- id: resource.order.id.to_s,- type: :order- }- },- customer_return: {- data: {- id: resource.customer_return.id.to_s,- type: :customer_return- }- },- refunds: {- data: [{- id: refund.id.to_s,- type: :refund- }]- },- reimbursement_credits: {- data: [{- id: reimbursement_credit.id.to_s,- type: :reimbursement_credit- }]- },- return_items: {- data: [{- id: resource.return_items.first.id.to_s,- type: :return_item- }]- },- performed_by: {- data: {- id: user.id.to_s,- type: :admin_user- }- }- },- type: type- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_type_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_type_serializer_spec.rbdeleted file mode 100644index eb6f088e96..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/reimbursement_type_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReimbursementTypeSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:reimbursement_type) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_reason_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_reason_serializer_spec.rbdeleted file mode 100644index 42254fbdd0..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_reason_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReturnAuthorizationReasonSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:return_authorization_reason) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rbdeleted file mode 100644index 8edcf9dd24..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_authorization_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReturnAuthorizationSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:return_authorization) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rbdeleted file mode 100644index 96337d5255..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/return_item_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ReturnItemSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:return_item) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/role_serializer_spec.rbdeleted file mode 100644index 262774bea7..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/role_serializer_spec.rb+++ /dev/null@@ -1,26 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::RoleSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:type) { :role }- let(:resource) { create(type) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- type: type,- attributes: {- name: resource.name,- created_at: resource.created_at,- updated_at: resource.updated_at- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rbdeleted file mode 100644index dca94fd2da..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipment_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ShipmentSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:shipment) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rbdeleted file mode 100644index 172508289c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_category_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ShippingCategorySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:shipping_category) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rbdeleted file mode 100644index 9878d82117..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_method_serializer_spec.rb+++ /dev/null@@ -1,63 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ShippingMethodSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:shipping_category) {create(:shipping_category) }- let(:tax_category) { create(:tax_category) }-- let(:resource) { create(:shipping_method, shipping_categories: [shipping_category], tax_category: tax_category) }-- it do- expect(subject).to eq(- {- data: {- id: resource.id.to_s,- type: :shipping_method,- attributes: {- name: resource.name,- code: resource.code,- admin_name: resource.admin_name,- display_on: resource.display_on,- tracking_url: resource.tracking_url,- deleted_at: resource.deleted_at,- created_at: resource.created_at,- updated_at: resource.updated_at,- public_metadata: {},- private_metadata: {}- },- relationships: {- calculator: {- data: {- id: resource.calculator.id.to_s,- type: :calculator- }- },- tax_category: {- data: {- id: tax_category.id.to_s,- type: :tax_category- }- },- shipping_categories: {- data: [- {- id: resource.shipping_categories.first.id.to_s,- type: :shipping_category- }- ]- },- shipping_rates: {- data: [- ]- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rbdeleted file mode 100644index 89e8160190..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/shipping_rate_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ShippingRateSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:shipping_rate) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_change_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_change_serializer_spec.rbdeleted file mode 100644index ff64fcf73c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_change_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StateChangeSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:state_change) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-end\ No newline at end of filediff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_serializer_spec.rbdeleted file mode 100644index 47adb52c74..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/state_serializer_spec.rb+++ /dev/null@@ -1,35 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StateSerializer do- subject { described_class.new(state) }-- let(:country) { create(:country) }- let(:state) { create(:state, country: country) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: state.id.to_s,- type: :state,- attributes: {- name: state.name,- abbr: state.abbr,- created_at: state.created_at,- updated_at: state.updated_at- },- relationships: {- country: {- data: {- id: country.id.to_s,- type: :country- }- },- },- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rbdeleted file mode 100644index a341f435ff..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb+++ /dev/null@@ -1,49 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StockItemSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { stock_location.stock_items.order(:id).first }- let(:stock_location) { create(:stock_location_with_items) }- let(:type) { :stock_item }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- backorderable: resource.backorderable,- count_on_hand: resource.count_on_hand,- created_at: resource.created_at,- deleted_at: resource.deleted_at,- is_available: resource.available?,- updated_at: resource.updated_at,- public_metadata: {},- private_metadata: {}- },- relationships: {- stock_location: {- data: {- id: stock_location.id.to_s,- type: :stock_location- }- },- variant: {- data: {- id: resource.variant.id.to_s,- type: :variant- }- },- metafields: {- data: []- }- },- type: type- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rbdeleted file mode 100644index f383629e7d..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb+++ /dev/null@@ -1,49 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StockLocationSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:stock_location, country: country) }- let(:type) { :stock_location }- let(:country) { create(:country) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- type: type,- attributes: {- active: resource.active,- address1: resource.address1,- address2: resource.address2,- admin_name: resource.admin_name,- display_name: resource.display_name,- backorderable_default: resource.backorderable_default,- company: resource.company,- city: resource.city,- created_at: resource.created_at,- deleted_at: resource.deleted_at,- default: resource.default,- name: resource.name,- phone: resource.phone,- propagate_all_variants: resource.propagate_all_variants,- state_name: resource.state_name,- updated_at: resource.updated_at,- zipcode: resource.zipcode- },- relationships: {- country: {- data: {- id: country.id.to_s,- type: :country- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rbdeleted file mode 100644index 468879e8fe..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb+++ /dev/null@@ -1,30 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StockMovementSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:type) { :stock_movement }- let(:stock_location) { create(:stock_location_with_items) }- let(:stock_item) { stock_location.stock_items.order(:id).first }- let(:resource) { create(type, stock_item: stock_item) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- quantity: resource.quantity,- action: resource.action,- originator_type: resource.originator_type,- created_at: resource.created_at,- updated_at: resource.updated_at- },- type: type- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rbdeleted file mode 100644index 9c4a3bb113..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb+++ /dev/null@@ -1,59 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StockTransferSerializer do- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let(:destination_location) { create(:stock_location) }- let(:resource) { create(type, destination_location: destination_location, source_location: source_location, stock_movements: [stock_movement]) }- let(:source_location) { create(:stock_location) }- let(:stock_item) { stock_location.stock_items.order(:id).first }- let(:stock_location) { create(:stock_location_with_items) }- let(:type) { :stock_transfer }-- let(:stock_movement) { build(:stock_movement, stock_item: stock_item) }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- attributes: {- type: resource.type,- reference: resource.reference,- created_at: resource.created_at,- updated_at: resource.updated_at,- number: resource.number,- public_metadata: resource.public_metadata,- private_metadata: resource.private_metadata- },- relationships: {- stock_movements: {- data: [{- id: stock_movement.id.to_s,- type: :stock_movement- }]- },- source_location: {- data: {- id: source_location.id.to_s,- type: :stock_location- }- },- destination_location: {- data: {- id: destination_location.id.to_s,- type: :stock_location- }- },- metafields: {- data: []- }- },- type: type,- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_category_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_category_serializer_spec.rbdeleted file mode 100644index 150d441d3a..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_category_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StoreCreditCategorySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:store_credit_category) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_event_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_event_serializer_spec.rbdeleted file mode 100644index 58a583409c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_event_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StoreCreditEventSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:store_credit_auth_event) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rbdeleted file mode 100644index cfb6dcf99a..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_serializer_spec.rb+++ /dev/null@@ -1,33 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StoreCreditSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:store_credit) }-- it_behaves_like 'an ActiveJob serializable hash'-- context 'with included relationships' do- subject do- described_class.new(resource, include: described_class.relationships_to_serialize.keys).serializable_hash- end-- it 'serializes the store credit' do- expect(subject[:data][:id]).to eq(resource.id.to_s)- expect(subject[:data][:type]).to eq(:store_credit)-- expect(subject[:data][:relationships]).to include(- created_by: {- data: {- id: resource.created_by_id.to_s,- type: :admin_user- }- }- )-- expect(subject[:included]).to include(hash_including(id: resource.created_by_id.to_s))- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_type_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_type_serializer_spec.rbdeleted file mode 100644index 7c65f483e8..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_credit_type_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StoreCreditTypeSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:store_credit_type) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_serializer_spec.rbdeleted file mode 100644index 33f958aa09..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb+++ /dev/null@@ -1,72 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::StoreSerializer do- subject { described_class.new(store).serializable_hash }-- let!(:store) { @default_store }- let!(:logo) do- store.logo.attach(io: File.new(Spree::Core::Engine.root + 'spec/fixtures' + 'thinking-cat.jpg'), filename: 'thinking-cat.jpg')- store.save- store.logo- end- let(:url_helpers) { Rails.application.routes.url_helpers }-- it 'generates the correct serialization' do- expect(subject).to eq(- {- data: {- id: store.id.to_s,- type: :store,- attributes: {- name: store.name,- url: store.url,- meta_description: store.meta_description,- meta_keywords: store.meta_keywords,- seo_title: store.seo_title,- mail_from_address: store.mail_from_address,- default_currency: store.default_currency,- code: store.code,- default: store.default,- created_at: store.created_at,- updated_at: store.updated_at,- supported_currencies: store.supported_currencies,- facebook: store.facebook,- twitter: store.twitter,- instagram: store.instagram,- default_locale: store.default_locale,- customer_support_email: store.customer_support_email,- description: store.description,- address: store.address,- contact_phone: store.contact_phone,- new_order_notifications_email: store.new_order_notifications_email,- public_metadata: {},- private_metadata: {},- seo_robots: store.seo_robots,- supported_locales: store.supported_locales,- deleted_at: store.deleted_at,- settings: store.settings,- logo: url_helpers.cdn_image_url(logo.attachment),- mailer_logo: nil,- favicon_path: nil,- storefront_custom_code_body_end: nil,- storefront_custom_code_body_start: nil,- storefront_custom_code_head: nil- },- relationships: {- default_country: {- data: {- id: store.default_country.id.to_s,- type: :country- }- },- metafields: {- data: []- }- },- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rbdeleted file mode 100644index 2f39ecac55..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_category_serializer_spec.rb+++ /dev/null@@ -1,35 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::TaxCategorySerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:tax_category) }- let(:type) { :tax_category }-- it do- expect(subject).to eq(- data: {- id: resource.id.to_s,- type: type,- attributes: {- name: resource.name,- description: resource.description,- is_default: resource.is_default,- deleted_at: resource.deleted_at,- created_at: resource.created_at,- updated_at: resource.updated_at,- tax_code: nil- },- relationships: {- tax_rates: {- data: []- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rbdeleted file mode 100644index 660cae6da3..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/tax_rate_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::TaxRateSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:tax_rate) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_image_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_image_serializer_spec.rbdeleted file mode 100644index 5e02c13faf..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_image_serializer_spec.rb+++ /dev/null@@ -1,27 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::TaxonImageSerializer do- subject { described_class.new(image) }-- let(:image) { create(:taxon_image) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: image.id.to_s,- type: :taxon_image,- attributes: {- alt: image.alt,- created_at: image.created_at,- updated_at: image.updated_at,- transformed_url: image.generate_url(size: ''),- original_url: image.original_url- },- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rbdeleted file mode 100644index 545c050282..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb+++ /dev/null@@ -1,182 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::TaxonSerializer do- subject { described_class.new(taxon.reload, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let(:taxonomy) { create(:taxonomy, store: store) }- let(:taxon) { create(:taxon, :with_description, taxonomy: taxonomy, products: create_list(:product, 2, stores: [store])) }- let!(:children) { create_list(:taxon, 2, taxonomy: taxonomy, parent: taxon) }- let(:url_helpers) { Rails.application.routes.url_helpers }-- context 'without products' do- it do- expect(subject).to match(- {- data: {- id: taxon.id.to_s,- type: :taxon,- attributes: {- position: taxon.position,- name: taxon.name,- permalink: taxon.permalink,- lft: taxon.lft,- rgt: taxon.rgt,- description: taxon.description.to_plain_text,- created_at: taxon.created_at,- updated_at: taxon.updated_at,- meta_title: taxon.meta_title,- meta_description: taxon.meta_description,- meta_keywords: taxon.meta_keywords,- depth: taxon.depth,- pretty_name: taxon.pretty_name,- seo_title: taxon.seo_title,- is_root: taxon.root?,- is_child: taxon.child?,- is_leaf: taxon.leaf?,- automatic: taxon.automatic?,- sort_order: taxon.sort_order,- rules_match_policy: taxon.rules_match_policy,- header_url: nil,- public_metadata: {},- private_metadata: {},- children_count: taxon.children_count,- classification_count: taxon.classification_count- },- relationships: {- parent: {- data: {- id: taxon.parent.id.to_s,- type: :taxon- }- },- taxonomy: {- data: {- id: taxon.taxonomy.id.to_s,- type: :taxonomy- }- },- image: {- data: nil- },- children: {- data: [- {- id: taxon.children.first.id.to_s,- type: :taxon- },- {- id: taxon.children.second.id.to_s,- type: :taxon- }- ]- },- metafields: {- data: []- }- }- }- }- )- end- end-- context 'with products' do- before do- serializer_params[:include_products] = true- end-- it do- expect(subject).to match(- {- data: {- id: taxon.id.to_s,- type: :taxon,- attributes: {- position: taxon.position,- name: taxon.name,- permalink: taxon.permalink,- lft: taxon.lft,- rgt: taxon.rgt,- description: taxon.description.to_plain_text,- created_at: taxon.created_at,- updated_at: taxon.updated_at,- meta_title: taxon.meta_title,- meta_description: taxon.meta_description,- meta_keywords: taxon.meta_keywords,- depth: taxon.depth,- pretty_name: taxon.pretty_name,- seo_title: taxon.seo_title,- is_root: taxon.root?,- is_child: taxon.child?,- is_leaf: taxon.leaf?,- automatic: taxon.automatic?,- sort_order: taxon.sort_order,- rules_match_policy: taxon.rules_match_policy,- header_url: nil,- public_metadata: {},- private_metadata: {},- children_count: taxon.children_count,- classification_count: taxon.classification_count- },- relationships: {- parent: {- data: {- id: taxon.parent.id.to_s,- type: :taxon- }- },- taxonomy: {- data: {- id: taxon.taxonomy.id.to_s,- type: :taxonomy- }- },- image: {- data: nil- },- products: {- data: [- {- id: taxon.products.first.id.to_s,- type: :product- },- {- id: taxon.products.second.id.to_s,- type: :product- }- ]- },- children: {- data: contain_exactly(- {- id: taxon.children.first.id.to_s,- type: :taxon- },- {- id: taxon.children.second.id.to_s,- type: :taxon- }- )- },- metafields: {- data: []- }- }- }- }- )- end- end-- context 'with header image' do- let(:taxon) { create(:taxon, :with_header_image, taxonomy: taxonomy) }-- it do- expect(subject[:data][:attributes][:header_url]).to eq(url_helpers.cdn_image_url(taxon.image.attachment))- end- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rbdeleted file mode 100644index ed6b903103..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/taxonomy_serializer_spec.rb+++ /dev/null@@ -1,53 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::TaxonomySerializer, retry: 3 do- subject { described_class.new(taxonomy).serializable_hash }-- let(:taxonomy) { create(:taxonomy) }- let(:taxon) { create(:taxon, taxonomy: taxonomy) }- let(:taxons_json) do- taxonomy.taxons.map do |taxon|- {- id: taxon.id.to_s,- type: :taxon- }- end- end-- it { expect(subject).to be_kind_of(Hash) }-- it do- expect(subject).to eq(- {- data: {- id: taxonomy.id.to_s,- type: :taxonomy,- attributes: {- name: taxonomy.name,- created_at: taxonomy.created_at,- updated_at: taxonomy.updated_at,- position: taxonomy.position,- public_metadata: {},- private_metadata: {}- },- relationships: {- root: {- data: {- id: taxonomy.root.id.to_s,- type: :taxon- }- },- taxons: {- data: taxons_json- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/user_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/user_serializer_spec.rbdeleted file mode 100644index a78ab0fc34..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/user_serializer_spec.rb+++ /dev/null@@ -1,82 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::UserSerializer do- subject { described_class.new(user, params: serializer_params) }-- include_context 'API v2 serializers params'-- let(:user) { create(:user_with_addresses) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: user.id.to_s,- type: :user,- attributes: {- email: user.email,- first_name: user.first_name,- last_name: user.last_name,- average_order_value: [],- lifetime_value: [],- selected_locale: nil,- store_credits: [],- created_at: user.created_at,- updated_at: user.updated_at,- public_metadata: {},- private_metadata: {}- },- relationships: {- bill_address: {- data: {- id: user.bill_address.id.to_s,- type: :address- }- },- ship_address: {- data: {- id: user.ship_address.id.to_s,- type: :address- }- }- }- }- }- )- end-- context 'when user has orders' do- before do- create(:completed_order_with_totals, user: user, currency: 'USD')- create(:completed_order_with_totals, user: user, currency: 'EUR')- create(:store_credit, amount: '100', store: store, user: user, currency: 'USD')- create(:store_credit, amount: '90', store: store, user: user, currency: 'EUR')- end-- it do- expect(subject.serializable_hash[:data][:attributes]).to eq({- email: user.email,- first_name: user.first_name,- last_name: user.last_name,- average_order_value: [{ amount: '110.00', currency: 'USD' }, { amount: '110.00', currency: 'EUR' }],- lifetime_value: [{ amount: '110.00', currency: 'USD' }, { amount: '110.00', currency: 'EUR' }],- selected_locale: nil,- store_credits: [{ amount: '100.00', currency: 'USD' }, { amount: '90.00', currency: 'EUR' }],- created_at: user.created_at,- updated_at: user.updated_at,- public_metadata: {},- private_metadata: {}- })- end- end-- context 'when user has selected non default locale' do- let(:user) { create(:user_with_addresses, selected_locale: 'fr') }-- it 'returns the selected locale in the serialized hash' do- expect(subject.serializable_hash[:data][:attributes][:selected_locale]).to eq('fr')- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rbdeleted file mode 100644index 6a829e9665..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/variant_serializer_spec.rb+++ /dev/null@@ -1,117 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::VariantSerializer do- subject { described_class.new(variant, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let!(:variant) { create(:variant, price: 10, compare_at_price: 15, images: create_list(:image, 2), tax_category: create(:tax_category)) }- let!(:digital) { create(:digital, variant: variant) }-- it do- expect(subject).to eq(- {- data: {- id: variant.id.to_s,- type: :variant,- attributes: {- sku: variant.sku,- barcode: variant.barcode,- weight: variant.weight,- weight_unit: variant.weight_unit,- height: variant.height,- depth: variant.depth,- dimensions_unit: variant.dimensions_unit,- deleted_at: variant.deleted_at,- is_master: variant.is_master,- cost_price: variant.cost_price,- position: variant.position,- cost_currency: variant.cost_currency,- track_inventory: variant.track_inventory,- updated_at: variant.updated_at,- discontinue_on: variant.discontinue_on,- created_at: variant.created_at,- name: variant.name,- options_text: variant.options_text,- total_on_hand: variant.total_on_hand,- purchasable: variant.purchasable?,- in_stock: variant.in_stock?,- backorderable: variant.backorderable?,- available: variant.available?,- currency: currency,- price: BigDecimal(10),- display_price: '$10.00',- compare_at_price: BigDecimal(15),- display_compare_at_price: '$15.00',- image_count: variant.image_count,- public_metadata: {},- private_metadata: {}- },- relationships: {- product: {- data: {- id: variant.product.id.to_s,- type: :product- }- },- tax_category: {- data: {- id: variant.tax_category.id.to_s,- type: :tax_category- }- },- option_values: {- data: [- {- id: variant.option_values.first.id.to_s,- type: :option_value- }- ]- },- digitals: {- data: [- {- id: variant.digitals.first.id.to_s,- type: :digital- }- ]- },- images: {- data: [- {- id: variant.images.first.id.to_s,- type: :image- },- {- id: variant.images.second.id.to_s,- type: :image- }- ]- },- stock_locations: {- data: [- {- id: variant.stock_locations.first.id.to_s,- type: :stock_location- }- ]- },- stock_items: {- data: [- {- id: variant.stock_items.first.id.to_s,- type: :stock_item- }- ]- },- metafields: {- data: []- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/wished_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/wished_item_serializer_spec.rbdeleted file mode 100644index 7d283d2e61..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/wished_item_serializer_spec.rb+++ /dev/null@@ -1,43 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::WishedItemSerializer do- subject { described_class.new(wished_item, params: serializer_params) }-- include_context 'API v2 serializers params'-- let!(:user) { create(:user) }- let!(:variant) { create(:variant) }- let!(:wishlist) { create(:wishlist, user: user) }- let!(:wished_item) { create(:wished_item, wishlist: wishlist, variant: variant, quantity: 3) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: wished_item.id.to_s,- type: :wished_item,- attributes: {- quantity: 3,- price: variant.price,- total: variant.price * 3,- display_price: '$19.99',- display_total: '$59.97',- created_at: wished_item.created_at,- updated_at: wished_item.updated_at- },- relationships: {- variant: {- data:- {- id: variant.id.to_s,- type: :variant- }- }- }- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/wishlist_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/wishlist_serializer_spec.rbdeleted file mode 100644index 80ff048487..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/wishlist_serializer_spec.rb+++ /dev/null@@ -1,41 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::WishlistSerializer do- subject { described_class.new(wishlist) }-- let!(:user) { create(:user) }- let!(:wishlist) { create(:wishlist, user: user) }- let!(:wished_item) { create(:wished_item, wishlist: wishlist) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: wishlist.id.to_s,- type: :wishlist,- attributes: {- name: wishlist.name,- is_default: false,- is_private: true,- token: wishlist.token,- variant_included: false,- created_at: wishlist.created_at,- updated_at: wishlist.updated_at- },- relationships: {- wished_items: {- data: [- {- id: wishlist.wished_items.first.id.to_s,- type: :wished_item- }- ]- }- }- }- }- )- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_member_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_member_serializer_spec.rbdeleted file mode 100644index 14e185748a..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_member_serializer_spec.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ZoneMemberSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params) }-- let(:resource) { create(:zone_member, zoneable: create(:country)) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rbdeleted file mode 100644index fe0794ec5f..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/platform/zone_serializer_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe Spree::Api::V2::Platform::ZoneSerializer do- include_context 'API v2 serializers params'-- subject { described_class.new(resource, params: serializer_params).serializable_hash }-- let(:resource) { create(:zone) }-- it { expect(subject).to be_kind_of(Hash) }-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/api/v2/resource_serializer_concern_spec.rb b/legacy_api_v2/spec/serializers/spree/api/v2/resource_serializer_concern_spec.rbdeleted file mode 100644index 62ca4a587c..0000000000--- a/legacy_api_v2/spec/serializers/spree/api/v2/resource_serializer_concern_spec.rb+++ /dev/null@@ -1,124 +0,0 @@-require 'spec_helper'--module Spree- TestOrder = Struct.new(:adjustment_total, :id, :item_total, :outstanding_balance, keyword_init: true) do- extend Spree::DisplayMoney-- money_methods :adjustment_total, :item_total, :outstanding_balance-- # Just for testing setter methods aren't added- def display_item_total=- end-- def self.json_api_type- to_s.demodulize.underscore- end-- def self.json_api_columns- %w[created_at updated_at]- end- end-- module Api- module V2- module Platform- class TestOrderSerializer < ::Spree::Api::V2::BaseSerializer- include Spree::Api::V2::ResourceSerializerConcern- end- end- end- end-end--describe Spree::Api::V2::ResourceSerializerConcern do- describe '.included' do- let(:adjustment_total) { 100.0 }- let(:created_at) { 1.day.ago }- let(:id) { 1 }- let(:item_total) { 110.0 }- let(:outstanding_balance) { 10.0 }- let(:serializable_hash) { Spree::Api::V2::Platform::TestOrderSerializer.new(test_order).serializable_hash }- let(:test_order) do- Spree::TestOrder.new(- adjustment_total: adjustment_total,- id: id,- item_total: item_total,- outstanding_balance: outstanding_balance- )- end- let(:updated_at) { Time.now }-- before { allow(test_order).to receive_messages(created_at: created_at, updated_at: updated_at) }-- it do- expect(serializable_hash).to(- eq(- data: {- id: test_order.id.to_s,- type: :test_order,- attributes: {- created_at: created_at,- display_adjustment_total: test_order.display_adjustment_total.to_s,- display_item_total: test_order.display_item_total.to_s,- display_outstanding_balance: test_order.display_outstanding_balance.to_s,- updated_at: updated_at- }- }- )- )- end-- it 'sets the base type' do- expect(serializable_hash[:data][:type]).to eq(:test_order)- end-- it 'adds the model class json_api_columns as attributes' do- expect(serializable_hash[:data][:attributes][:created_at]).to eq(created_at)- expect(serializable_hash[:data][:attributes][:updated_at]).to eq(updated_at)- end-- it 'adds all the display instance methods the class has' do- expect(serializable_hash[:data][:attributes].key?(:display_adjustment_total)).to eq(true)- expect(serializable_hash[:data][:attributes].key?(:display_item_total)).to eq(true)- expect(serializable_hash[:data][:attributes].key?(:display_outstanding_balance)).to eq(true)- end-- it 'converts to string the display money attributes' do- expect(serializable_hash[:data][:attributes][:display_outstanding_balance]).to(- eq(test_order.display_outstanding_balance.to_s)- )- expect(serializable_hash[:data][:attributes][:display_adjustment_total]).to(- eq(test_order.display_adjustment_total.to_s)- )- expect(serializable_hash[:data][:attributes][:display_item_total]).to(- eq(test_order.display_item_total.to_s)- )- end-- it 'does not add display setter methods - ending with "="' do- expect(serializable_hash[:data][:attributes].key?(:display_item_total=)).to eq(false)- end-- context 'when model class is a Spree::Product' do- context 'display_amount method' do- let(:product) { create(:product) }- let(:serializable_hash) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash }-- it 'does not add the display_amount method' do- expect(serializable_hash[:data][:attributes].key?(:display_amount)).to eq(false)- end- end- end-- context 'when model class is a Spree::Variant' do- context 'display_amount method' do- let(:variant) { create(:variant) }- let(:serializable_hash) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash }-- it 'does not add the display_amount method' do- expect(serializable_hash[:data][:attributes].key?(:display_amount)).to eq(false)- end- end- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/cart_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/cart_serializer_spec.rbdeleted file mode 100644index b342e063ce..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/cart_serializer_spec.rb+++ /dev/null@@ -1,27 +0,0 @@-require 'spec_helper'--RSpec.describe Spree::V2::Storefront::CartSerializer do- subject { described_class.new(order).serializable_hash }-- include_context 'API v2 serializers params'-- let!(:order) { build(:order) }-- describe '#promo_total_cents' do- context 'without any promo applied' do- it 'returns 0 promo total' do- expect(subject[:data][:attributes][:promo_total_cents]).to eq(0)- end- end-- context 'with a promo applied' do- before do- order.promo_total = 10- end-- it 'returns the promo total in cents' do- expect(subject[:data][:attributes][:promo_total_cents]).to eq(1000)- end- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/digital_link_serializer.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/digital_link_serializer.rbdeleted file mode 100644index 3ec984edf2..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/digital_link_serializer.rb+++ /dev/null@@ -1,26 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::DigitalLinkSerializer do- subject { described_class.new(digital_link) }-- let(:digital_link) { create(:digital_link) }-- it { expect(subject.serializable_hash).to be_kind_of(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: digital_link.id.to_s,- type: :digital_link,- attributes: {- token: digital_link.token- }- }- }- )- end-- it { expect(subject.serializable_hash[:data][:id]).to be_kind_of(String) }- it { expect(subject.serializable_hash[:data][:type]).to be(:digital_link) }-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/line_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/line_item_serializer_spec.rbdeleted file mode 100644index 75d7c35977..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/line_item_serializer_spec.rb+++ /dev/null@@ -1,52 +0,0 @@-require 'spec_helper'--RSpec.describe Spree::V2::Storefront::LineItemSerializer do- subject { described_class.new(line_item).serializable_hash }-- include_context 'API v2 serializers params'-- let!(:line_item) { build(:line_item) }-- it { expect(subject).to be_kind_of(Hash) }-- describe 'attributes' do- it 'returns expected attributes' do- expect(subject[:data][:attributes]).to include(- name: line_item.name,- quantity: line_item.quantity,- price: line_item.price,- slug: line_item.slug,- options_text: line_item.options_text,- currency: line_item.currency,- display_price: line_item.display_price,- total: line_item.total,- display_total: line_item.display_total,- adjustment_total: line_item.adjustment_total,- display_adjustment_total: line_item.display_adjustment_total,- additional_tax_total: line_item.additional_tax_total,- discounted_amount: line_item.discounted_amount,- display_discounted_amount: line_item.display_discounted_amount,- display_additional_tax_total: line_item.display_additional_tax_total,- promo_total: line_item.promo_total,- display_promo_total: line_item.display_promo_total,- included_tax_total: line_item.included_tax_total,- display_included_tax_total: line_item.display_included_tax_total,- pre_tax_amount: line_item.pre_tax_amount,- display_pre_tax_amount: line_item.display_pre_tax_amount,- compare_at_amount: line_item.compare_at_amount,- display_compare_at_amount: line_item.display_compare_at_amount,- public_metadata: line_item.public_metadata- )- end- end-- describe 'relationships' do- it 'includes variant relationship' do- expect(subject[:data][:relationships]).to have_key(:variant)- end-- it 'includes digital_links relationship' do- expect(subject[:data][:relationships]).to have_key(:digital_links)- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/product_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/product_serializer_spec.rbdeleted file mode 100644index 99ad677ea1..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/product_serializer_spec.rb+++ /dev/null@@ -1,183 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::ProductSerializer do- subject { described_class.new(product, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let(:product) { create(:product, price: 20) }-- context 'with tags' do- before { product.tag_list.add('tag1', 'tag2') }-- it 'returns tags' do- expect(subject[:data][:attributes][:tags]).to eq ['tag1', 'tag2']- end- end-- context 'with labels' do- before { product.label_list.add('label1', 'label2') }-- it 'returns labels' do- expect(subject[:data][:attributes][:labels]).to eq ['label1', 'label2']- end- end-- describe 'pricing attributes' do- it 'returns base price attributes' do- expect(subject[:data][:attributes]).to include(- currency: currency,- price: BigDecimal(20),- display_price: '$20.00'- )- end- end-- describe 'pricing context integration' do- let(:other_store) { create(:store, default: false) }- let(:other_zone) { create(:zone) }- let(:user) { create(:user) }-- context 'with store-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: other_store) }- let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 12.50, price_list: price_list) }-- context 'when store matches' do- let(:serializer_params) do- {- store: other_store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: zone }- }- end-- it 'returns the store-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('12.50'))- expect(subject[:data][:attributes][:display_price]).to eq('$12.50')- end- end-- context 'when store does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(20))- expect(subject[:data][:attributes][:display_price]).to eq('$20.00')- end- end- end-- context 'with zone-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: store) }- let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }- let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 15.00, price_list: price_list) }-- context 'when zone matches' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: other_zone }- }- end-- it 'returns the zone-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('15.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$15.00')- end- end-- context 'when zone does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(20))- expect(subject[:data][:attributes][:display_price]).to eq('$20.00')- end- end- end-- context 'with user-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: store) }- let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }- let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 14.00, price_list: price_list) }-- context 'when user matches' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: user,- locale: locale,- price_options: { tax_zone: zone }- }- end-- it 'returns the user-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('14.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$14.00')- end- end-- context 'when user does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(20))- expect(subject[:data][:attributes][:display_price]).to eq('$20.00')- end- end- end-- context 'with combined rules (zone AND user)' do- let!(:price_list) { create(:price_list, :active, store: store, match_policy: 'all') }- let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }- let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }- let!(:price_list_price) { create(:price, variant: product.master, currency: currency, amount: 9.00, price_list: price_list) }-- context 'when both zone and user match' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: user,- locale: locale,- price_options: { tax_zone: other_zone }- }- end-- it 'returns the combined rule price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('9.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$9.00')- end- end-- context 'when only zone matches' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: other_zone }- }- end-- it 'returns the base price because both rules must match' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(20))- expect(subject[:data][:attributes][:display_price]).to eq('$20.00')- end- end- end-- context 'with multiple price lists' do- let!(:second_position_list) { create(:price_list, :active, store: store, position: 2) }- let!(:first_position_list) { create(:price_list, :active, store: store, position: 1) }- let!(:second_price) { create(:price, variant: product.master, currency: currency, amount: 16.00, price_list: second_position_list) }- let!(:first_price) { create(:price, variant: product.master, currency: currency, amount: 10.00, price_list: first_position_list) }-- it 'returns the first position price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('10.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$10.00')- end- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rbdeleted file mode 100644index 806e4a33c9..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb+++ /dev/null@@ -1,187 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::TaxonSerializer do- subject { described_class.new(taxon, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let(:taxonomy) { create(:taxonomy, store: store) }- let(:taxon) { create(:taxon, :with_description, taxonomy: taxonomy, products: build_list(:product, 2, stores: [store])) }- let!(:children) { create_list(:taxon, 2, taxonomy: taxonomy, parent: taxon) }- let(:url_helpers) { Rails.application.routes.url_helpers }-- let!(:metafield_definition) { create(:metafield_definition, :short_text_field, resource_type: 'Spree::Taxon') }- let!(:metafield) { create(:metafield, metafield_definition: metafield_definition, resource: taxon, value: 'Additional Info') }-- before do- taxon.reload # Reload taxon to ensure all associations are loaded- end-- context 'without products' do- it do- expect(subject).to match(- {- data: {- id: taxon.id.to_s,- type: :taxon,- attributes: {- name: taxon.name,- pretty_name: taxon.pretty_name,- permalink: taxon.permalink,- seo_title: taxon.seo_title,- meta_title: taxon.meta_title,- meta_description: taxon.meta_description,- meta_keywords: taxon.meta_keywords,- left: taxon.left,- right: taxon.right,- position: taxon.position,- depth: taxon.depth,- updated_at: taxon.updated_at,- public_metadata: {},- description: taxon.description.to_plain_text,- has_products: taxon.active_products_with_descendants.exists?,- header_url: nil,- is_root: taxon.root?,- is_child: taxon.child?,- is_leaf: taxon.leaf?,- localized_slugs: taxon.localized_slugs_for_store(store)- },- relationships: {- parent: {- data: {- id: taxon.parent_id.to_s,- type: :taxon- }- },- taxonomy: {- data: {- id: taxonomy.id.to_s,- type: :taxonomy- }- },- children: {- data: [- {- id: taxon.children.first.id.to_s,- type: :taxon- },- {- id: taxon.children.second.id.to_s,- type: :taxon- }- ]- },- image: {- data: nil- },- metafields: {- data: [- {- id: metafield.id.to_s,- type: :metafield- }- ]- }- }- }- }- )- end- end-- context 'with products' do- before do- serializer_params[:include_products] = true- end-- it do- expect(subject).to match(- {- data: {- id: taxon.id.to_s,- type: :taxon,- attributes: {- name: taxon.name,- pretty_name: taxon.pretty_name,- permalink: taxon.permalink,- seo_title: taxon.seo_title,- meta_title: taxon.meta_title,- meta_description: taxon.meta_description,- meta_keywords: taxon.meta_keywords,- left: taxon.left,- right: taxon.right,- position: taxon.position,- depth: taxon.depth,- updated_at: taxon.updated_at,- public_metadata: {},- description: taxon.description.to_plain_text,- has_products: taxon.active_products_with_descendants.exists?,- header_url: nil,- is_root: taxon.root?,- is_child: taxon.child?,- is_leaf: taxon.leaf?,- localized_slugs: taxon.localized_slugs_for_store(store)- },- relationships: {- parent: {- data: {- id: taxon.parent_id.to_s,- type: :taxon- }- },- taxonomy: {- data: {- id: taxonomy.id.to_s,- type: :taxonomy- }- },- children: {- data: contain_exactly(- {- id: taxon.children.first.id.to_s,- type: :taxon- },- {- id: taxon.children.second.id.to_s,- type: :taxon- }- )- },- products: {- data: [- {- id: taxon.products.first.id.to_s,- type: :product- },- {- id: taxon.products.second.id.to_s,- type: :product- }- ]- },- image: {- data: nil- },- metafields: {- data: [- {- id: metafield.id.to_s,- type: :metafield- }- ]- }- }- }- }- )- end- end-- context 'with header image' do- let(:taxon) { create(:taxon, :with_header_image, taxonomy: taxonomy) }-- it do- expect(subject[:data][:attributes][:header_url]).to eq(url_helpers.cdn_image_url(taxon.image.attachment))- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/user_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/user_serializer_spec.rbdeleted file mode 100644index af4e67fa9d..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/user_serializer_spec.rb+++ /dev/null@@ -1,76 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::UserSerializer do- subject { described_class.new(user, params: serializer_params) }-- include_context 'API v2 serializers params'-- let(:user) { create(:user_with_addresses) }-- it { expect(subject.serializable_hash).to be_a(Hash) }-- it do- expect(subject.serializable_hash).to eq(- {- data: {- id: user.id.to_s,- type: :user,- attributes: {- completed_orders: 0,- email: user.email,- first_name: user.first_name,- last_name: user.last_name,- public_metadata: {},- selected_locale: nil,- tags: [],- store_credits: 0- },- relationships: {- default_billing_address: {- data: {- id: user.bill_address.id.to_s,- type: :address- }- },- default_shipping_address: {- data: {- id: user.ship_address.id.to_s,- type: :address- }- }- }- }- }- )- end-- context 'when user has orders' do- before do- create(:completed_order_with_totals, user: user, currency: 'USD')- create(:completed_order_with_totals, user: user, currency: 'EUR')- create(:store_credit, amount: '100', store: store, user: user, currency: 'USD')- create(:store_credit, amount: '90', store: store, user: user, currency: 'EUR')- end-- it do- expect(subject.serializable_hash[:data][:attributes]).to eq({- completed_orders: 2,- email: user.email,- first_name: user.first_name,- last_name: user.last_name,- public_metadata: {},- selected_locale: nil,- store_credits: 0.1e3,- tags: []- })- end- end-- context 'when user has selected non default locale' do- let(:user) { create(:user_with_addresses, selected_locale: 'fr') }-- it 'returns the selected locale in the serialized hash' do- expect(subject.serializable_hash[:data][:attributes][:selected_locale]).to eq('fr')- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/variant_serializer_spec.rbdeleted file mode 100644index 02b80f9faf..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/variant_serializer_spec.rb+++ /dev/null@@ -1,170 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::VariantSerializer do- subject { described_class.new(variant, params: serializer_params).serializable_hash }-- include_context 'API v2 serializers params'-- let!(:variant) { create(:variant, price: 10, compare_at_price: 15) }-- it 'returns expected attributes' do- expect(subject[:data][:attributes]).to include(- sku: variant.sku,- barcode: variant.barcode,- weight: variant.weight,- height: variant.height,- width: variant.width,- depth: variant.depth,- is_master: variant.is_master,- options_text: variant.options_text,- options: variant.options,- public_metadata: variant.public_metadata,- purchasable: variant.purchasable?,- in_stock: variant.in_stock?,- backorderable: variant.backorderable?,- currency: currency,- price: BigDecimal(10),- display_price: '$10.00',- compare_at_price: BigDecimal(15),- display_compare_at_price: '$15.00'- )- end-- it 'returns expected relationships' do- expect(subject[:data][:relationships]).to include(- :product,- :images,- :option_values- )- end-- it 'returns correct type' do- expect(subject[:data][:type]).to eq :variant- end-- describe 'pricing context integration' do- let(:other_store) { create(:store, default: false) }- let(:other_zone) { create(:zone) }- let(:user) { create(:user) }-- context 'with store-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: other_store) }- let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 7.50, price_list: price_list) }-- context 'when store matches' do- let(:serializer_params) do- {- store: other_store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: zone }- }- end-- it 'returns the store-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('7.50'))- expect(subject[:data][:attributes][:display_price]).to eq('$7.50')- end- end-- context 'when store does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(10))- expect(subject[:data][:attributes][:display_price]).to eq('$10.00')- end- end- end-- context 'with zone-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: store) }- let!(:zone_rule) { create(:zone_price_rule, price_list: price_list, zone_ids: [other_zone.id]) }- let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 8.00, price_list: price_list) }-- context 'when zone matches' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: nil,- locale: locale,- price_options: { tax_zone: other_zone }- }- end-- it 'returns the zone-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('8.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$8.00')- end- end-- context 'when zone does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(10))- expect(subject[:data][:attributes][:display_price]).to eq('$10.00')- end- end- end-- context 'with user-specific pricing' do- let!(:price_list) { create(:price_list, :active, store: store) }- let!(:user_rule) { create(:user_price_rule, price_list: price_list, user_ids: [user.id]) }- let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 6.50, price_list: price_list) }-- context 'when user matches' do- let(:serializer_params) do- {- store: store,- currency: currency,- user: user,- locale: locale,- price_options: { tax_zone: zone }- }- end-- it 'returns the user-specific price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('6.50'))- expect(subject[:data][:attributes][:display_price]).to eq('$6.50')- end- end-- context 'when user does not match' do- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(10))- expect(subject[:data][:attributes][:display_price]).to eq('$10.00')- end- end- end-- context 'with multiple price lists' do- let!(:second_position_list) { create(:price_list, :active, store: store, position: 2) }- let!(:first_position_list) { create(:price_list, :active, store: store, position: 1) }- let!(:second_price) { create(:price, variant: variant, currency: currency, amount: 8.00, price_list: second_position_list) }- let!(:first_price) { create(:price, variant: variant, currency: currency, amount: 5.00, price_list: first_position_list) }-- it 'returns the first position price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('5.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$5.00')- end- end-- context 'with date-based pricing' do- let!(:price_list) { create(:price_list, :active, store: store, starts_at: 1.day.ago, ends_at: 1.day.from_now) }- let!(:price_list_price) { create(:price, variant: variant, currency: currency, amount: 7.00, price_list: price_list) }-- it 'returns the date-specific price when within range' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal('7.00'))- expect(subject[:data][:attributes][:display_price]).to eq('$7.00')- end-- context 'when outside date range' do- let!(:price_list) { create(:price_list, :active, store: store, starts_at: 2.days.from_now, ends_at: 3.days.from_now) }-- it 'returns the base price' do- expect(subject[:data][:attributes][:price]).to eq(BigDecimal(10))- expect(subject[:data][:attributes][:display_price]).to eq('$10.00')- end- end- end- end-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rbdeleted file mode 100644index 04e3ad5032..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/wished_item_serializer_spec.rb+++ /dev/null@@ -1,36 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::WishedItemSerializer do- subject { described_class.new(wished_item, params: { currency: 'USD' }).serializable_hash }-- let!(:wishlist) { create(:wishlist) }- let!(:wished_item) { create(:wished_item, wishlist: wishlist, variant: create(:variant), quantity: 5) }-- it do- expect(subject).to eq(- {- data: {- id: wished_item.id.to_s,- type: :wished_item,- attributes: {- display_price: '$19.99',- display_total: '$99.95',- price: wished_item.variant.price,- total: (wished_item.variant.price * 5),- quantity: 5,- },- relationships: {- variant: {- data: {- id: wished_item.variant_id.to_s,- type: :variant- }- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb b/legacy_api_v2/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rbdeleted file mode 100644index 1eb869f49c..0000000000--- a/legacy_api_v2/spec/serializers/spree/v2/storefront/wishlist_serializer_spec.rb+++ /dev/null@@ -1,38 +0,0 @@-require 'spec_helper'--describe Spree::V2::Storefront::WishlistSerializer do- subject { described_class.new(wishlist).serializable_hash }-- let!(:wishlist) { create(:wishlist) }- let!(:wished_item) { create(:wished_item, wishlist: wishlist, variant: create(:variant), quantity: 1) }-- it do- expect(subject).to eq(- {- data: {- id: wishlist.id.to_s,- type: :wishlist,- attributes: {- name: wishlist.name,- token: wishlist.token,- is_private: wishlist.is_private,- is_default: wishlist.is_default,- variant_included: false- },- relationships: {- wished_items: {- data: [- {- id: wishlist.wished_items.first.id.to_s,- type: :wished_item- }- ]- }- }- }- }- )- end-- it_behaves_like 'an ActiveJob serializable hash'-enddiff --git a/legacy_api_v2/spec/spec_helper.rb b/legacy_api_v2/spec/spec_helper.rbdeleted file mode 100644index 5b740d0b6b..0000000000--- a/legacy_api_v2/spec/spec_helper.rb+++ /dev/null@@ -1,109 +0,0 @@-if ENV['COVERAGE']- # Run Coverage report- require 'simplecov'- SimpleCov.start 'rails' do- add_group 'Serializers', 'app/serializers'- add_group 'Libraries', 'lib/spree'-- add_filter '/bin/'- add_filter '/db/'- add_filter '/script/'- add_filter '/spec/'- add_filter '/lib/spree/api/testing_support/'-- coverage_dir "#{ENV['COVERAGE_DIR']}/legacy_api_v2_"+ ENV.fetch('CIRCLE_NODE_INDEX', 0) if ENV['COVERAGE_DIR']- command_name "test_" + ENV.fetch('CIRCLE_NODE_INDEX', 0)-- end-end--# This file is copied to spec/ when you run 'rails generate rspec:install'-ENV['RAILS_ENV'] ||= 'test'--begin- require File.expand_path('../dummy/config/environment', __FILE__)-rescue LoadError- puts 'Could not load dummy application. Please ensure you have run `bundle exec rake test_app`'- exit-end--require 'rspec/rails'-require 'database_cleaner/active_record'-require 'ffaker'-require 'webmock/rspec'-require 'i18n/tasks'-require 'jsonapi/rspec'--# Requires supporting ruby files with custom matchers and macros, etc,-# in spec/support/ and its subdirectories.-Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }--require 'spree/testing_support/factories'-require 'spree/testing_support/jobs'-require 'spree/testing_support/store'-require 'spree/testing_support/preferences'-require 'spree/testing_support/image_helpers'-require 'spree/testing_support/next_instance_of'-require 'spree/testing_support/rspec_retry_config'--require 'spree/legacy_api_v2/testing_support/v2/base'-require 'spree/legacy_api_v2/testing_support/v2/current_order'-require 'spree/legacy_api_v2/testing_support/v2/platform_contexts'-require 'spree/legacy_api_v2/testing_support/v2/serializers_params'-require 'spree/legacy_api_v2/testing_support/serializers'-require 'spree/legacy_api_v2/testing_support/factories'--def json_response- case body = JSON.parse(response.body)- when Hash- body.with_indifferent_access- when Array- body- end-end--RSpec.configure do |config|- config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]- config.color = true- config.default_formatter = 'doc'- config.fail_fast = ENV['FAIL_FAST'] || false- config.infer_spec_type_from_file_location!- config.raise_errors_for_deprecations!- config.use_transactional_fixtures = true-- config.include JSONAPI::RSpec- config.include FactoryBot::Syntax::Methods- config.include Spree::TestingSupport::Preferences- config.include Spree::TestingSupport::ImageHelpers-- config.before(:suite) do- Spree::Events.disable!- # Clean out the database state before the tests run- DatabaseCleaner.strategy = :transaction- DatabaseCleaner.clean_with(:truncation)- end-- # Re-enable events for specs that need them- config.around(:each, events: true) do |example|- Spree::Events.enable { example.run }- end-- config.before do- reset_spree_preferences-- # Request specs to paths with ?locale=xx don't reset the locale afterwards- # Some tests assume that the current locale is :en, so we ensure it here- I18n.locale = :en-- # Reset Spree::Current to avoid stale memoized values between tests- Spree::Current.reset- end-- config.around(:each) do |example|- DatabaseCleaner.cleaning do- example.run- end- end-- config.order = :random-enddiff --git a/legacy_api_v2/spec/support/controller_hacks.rb b/legacy_api_v2/spec/support/controller_hacks.rbdeleted file mode 100644index 482114a053..0000000000--- a/legacy_api_v2/spec/support/controller_hacks.rb+++ /dev/null@@ -1,40 +0,0 @@-require 'active_support/all'-module ControllerHacks- extend ActiveSupport::Concern-- included do- routes { Spree::Core::Engine.routes }- end-- def api_get(action, params = {}, session = nil, flash = nil)- api_process(action, params, session, flash, 'GET')- end-- def api_post(action, params = {}, session = nil, flash = nil)- api_process(action, params, session, flash, 'POST')- end-- def api_put(action, params = {}, session = nil, flash = nil)- api_process(action, params, session, flash, 'PUT')- end-- def api_delete(action, params = {}, session = nil, flash = nil)- api_process(action, params, session, flash, 'DELETE')- end-- def api_process(action, params = {}, session = nil, flash = nil, method = 'get')- scoping = respond_to?(:resource_scoping) ? resource_scoping : {}- process(- action,- method: method,- params: params.merge(scoping),- session: session,- flash: flash,- format: :json- )- end-end--RSpec.configure do |config|- config.include ControllerHacks, type: :controller-enddiff --git a/legacy_api_v2/spec/support/have_attributes_matcher.rb b/legacy_api_v2/spec/support/have_attributes_matcher.rbdeleted file mode 100644index b2ca174c45..0000000000--- a/legacy_api_v2/spec/support/have_attributes_matcher.rb+++ /dev/null@@ -1,8 +0,0 @@-RSpec::Matchers.define :have_attributes do |expected_attributes|- match do |actual|- # actual is a Hash object representing an object, like this:- # { "name" => "Product #1" }- actual_attributes = actual.keys.map(&:to_sym)- expected_attributes.map(&:to_sym).all? { |attr| actual_attributes.include?(attr) }- end-enddiff --git a/legacy_api_v2/spree_legacy_api_v2.gemspec b/legacy_api_v2/spree_legacy_api_v2.gemspecdeleted file mode 100644index 162319eaa6..0000000000--- a/legacy_api_v2/spree_legacy_api_v2.gemspec+++ /dev/null@@ -1,33 +0,0 @@-require_relative '../core/lib/spree/core/version'--Gem::Specification.new do |s|- s.name = 'spree_legacy_api_v2'- s.version = Spree.version- s.authors = ['Ryan Bigg', 'Spark Solutions Sp. z o.o.', 'Vendo Connect Inc.']- s.email = ['[email protected]']- s.summary = %q{Spree's Legacy API v2}- s.description = %q{Legacy API v2 endpoints for Spree Commerce.}- s.homepage = 'https://spreecommerce.org'- s.licenses = ['AGPL-3.0-or-later', 'BSD-3-Clause']-- s.metadata = {- 'bug_tracker_uri' => 'https://github.com/spree/spree/issues',- 'changelog_uri' => "https://github.com/spree/spree/releases/tag/v#{s.version}",- 'documentation_uri' => 'https://docs.spreecommerce.org/',- 'source_code_uri' => "https://github.com/spree/spree/tree/v#{s.version}",- }-- s.required_ruby_version = '>= 3.2'-- s.files = Dir["{app,config,db,lib,vendor}/**/*", "LICENSE.md", "Rakefile", "README.md"].reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }- s.require_paths = ['lib']-- s.add_development_dependency 'jsonapi-rspec'- s.add_development_dependency 'multi_json'-- s.add_dependency 'doorkeeper', '~> 5.3'- s.add_dependency 'jsonapi-serializer', '~> 2.1'- s.add_dependency 'pagy', '~> 43.0'-- s.add_dependency 'spree', s.version-end