Created
May 10, 2022 16:05
-
-
Save searls/f0ab6592ca04e50a23fc41441e7556d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "date" | |
require "mocktail" | |
require "minitest/autorun" | |
class FetchesOrdersAndItems | |
Result = Struct.new(:orders, :items, keyword_init: true) | |
def fetch(start_date, end_date) | |
end | |
end | |
class SummarizesSalesPerformance | |
def summarize(orders:, items:) | |
end | |
end | |
class BuildsReportRows | |
def build(summary) | |
end | |
end | |
class RendersReport | |
def render(rows) | |
end | |
end | |
class RunsSalesReport | |
def initialize | |
@fetches_orders_and_items = FetchesOrdersAndItems.new | |
@summarizes_sales_performance = SummarizesSalesPerformance.new | |
@builds_report_rows = BuildsReportRows.new | |
@renders_report = RendersReport.new | |
end | |
def run(start_date, end_date) | |
orders_and_items = @fetches_orders_and_items.fetch(start_date, end_date) | |
summary = @summarizes_sales_performance.summarize( | |
orders: orders_and_items.orders, | |
items: orders_and_items.items, | |
) | |
rows = @builds_report_rows.build(summary) | |
@renders_report.render(rows) | |
end | |
end | |
class RunsSalesReportTest < Minitest::Test | |
include Mocktail::DSL | |
def setup | |
@fetches_orders_and_items = Mocktail.of_next(FetchesOrdersAndItems) | |
@summarizes_sales_performance = Mocktail.of_next(SummarizesSalesPerformance) | |
@builds_report_rows = Mocktail.of_next(BuildsReportRows) | |
@renders_report = Mocktail.of_next(RendersReport) | |
@subject = RunsSalesReport.new | |
end | |
def test_sales_report_summary | |
stubs { @fetches_orders_and_items.fetch(Date.civil(2020,1,1), Date.civil(2020,1,31)) }.with { | |
FetchesOrdersAndItems::Result.new(orders: [:an_order], items: [:an_item]) | |
} | |
stubs { @summarizes_sales_performance.summarize(orders: [:an_order], items: [:an_item]) }.with { :some_summary } | |
stubs { @builds_report_rows.build(:some_summary) }.with { [:a_row] } | |
@subject.run(Date.civil(2020,1,1), Date.civil(2020,1,31)) | |
verify { @renders_report.render([:a_row]) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment