require 'spec_helper'
module Peddler
module Feeds
module OrderFulfillment
describe Batch do
let(:transport) do
transport = Peddler::Transport.new
transport.modernize_request
transport
end
let(:feed) { Peddler::Feeds::OrderFulfillment::Batch.new(transport) }
let(:fulfilled_order) do
Peddler::Feeds::OrderFulfillment::Item.new(
:order_id => '123-1234567-1234567',
:ship_date => Date.parse('2009-08-11').to_s
)
end
it 'adds items to batch' do
feed.batch.size.should == 0
feed << fulfilled_order
feed.batch.size.should == 1
end
it 'creates content for upload' do
feed << fulfilled_order
feed.file_content.should == "order-id\torder-item-id\tquantity\tship-date\tcarrier-code\tcarrier-name\ttracking-number\tship-method\r\n123-1234567-1234567\t\t\t2009-08-11\t\t\t\t\r\n"
end
it 'uploads' do
feed.id.should == nil
transport.stub!(:execute_request).and_return(' 130895733_POST_FLAT_FILE_FULFILLMENT_DATA__SUBMITTED_2007-04-05T00:34:00+0000')
feed.upload
feed.id.should == '130895733'
feed.status.should == '_SUBMITTED_'
end
it 'refreshes status' do
transport.stub!(:execute_request).and_return(' 130895733_POST_FLAT_FILE_FULFILLMENT_DATA__SUBMITTED_2007-04-05T00:34:00+0000')
feed.upload
transport.stub!(:execute_request).and_return('130895733_POST_FLAT_FILE_FULFILLMENT_DATA__IN_PROGRESS_2007-04-05T00:34:00+00002007-04-05T00:39:00+0000')
feed.status.should == '_SUBMITTED_'
feed.status!.should == '_IN_PROGRESS_'
transport.stub!(:execute_request).and_return('130895733_POST_FLAT_FILE_FULFILLMENT_DATA__DONE_2007-04-05T00:34:00+00002007-04-05T00:39:00+00002007-04-05T01:02:00+000022003404021FeedSummaryReport43072858442009-04-24T23:47:24+00:00FALSE')
feed.status!.should == '_DONE_'
feed.download.id.should == '3404021'
feed.download.available_at.should == '2009-04-24T23:47:24+00:00'
end
end
end
module OrderCancellation
describe Batch do
let(:transport) do
transport = Peddler::Transport.new
transport.modernize_request
transport
end
let(:feed) { Peddler::Feeds::OrderCancellation::Batch.new(transport) }
let(:cancelled_order) { Peddler::Feeds::OrderCancellation::Item.new(:order_id => '123-1234567-1234567') }
it 'adds items to batch' do
feed.batch.size.should == 0
feed << cancelled_order
feed.batch.size.should == 1
end
it 'creates content for upload' do
feed << cancelled_order
feed.file_content.should == "TemplateType=OrderCancellation Version=1.0/1.0.3 This row for Amazon.com use only. Do not modify or delete.\r\norder-id\tcancellation-reason-code\tamazon-order-item-code\r\n123-1234567-1234567\t\t\r\n"
end
it 'raises error if cancellation reason code is given but Amazon order item code is missing' do
cancelled_order.cancellation_reason_code = 'BuyerCanceled'
lambda { cancelled_order.to_s }.should raise_error(PeddlerError)
end
it 'raises error if Amazon order item code is given but cancellation reason code is missing' do
cancelled_order.amazon_order_item_code = '111111111111'
lambda { cancelled_order.to_s }.should raise_error(PeddlerError)
end
end
end
end
end