1
0
planet_express/spec/shipment_reader_spec.rb
Tim Kächele 66886e6ae6 Implement shipment reader
- Add shipment object
- Add object to represent invalid shipments
- Implement reader for the csv input format
2021-03-05 21:43:44 +01:00

46 lines
1.4 KiB
Ruby

# frozen_string_literal: true
RSpec.describe PlanetExpress::ShipmentReader do
let(:shipping_option_repsitory) { PlanetExpress::ShippingOptionRepository.new }
let(:input) { '' }
subject { PlanetExpress::ShipmentReader.new(input, shipping_option_repsitory) }
describe '#each' do
context 'with a file' do
let(:input) { File.read(File.expand_path('../fixtures/shipment_input_file.txt', __FILE__)) }
let(:result) { subject.to_a }
it 'parses the file' do
expect(result.length).to eq(21)
expect(result.select { |item| item.instance_of?(PlanetExpress::Shipment) }.length).to eq(20)
expect(result.select { |item| item.instance_of?(PlanetExpress::InvalidShipment) }.length).to eq(1)
end
end
context 'with valid shipment' do
let(:input) { '2015-02-01 S MR' }
let(:result) { subject.to_a }
let(:shipment) { result.first }
it 'returns a parsed shipment' do
expect(shipment.date).to eq(Date.new(2015, 2, 1))
expect(shipment.shipping_option).to eq(PlanetExpress::ShippingOption.new('MR', 'S', 200))
end
end
context 'with an invalid shipment' do
let(:input) { '2015-02-29 CUSPS' }
let(:result) { subject.to_a }
let(:shipment) { result.first }
it 'returns an invalid shipment' do
expect(shipment).to be_an_instance_of(PlanetExpress::InvalidShipment)
end
end
end
end