Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Add more information to return items
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Thal authored and Jeff Dutil committed Jan 20, 2015
1 parent 9339e40 commit e0abe0d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
35 changes: 33 additions & 2 deletions app/serializers/spree/wombat/return_item_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
41 changes: 41 additions & 0 deletions spec/serializers/spree/wombat/return_item_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0abe0d

Please sign in to comment.