Skip to content

Commit

Permalink
don't include empty tracks in slack summary
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdel committed May 4, 2024
1 parent 6b9bedb commit 7d93787
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pears/slack/messages/daily_pears_message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Pears.Slack.Messages.DailyPairsMessage do
summary_lines =
team.tracks
|> Map.values()
|> Enum.filter(fn track -> map_size(track.pears) > 0 end)
|> Enum.map(&build_daily_pears_summary_line/1)
|> Enum.join("\n")
|> String.trim_trailing()
Expand Down
78 changes: 78 additions & 0 deletions test/pears/slack/messages/daily_pears_message_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
defmodule Pears.Slack.Messages.DailyPairsMessageTest do
use ExUnit.Case, async: true

alias Pears.Core.Team
alias Pears.Slack.Messages.DailyPairsMessage

setup [:team]

describe "new/1" do
test "returns a message with a list of pairs", %{team: team} do
team =
team
|> Team.add_track("track1")
|> Team.add_pear("pear1")
|> Team.add_pear("pear2")
|> Team.add_pear_to_track("pear1", "track1")
|> Team.add_pear_to_track("pear2", "track1")
|> Team.add_track("track2")
|> Team.add_pear("pear3")
|> Team.add_pear("pear4")
|> Team.add_pear_to_track("pear3", "track2")
|> Team.add_pear_to_track("pear4", "track2")

{:ok, message} = DailyPairsMessage.new(team)

assert lines(message) == [
"Today's 🍐s are:",
"- pear1 & pear2 on track1",
"- pear3 & pear4 on track2"
]
end

test "does not include empty tracks", %{team: team} do
team =
team
|> Team.add_track("track1")
|> Team.add_pear("pear1")
|> Team.add_pear("pear2")
|> Team.add_pear_to_track("pear1", "track1")
|> Team.add_pear_to_track("pear2", "track1")
|> Team.add_track("track2")

{:ok, message} = DailyPairsMessage.new(team)

assert lines(message) == [
"Today's 🍐s are:",
"- pear1 & pear2 on track1"
]
end

test "does not include available pears", %{team: team} do
team =
team
|> Team.add_track("track1")
|> Team.add_pear("pear1")
|> Team.add_pear("pear2")
|> Team.add_pear_to_track("pear1", "track1")

{:ok, message} = DailyPairsMessage.new(team)

assert lines(message) == [
"Today's 🍐s are:",
"- pear1 on track1"
]
end
end

defp team(_) do
{:ok, team: Team.new(name: "test team")}
end

defp lines(message) do
message
|> String.trim()
|> String.split("\n")
|> Enum.map(&String.trim/1)
end
end

0 comments on commit 7d93787

Please sign in to comment.