mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
In current_order_serializer, serialize shipping_method_id from order.shipping_method.id. Adapted respective spec.
This commit is contained in:
@@ -12,6 +12,10 @@ class Api::CurrentOrderSerializer < ActiveModel::Serializer
|
||||
object.payments.first.andand.payment_method_id
|
||||
end
|
||||
|
||||
def shipping_method_id
|
||||
object.shipping_method.andand.id
|
||||
end
|
||||
|
||||
def display_total
|
||||
object.display_total.money.to_f
|
||||
end
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::CurrentOrderSerializer do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:li) { create(:line_item, variant: create(:variant)) }
|
||||
let(:order) { create(:order, line_items: [li]) }
|
||||
let(:serializer) { Api::CurrentOrderSerializer.new(order, current_distributor: distributor, current_order_cycle: oc ).to_json }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
let(:line_item) { create(:line_item, variant: create(:variant)) }
|
||||
let(:order) { create(:order, line_items: [line_item]) }
|
||||
let(:serializer) { Api::CurrentOrderSerializer.new(order, current_distributor: distributor, current_order_cycle: order_cycle).to_json }
|
||||
|
||||
it "serializers the current order" do
|
||||
serializer.should match order.id.to_s
|
||||
expect(serializer).to match order.id.to_s
|
||||
end
|
||||
|
||||
it "includes line items" do
|
||||
serializer.should match li.id.to_s
|
||||
expect(serializer).to match line_item.id.to_s
|
||||
end
|
||||
|
||||
it "includes variants of line items" do
|
||||
serializer.should match li.variant.name
|
||||
expect(serializer).to match line_item.variant.name
|
||||
end
|
||||
|
||||
context 'when there is no shipment' do
|
||||
it 'includes the shipping method of the order' do
|
||||
expect(serializer).to match('\"shipping_method_id\":null')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is a shipment' do
|
||||
before { create(:shipment, order: order) }
|
||||
|
||||
it 'includes the shipping method of the order' do
|
||||
expect(serializer).to match("\"shipping_method_id\":#{order.shipping_method.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user