Ensure price estimates generated for subscriptions take overrides into account

This commit is contained in:
Rob Harrington
2018-02-21 14:36:26 +11:00
parent add9c83812
commit ae1c8344d1
2 changed files with 22 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ module Admin
@subscription_line_item.assign_attributes(params[:subscription_line_item])
fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(@shop, @order_cycle) if @order_cycle
OpenFoodNetwork::ScopeVariantToHub.new(@shop).scope(@variant)
@subscription_line_item.variant = @variant # Ensures override price is used
render json: @subscription_line_item, serializer: Api::Admin::SubscriptionLineItemSerializer, fee_calculator: fee_calculator
end

View File

@@ -81,13 +81,28 @@ describe Admin::SubscriptionLineItemsController, type: :controller do
context "and a managed schedule_id is provided" do
before { params.merge!(schedule_id: schedule.id) }
it "returns a serialized subscription line item with a price estimate" do
spree_post :build, params
context "where no relevant variant override exists" do
it "returns a serialized subscription line item with a price estimate, based on the variant" do
spree_post :build, params
json_response = JSON.parse(response.body)
expect(json_response['price_estimate']).to eq 18.5
expect(json_response['quantity']).to eq 2
expect(json_response['description']).to eq "#{variant.product.name} - 100g"
json_response = JSON.parse(response.body)
expect(json_response['price_estimate']).to eq 18.5
expect(json_response['quantity']).to eq 2
expect(json_response['description']).to eq "#{variant.product.name} - 100g"
end
end
context "where a relevant variant override exists" do
let!(:override) { create(:variant_override, hub_id: shop.id, variant_id: variant.id, price: 12.00) }
it "returns a serialized subscription line item with a price estimate, based on the override" do
spree_post :build, params
json_response = JSON.parse(response.body)
expect(json_response['price_estimate']).to eq 15.5
expect(json_response['quantity']).to eq 2
expect(json_response['description']).to eq "#{variant.product.name} - 100g"
end
end
end
end