Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed using prefixed IDs in Store API

Damian Legawieca5971cadbdb9
diff --git a/api/app/controllers/spree/api/v3/store/addresses_controller.rb b/api/app/controllers/spree/api/v3/store/addresses_controller.rb
index 03227a2dc3..17397a5deb 100644
--- a/api/app/controllers/spree/api/v3/store/addresses_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/addresses_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class AddressesController < Store::ResourceController
+ class AddressesController < ResourceController
prepend_before_action :require_authentication!
# POST /api/v3/store/customers/me/addresses
diff --git a/api/app/controllers/spree/api/v3/store/credit_cards_controller.rb b/api/app/controllers/spree/api/v3/store/credit_cards_controller.rb
index 4700243e47..7da2f0da8a 100644
--- a/api/app/controllers/spree/api/v3/store/credit_cards_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/credit_cards_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class CreditCardsController < Store::ResourceController
+ class CreditCardsController < ResourceController
prepend_before_action :require_authentication!
protected
diff --git a/api/app/controllers/spree/api/v3/store/digitals_controller.rb b/api/app/controllers/spree/api/v3/store/digitals_controller.rb
index bf2d480740..f2b37dbccd 100644
--- a/api/app/controllers/spree/api/v3/store/digitals_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/digitals_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class DigitalsController < Store::ResourceController
+ class DigitalsController < ResourceController
# GET /api/v3/store/digitals/:id?token=...
def show
if @resource.authorize!
diff --git a/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb b/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
index 937bfadbc4..f40ba2ef5b 100644
--- a/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
@@ -3,7 +3,7 @@ module Spree
module V3
module Store
module Orders
- class LineItemsController < Store::ResourceController
+ class LineItemsController < ResourceController
include Spree::Api::V3::OrderConcern
skip_before_action :set_resource
@@ -70,15 +70,7 @@ module Spree
end
def variant
- variants = current_store.variants.accessible_by(current_ability)
- variant_id = permitted_params[:variant_id]
-
- # Support both prefix_id (variant_xxx) and database ID
- if variant_id.to_s.start_with?('variant_')
- variants.find_by!(prefix_id: variant_id)
- else
- variants.find(variant_id)
- end
+ @variant ||= current_store.variants.accessible_by(current_ability).find_by!(prefix_id: permitted_params[:variant_id])
end
def model_class
diff --git a/api/app/controllers/spree/api/v3/store/orders/promotions_controller.rb b/api/app/controllers/spree/api/v3/store/orders/promotions_controller.rb
index b1b14caa5c..dc8059d73e 100644
--- a/api/app/controllers/spree/api/v3/store/orders/promotions_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders/promotions_controller.rb
@@ -3,7 +3,7 @@ module Spree
module V3
module Store
module Orders
- class PromotionsController < Store::ResourceController
+ class PromotionsController < ResourceController
include Spree::Api::V3::OrderConcern
before_action :authorize_order_access!
@@ -45,7 +45,7 @@ module Spree
end
def promotion_handler
- @promotion_handler ||= Spree::PromotionHandler::Coupon.new(@parent)
+ @promotion_handler ||= Spree.coupon_handler.new(@parent)
end
def permitted_params
diff --git a/api/app/controllers/spree/api/v3/store/orders/shipments_controller.rb b/api/app/controllers/spree/api/v3/store/orders/shipments_controller.rb
index f2f4fe4a13..33f4581883 100644
--- a/api/app/controllers/spree/api/v3/store/orders/shipments_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders/shipments_controller.rb
@@ -3,7 +3,7 @@ module Spree
module V3
module Store
module Orders
- class ShipmentsController < Store::ResourceController
+ class ShipmentsController < ResourceController
include Spree::Api::V3::OrderConcern
before_action :authorize_order_access!
diff --git a/api/app/controllers/spree/api/v3/store/orders/store_credits_controller.rb b/api/app/controllers/spree/api/v3/store/orders/store_credits_controller.rb
index e34adde07d..9dcf6ecc95 100644
--- a/api/app/controllers/spree/api/v3/store/orders/store_credits_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders/store_credits_controller.rb
@@ -12,7 +12,7 @@ module Spree
# POST /api/v3/store/orders/:order_id/store_credits
def create
- result = add_store_credit_service.call(
+ result = Spree.checkout_add_store_credit_service.call(
order: @order,
amount: params[:amount].try(:to_f)
)
@@ -26,7 +26,7 @@ module Spree
# DELETE /api/v3/store/orders/:order_id/store_credits
def destroy
- result = remove_store_credit_service.call(order: @order)
+ result = Spree.checkout_remove_store_credit_service.call(order: @order)
if result.success?
render json: serialize_resource(@order.reload)
@@ -45,14 +45,6 @@ module Spree
def serializer_class
Spree.api.order_serializer
end
-
- def add_store_credit_service
- Spree::Api::Dependencies.storefront_checkout_add_store_credit_service.constantize
- end
-
- def remove_store_credit_service
- Spree::Api::Dependencies.storefront_checkout_remove_store_credit_service.constantize
- end
end
end
end
diff --git a/api/app/controllers/spree/api/v3/store/orders_controller.rb b/api/app/controllers/spree/api/v3/store/orders_controller.rb
index 5e7088ed7e..943c8b5f46 100644
--- a/api/app/controllers/spree/api/v3/store/orders_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class OrdersController < Store::ResourceController
+ class OrdersController < ResourceController
include Spree::Api::V3::OrderConcern
# Skip base controller's set_resource and define our own complete list
@@ -25,7 +25,15 @@ module Spree
# PATCH /api/v3/store/orders/:id
def update
- if @order.update(permitted_params)
+ result = Spree.checkout_update_service.call(
+ order: @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
+ )
+
+ if result.success?
render json: serialize_resource(@order.reload)
else
render_errors(@order.errors)
@@ -34,7 +42,7 @@ module Spree
# PATCH /api/v3/store/orders/:id/next
def next
- result = next_service.call(order: @order)
+ result = Spree.checkout_next_service.call(order: @order)
if result.success?
render json: serialize_resource(@order)
@@ -45,7 +53,7 @@ module Spree
# PATCH /api/v3/store/orders/:id/advance
def advance
- result = advance_service.call(order: @order)
+ result = Spree.checkout_advance_service.call(order: @order)
if result.success?
render json: serialize_resource(@order)
@@ -56,7 +64,7 @@ module Spree
# PATCH /api/v3/store/orders/:id/complete
def complete
- result = complete_service.call(order: @order)
+ result = Spree.checkout_complete_service.call(order: @order)
if result.success?
render json: serialize_resource(@order)
@@ -102,22 +110,6 @@ module Spree
def permitted_params
params.require(:order).permit(Spree::PermittedAttributes.checkout_attributes)
end
-
- def update_service
- Spree::Api::Dependencies.storefront_checkout_update_service.constantize
- end
-
- def next_service
- Spree::Api::Dependencies.storefront_checkout_next_service.constantize
- end
-
- def advance_service
- Spree::Api::Dependencies.storefront_checkout_advance_service.constantize
- end
-
- def complete_service
- Spree::Api::Dependencies.storefront_checkout_complete_service.constantize
- end
end
end
end
diff --git a/api/app/controllers/spree/api/v3/store/payment_sources_controller.rb b/api/app/controllers/spree/api/v3/store/payment_sources_controller.rb
index 0e336a7269..15116cc22e 100644
--- a/api/app/controllers/spree/api/v3/store/payment_sources_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/payment_sources_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class PaymentSourcesController < Store::ResourceController
+ class PaymentSourcesController < ResourceController
prepend_before_action :require_authentication!
protected
diff --git a/api/app/controllers/spree/api/v3/store/products_controller.rb b/api/app/controllers/spree/api/v3/store/products_controller.rb
index 61c4c6346a..a007bf72bf 100644
--- a/api/app/controllers/spree/api/v3/store/products_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/products_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class ProductsController < Store::ResourceController
+ class ProductsController < ResourceController
protected
def model_class
diff --git a/api/app/controllers/spree/api/v3/store/stores_controller.rb b/api/app/controllers/spree/api/v3/store/stores_controller.rb
index c91dae964c..9466df41d0 100644
--- a/api/app/controllers/spree/api/v3/store/stores_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/stores_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class StoresController < Store::ResourceController
+ class StoresController < ResourceController
# Public endpoint - no authentication required
# GET /api/v3/store/store
diff --git a/api/app/controllers/spree/api/v3/store/taxonomies_controller.rb b/api/app/controllers/spree/api/v3/store/taxonomies_controller.rb
index 3b2c914f46..de5f015e40 100644
--- a/api/app/controllers/spree/api/v3/store/taxonomies_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/taxonomies_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class TaxonomiesController < Store::ResourceController
+ class TaxonomiesController < ResourceController
protected
def model_class
diff --git a/api/app/controllers/spree/api/v3/store/taxons_controller.rb b/api/app/controllers/spree/api/v3/store/taxons_controller.rb
index ebfc41c717..f407f849ce 100644
--- a/api/app/controllers/spree/api/v3/store/taxons_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/taxons_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class TaxonsController < Store::ResourceController
+ class TaxonsController < ResourceController
protected
def model_class
diff --git a/api/app/controllers/spree/api/v3/store/wishlist_items_controller.rb b/api/app/controllers/spree/api/v3/store/wishlist_items_controller.rb
index 844a00e6c6..c86e1749cd 100644
--- a/api/app/controllers/spree/api/v3/store/wishlist_items_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/wishlist_items_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class WishlistItemsController < Store::ResourceController
+ class WishlistItemsController < ResourceController
prepend_before_action :require_authentication!
protected
diff --git a/api/app/controllers/spree/api/v3/store/wishlists_controller.rb b/api/app/controllers/spree/api/v3/store/wishlists_controller.rb
index 7a8cbbb9f1..bd6776b6de 100644
--- a/api/app/controllers/spree/api/v3/store/wishlists_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/wishlists_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Store
- class WishlistsController < Store::ResourceController
+ class WishlistsController < ResourceController
prepend_before_action :require_authentication!
# POST /api/v3/store/wishlists
diff --git a/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb
index dc2f2c7206..8ea8f283f2 100644
--- a/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/customers_controller_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe Spree::Api::V3::Store::CustomersController, type: :controller do
get :show, params: { id: 'me' }
expect(response).to have_http_status(:ok)
- expect(json_response['id']).to eq(user.id)
+ expect(json_response['id']).to eq(user.prefix_id)
expect(json_response['email']).to eq(user.email)
end
diff --git a/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
index 806f8fa75b..5eec7536a4 100644
--- a/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
@@ -12,28 +12,29 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
before do
request.headers['X-Spree-Api-Key'] = api_key.token
request.headers['Authorization'] = "Bearer #{jwt_token}"
+ request.headers['x-spree-order-token'] = order.token
end
describe 'POST #create' do
it 'adds a line item to the order' do
expect {
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.id, quantity: 2 } }
+ post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
}.to change(Spree::LineItem, :count).by(1)
expect(response).to have_http_status(:created)
- expect(json_response['variant_id']).to eq(variant.id)
+ expect(json_response['variant_id']).to eq(variant.prefix_id)
expect(json_response['quantity']).to eq(2)
end
it 'defaults quantity to 1' do
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.id } }
+ post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id } }
expect(response).to have_http_status(:created)
expect(json_response['quantity']).to eq(1)
end
it 'updates order totals' do
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.id, quantity: 2 } }
+ post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
expect(order.reload.item_total).to be > 0
end
@@ -45,13 +46,13 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'adds line item with valid order token' do
request.headers['X-Spree-Order-Token'] = guest_order.token
- post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.id, quantity: 1 } }
+ post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:created)
end
it 'returns forbidden without order token' do
- post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.id, quantity: 1 } }
+ post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -71,7 +72,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
context 'error handling' do
it 'returns not found for non-existent order' do
- post :create, params: { order_id: 'invalid', line_item: { variant_id: variant.id, quantity: 1 } }
+ post :create, params: { order_id: 'invalid', line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('order_not_found')
@@ -81,7 +82,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'returns forbidden for other users order' do
other_order = create(:order, store: store)
- post :create, params: { order_id: other_order.number, line_item: { variant_id: variant.id, quantity: 1 } }
+ post :create, params: { order_id: other_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -93,7 +94,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
let!(:line_item) { create(:line_item, order: order, variant: variant, quantity: 1) }
it 'updates line item quantity' do
- patch :update, params: { order_id: order.number, id: line_item.id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: order.number, id: line_item.prefix_id, line_item: { quantity: 5 } }
expect(response).to have_http_status(:ok)
expect(line_item.reload.quantity).to eq(5)
@@ -101,7 +102,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'updates order totals' do
original_total = order.item_total
- patch :update, params: { order_id: order.number, id: line_item.id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: order.number, id: line_item.prefix_id, line_item: { quantity: 5 } }
expect(order.reload.item_total).to be > original_total
end
@@ -119,7 +120,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
other_order = create(:order, store: store)
other_line_item = create(:line_item, order: other_order, variant: variant)
- patch :update, params: { order_id: other_order.number, id: other_line_item.id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: other_order.number, id: other_line_item.prefix_id, line_item: { quantity: 5 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -132,7 +133,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'removes line item from order' do
expect {
- delete :destroy, params: { order_id: order.number, id: line_item.id }
+ delete :destroy, params: { order_id: order.number, id: line_item.prefix_id }
}.to change(Spree::LineItem, :count).by(-1)
expect(response).to have_http_status(:no_content)
@@ -140,7 +141,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'updates order totals' do
order.update_columns(item_total: 100)
- delete :destroy, params: { order_id: order.number, id: line_item.id }
+ delete :destroy, params: { order_id: order.number, id: line_item.prefix_id }
expect(order.reload.item_total).to eq(0)
end
@@ -158,7 +159,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
other_order = create(:order, store: store)
other_line_item = create(:line_item, order: other_order, variant: variant)
- delete :destroy, params: { order_id: other_order.number, id: other_line_item.id }
+ delete :destroy, params: { order_id: other_order.number, id: other_line_item.prefix_id }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
diff --git a/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
index b3465b42f5..a144f45ba9 100644
--- a/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
@@ -113,7 +113,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'returns order with expected attributes' do
get :show, params: { id: order.number }
- expect(json_response['id']).to eq(order.id)
+ expect(json_response['id']).to eq(order.prefix_id)
expect(json_response['number']).to eq(order.number)
end
end
diff --git a/api/spec/controllers/spree/api/v3/store/products_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/products_controller_spec.rb
index 1155e600ea..60dd47d963 100644
--- a/api/spec/controllers/spree/api/v3/store/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/products_controller_spec.rb
@@ -58,7 +58,7 @@ RSpec.describe Spree::Api::V3::Store::ProductsController, type: :controller do
get :index
ids = json_response['data'].map { |p| p['id'] }
- expect(ids).not_to include(other_store_product.id)
+ expect(ids).not_to include(other_store_product.prefix_id)
end
end
diff --git a/api/spec/controllers/spree/api/v3/store/stores_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/stores_controller_spec.rb
index 5b6f54f5e3..f8109e4537 100644
--- a/api/spec/controllers/spree/api/v3/store/stores_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/stores_controller_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Spree::Api::V3::Store::StoresController, type: :controller do
get :current
expect(response).to have_http_status(:ok)
- expect(json_response['id']).to eq(store.id)
+ expect(json_response['id']).to eq(store.prefix_id)
end
it 'returns store attributes' do
diff --git a/api/spec/controllers/spree/api/v3/store/taxonomies_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/taxonomies_controller_spec.rb
index 259940828a..3049788505 100644
--- a/api/spec/controllers/spree/api/v3/store/taxonomies_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/taxonomies_controller_spec.rb
@@ -33,7 +33,7 @@ RSpec.describe Spree::Api::V3::Store::TaxonomiesController, type: :controller do
get :index
ids = json_response['data'].map { |t| t['id'] }
- expect(ids).not_to include(other_store_taxonomy.id)
+ expect(ids).not_to include(other_store_taxonomy.prefix_id)
end
it 'returns pagination metadata' do
@@ -60,14 +60,14 @@ RSpec.describe Spree::Api::V3::Store::TaxonomiesController, type: :controller do
get :show, params: { id: taxonomy.id }
expect(response).to have_http_status(:ok)
- expect(json_response['id']).to eq(taxonomy.id)
+ expect(json_response['id']).to eq(taxonomy.prefix_id)
expect(json_response['name']).to eq(taxonomy.name)
end
it 'returns taxonomy with its attributes' do
get :show, params: { id: taxonomy.id }
- expect(json_response['id']).to eq(taxonomy.id)
+ expect(json_response['id']).to eq(taxonomy.prefix_id)
expect(json_response['name']).to be_present
end
diff --git a/api/spec/controllers/spree/api/v3/store/wishlist_items_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/wishlist_items_controller_spec.rb
index 4ab1120cfd..9412afa464 100644
--- a/api/spec/controllers/spree/api/v3/store/wishlist_items_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/wishlist_items_controller_spec.rb
@@ -21,23 +21,17 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
it 'adds item to wishlist' do
expect {
- post :create, params: { wishlist_id: wishlist.id, wished_item: { variant_id: new_variant.id, quantity: 1 } }
+ post :create, params: { wishlist_id: wishlist.prefix_id, wished_item: { variant_id: new_variant.prefix_id, quantity: 3 } }
}.to change(Spree::WishedItem, :count).by(1)
expect(response).to have_http_status(:created)
- expect(json_response['variant_id']).to eq(new_variant.id)
- end
-
- it 'sets correct quantity' do
- post :create, params: { wishlist_id: wishlist.id, wished_item: { variant_id: new_variant.id, quantity: 3 } }
-
- expect(response).to have_http_status(:created)
+ expect(json_response['variant_id']).to eq(new_variant.prefix_id)
expect(json_response['quantity']).to eq(3)
end
context 'validation errors' do
it 'returns errors for missing variant_id' do
- post :create, params: { wishlist_id: wishlist.id, wished_item: { quantity: 1 } }
+ post :create, params: { wishlist_id: wishlist.prefix_id, wished_item: { quantity: 1 } }
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']['code']).to eq('validation_error')
@@ -45,7 +39,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
end
it 'returns errors for invalid variant_id' do
- post :create, params: { wishlist_id: wishlist.id, wished_item: { variant_id: 0, quantity: 1 } }
+ post :create, params: { wishlist_id: wishlist.prefix_id, wished_item: { variant_id: 0, quantity: 1 } }
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']['code']).to eq('validation_error')
@@ -58,7 +52,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
other_user = create(:user)
other_wishlist = create(:wishlist, user: other_user, store: store)
- post :create, params: { wishlist_id: other_wishlist.id, wished_item: { variant_id: new_variant.id, quantity: 1 } }
+ post :create, params: { wishlist_id: other_wishlist.prefix_id, wished_item: { variant_id: new_variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -66,7 +60,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
end
it 'returns not found for non-existent wishlist' do
- post :create, params: { wishlist_id: 0, wished_item: { variant_id: new_variant.id, quantity: 1 } }
+ post :create, params: { wishlist_id: 0, wished_item: { variant_id: new_variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -77,7 +71,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
before { request.headers['Authorization'] = nil }
it 'returns unauthorized' do
- post :create, params: { wishlist_id: wishlist.id, wished_item: { variant_id: new_variant.id, quantity: 1 } }
+ post :create, params: { wishlist_id: wishlist.prefix_id, wished_item: { variant_id: new_variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']['code']).to eq('authentication_required')
@@ -88,7 +82,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
describe 'PATCH #update' do
it 'updates wished item quantity' do
- patch :update, params: { wishlist_id: wishlist.id, id: wished_item.id, wished_item: { quantity: 5 } }
+ patch :update, params: { wishlist_id: wishlist.prefix_id, id: wished_item.prefix_id, wished_item: { quantity: 5 } }
expect(response).to have_http_status(:ok)
expect(wished_item.reload.quantity).to eq(5)
@@ -96,7 +90,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
context 'validation errors' do
it 'returns errors for invalid quantity' do
- patch :update, params: { wishlist_id: wishlist.id, id: wished_item.id, wished_item: { quantity: 0 } }
+ patch :update, params: { wishlist_id: wishlist.prefix_id, id: wished_item.prefix_id, wished_item: { quantity: 0 } }
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']['code']).to eq('validation_error')
@@ -106,7 +100,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
context 'error handling' do
it 'returns not found for non-existent item' do
- patch :update, params: { wishlist_id: wishlist.id, id: 0, wished_item: { quantity: 5 } }
+ patch :update, params: { wishlist_id: wishlist.prefix_id, id: 0, wished_item: { quantity: 5 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -118,7 +112,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
other_wishlist = create(:wishlist, user: other_user, store: store)
other_item = create(:wished_item, wishlist: other_wishlist, variant: variant)
- patch :update, params: { wishlist_id: other_wishlist.id, id: other_item.id, wished_item: { quantity: 5 } }
+ patch :update, params: { wishlist_id: other_wishlist.prefix_id, id: other_item.prefix_id, wished_item: { quantity: 5 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -129,7 +123,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
describe 'DELETE #destroy' do
it 'removes item from wishlist' do
expect {
- delete :destroy, params: { wishlist_id: wishlist.id, id: wished_item.id }
+ delete :destroy, params: { wishlist_id: wishlist.prefix_id, id: wished_item.prefix_id }
}.to change(Spree::WishedItem, :count).by(-1)
expect(response).to have_http_status(:no_content)
@@ -137,7 +131,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
context 'error handling' do
it 'returns not found for non-existent item' do
- delete :destroy, params: { wishlist_id: wishlist.id, id: 0 }
+ delete :destroy, params: { wishlist_id: wishlist.prefix_id, id: 0 }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -149,7 +143,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistItemsController, type: :controller
other_wishlist = create(:wishlist, user: other_user, store: store)
other_item = create(:wished_item, wishlist: other_wishlist, variant: variant)
- delete :destroy, params: { wishlist_id: other_wishlist.id, id: other_item.id }
+ delete :destroy, params: { wishlist_id: other_wishlist.prefix_id, id: other_item.prefix_id }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
diff --git a/api/spec/controllers/spree/api/v3/store/wishlists_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/wishlists_controller_spec.rb
index 6a0c09a331..5c39705d84 100644
--- a/api/spec/controllers/spree/api/v3/store/wishlists_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/wishlists_controller_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
expect(response).to have_http_status(:ok)
expect(json_response['data'].size).to eq(1)
- expect(json_response['data'].first['id']).to eq(wishlist.id)
+ expect(json_response['data'].first['id']).to eq(wishlist.prefix_id)
end
it 'does not return other users wishlists' do
@@ -28,7 +28,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
get :index
ids = json_response['data'].map { |w| w['id'] }
- expect(ids).not_to include(other_wishlist.id)
+ expect(ids).not_to include(other_wishlist.prefix_id)
end
it 'returns pagination metadata' do
@@ -52,10 +52,10 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
describe 'GET #show' do
it 'returns the wishlist' do
- get :show, params: { id: wishlist.id }
+ get :show, params: { id: wishlist.prefix_id }
expect(response).to have_http_status(:ok)
- expect(json_response['id']).to eq(wishlist.id)
+ expect(json_response['id']).to eq(wishlist.prefix_id)
expect(json_response['name']).to eq(wishlist.name)
end
@@ -72,7 +72,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
other_user = create(:user)
other_wishlist = create(:wishlist, user: other_user, store: store)
- get :show, params: { id: other_wishlist.id }
+ get :show, params: { id: other_wishlist.prefix_id }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -127,7 +127,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
describe 'PATCH #update' do
it 'updates the wishlist name' do
- patch :update, params: { id: wishlist.id, wishlist: { name: 'Updated Name' } }
+ patch :update, params: { id: wishlist.prefix_id, wishlist: { name: 'Updated Name' } }
expect(response).to have_http_status(:ok)
expect(wishlist.reload.name).to eq('Updated Name')
@@ -135,7 +135,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
context 'validation errors' do
it 'returns errors for blank name' do
- patch :update, params: { id: wishlist.id, wishlist: { name: '' } }
+ patch :update, params: { id: wishlist.prefix_id, wishlist: { name: '' } }
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']['code']).to eq('validation_error')
@@ -148,7 +148,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
other_user = create(:user)
other_wishlist = create(:wishlist, user: other_user, store: store)
- patch :update, params: { id: other_wishlist.id, wishlist: { name: 'Hacked' } }
+ patch :update, params: { id: other_wishlist.prefix_id, wishlist: { name: 'Hacked' } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')
@@ -159,7 +159,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
describe 'DELETE #destroy' do
it 'deletes the wishlist' do
expect {
- delete :destroy, params: { id: wishlist.id }
+ delete :destroy, params: { id: wishlist.prefix_id }
}.to change(Spree::Wishlist, :count).by(-1)
expect(response).to have_http_status(:no_content)
@@ -178,7 +178,7 @@ RSpec.describe Spree::Api::V3::Store::WishlistsController, type: :controller do
other_user = create(:user)
other_wishlist = create(:wishlist, user: other_user, store: store)
- delete :destroy, params: { id: other_wishlist.id }
+ delete :destroy, params: { id: other_wishlist.prefix_id }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('record_not_found')