From e0abe0d8cd7755e4a1f7d3e79b1ec278b423141b Mon Sep 17 00:00:00 2001 From: Andrew Thal Date: Tue, 20 Jan 2015 11:53:52 -0500 Subject: [PATCH] Add more information to return items --- .../spree/wombat/return_item_serializer.rb | 35 +++++++++++++++- .../wombat/return_item_serializer_spec.rb | 41 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/app/serializers/spree/wombat/return_item_serializer.rb b/app/serializers/spree/wombat/return_item_serializer.rb index 666fb81..786f355 100644 --- a/app/serializers/spree/wombat/return_item_serializer.rb +++ b/app/serializers/spree/wombat/return_item_serializer.rb @@ -5,10 +5,11 @@ module Wombat class ReturnItemSerializer < ActiveModel::Serializer attributes :return_authorization_id, :product_id, :exchange_product_id, :reception_status, :acceptance_status, :pre_tax_amount, :included_tax_total, - :additional_tax_total + :additional_tax_total, :order_number, :created_at, :reimbursed_at, :reimbursed, + :store def product_id - object.inventory_unit.variant.sku + inventory_unit.variant.sku end def exchange_product_id @@ -18,6 +19,36 @@ def exchange_product_id def return_authorization_id object.return_authorization.try(:number) end + + def order_number + order.number + end + + def reimbursed_at + reimbursement.try(:created_at) + end + + def reimbursed + !!reimbursement + end + + def store + order.store.code + end + + private + + def inventory_unit + object.inventory_unit + end + + def reimbursement + object.reimbursement + end + + def order + inventory_unit.order + end end end end diff --git a/spec/serializers/spree/wombat/return_item_serializer_spec.rb b/spec/serializers/spree/wombat/return_item_serializer_spec.rb index 4794edc..6d8d8b3 100644 --- a/spec/serializers/spree/wombat/return_item_serializer_spec.rb +++ b/spec/serializers/spree/wombat/return_item_serializer_spec.rb @@ -47,6 +47,47 @@ module Wombat return_item.additional_tax_total = 5.0.to_d expect(serialized_return_item[:additional_tax_total]).to eq "5.0" end + + it "sets the id" do + return_item.save! + expect(serialized_return_item[:id]).to eq return_item.id + end + + it 'sets the order number' do + return_item.save! + expect(serialized_return_item[:order_number]).to eq return_item.inventory_unit.order.number + end + + it 'sets the created_at' do + return_item.save! + expect(serialized_return_item[:created_at]).to eq return_item.created_at.as_json + end + + context 'is reimbursed' do + it 'sets reimbursed to true' do + return_item.build_reimbursement + expect(serialized_return_item[:reimbursed]).to eq true + end + + it 'sets reimbursed_at' do + return_item.create_reimbursement + expect(serialized_return_item[:reimbursed_at]).to eq return_item.reimbursement.created_at.as_json + end + end + + context 'is not reimbursed' do + it 'sets reimbursed to false' do + expect(serialized_return_item[:reimbursed]).to eq false + end + + it 'does not set reimbursed_at' do + expect(serialized_return_item[:reimbursed_at]).to eq nil + end + end + + it "sets the order's store as the store code" do + expect(serialized_return_item[:store]).to eq return_item.inventory_unit.order.store.code + end end end end