2023-09-02 08:35:10 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe PlanetExpressExpress do
|
2024-08-25 10:09:43 +02:00
|
|
|
it "calculates the shipment discounts and formats them properly" do
|
|
|
|
input_file = File.open(
|
|
|
|
File.expand_path("../fixtures/input.txt", __FILE__),
|
|
|
|
"r"
|
|
|
|
)
|
|
|
|
|
|
|
|
output = StringIO.new
|
|
|
|
|
2024-12-11 18:06:04 +01:00
|
|
|
PlanetExpressExpress::ShipmentReader.new(PlanetExpressExpress::PRICE_LIST).read_shipments(input_file) do |shipments|
|
|
|
|
PlanetExpressExpress::Rules.new(PlanetExpressExpress::PRICE_LIST).apply_rules(shipments)
|
|
|
|
PlanetExpressExpress::DiscountBudget.new(PlanetExpressExpress::DISCOUNT_LIMIT).limit_discounts(shipments)
|
|
|
|
PlanetExpressExpress::Formatter.new(output).format(shipments)
|
|
|
|
end
|
2024-08-25 10:09:43 +02:00
|
|
|
|
|
|
|
expected_output = File.read(
|
2024-08-25 10:11:51 +02:00
|
|
|
File.expand_path("../fixtures/output.txt", __FILE__)
|
2024-08-25 10:09:43 +02:00
|
|
|
)
|
2023-09-02 08:35:10 +02:00
|
|
|
|
2024-08-25 10:09:43 +02:00
|
|
|
output.rewind
|
|
|
|
expect(output.read).to match(expected_output)
|
2023-09-02 08:35:10 +02:00
|
|
|
end
|
|
|
|
end
|