require 'spec_helper'
describe MWS::API::Feeds::Envelope, 'built xml' do
subject { described_class.new(params) }
context 'when passed message param' do
let(:params) do
{ feed_type: '_POST_INVENTORY_AVAILABILITY_DATA_',
message_type: :inventory,
message: {
'MessageID' => '123123123',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'ANY-SKU',
'Quantity' => '50'
} } }
end
it 'should contain passed data' do
expect(subject.to_s).to include("Inventoryfalse\n 123123123\n Update\n \n ANY-SKU\n 50\n \n")
end
it 'should be valid' do
expect(subject).to be_valid
end
end
context 'when passed \'messages\' param' do
let(:params) do
{ feed_type: '_POST_INVENTORY_AVAILABILITY_DATA_',
message_type: :inventory,
messages: [
{
'MessageID' => '123123123',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'ANY-SKU',
'Quantity' => '50'
}
},
{ 'MessageID' => '321321321',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'ANY-OTHER-SKU',
'Quantity' => '10'
}
}] }
end
it 'should contain passed data of each message' do
expect(subject.to_s).to include("Inventoryfalse\n 123123123\n Update\n \n ANY-SKU\n 50\n \n")
expect(subject.to_s).to include("\n 321321321\n Update\n \n ANY-OTHER-SKU\n 10\n \n")
end
it 'should be valid' do
expect(subject).to be_valid
end
end
context 'when passed \'message\' and \'messages\'' do
let(:multiple_messages) do
{ messages: [
{
'MessageID' => '123123123',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'ANY-SKU',
'Quantity' => '50'
}
},
{ 'MessageID' => '321321321',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'ANY-OTHER-SKU',
'Quantity' => '10'
}
}] }
end
let(:single_message) do
{ message: {
'MessageID' => '987654321',
'OperationType' => 'Update',
'Inventory' => {
'SKU' => 'SINGLE-SKU',
'Quantity' => '20'
} } }
end
let(:params) do
{ feed_type: '_POST_INVENTORY_AVAILABILITY_DATA_',
message_type: :inventory }.merge(multiple_messages).merge(single_message)
end
it 'should contain info from all of these keys' do
expect(subject.to_s).to include("\n 123123123\n Update\n \n ANY-SKU\n 50\n \n")
expect(subject.to_s).to include("\n 321321321\n Update\n \n ANY-OTHER-SKU\n 10\n \n")
expect(subject.to_s).to include("\n 987654321\n Update\n \n SINGLE-SKU\n 20\n \n")
end
end
end