Skip to content

Commit 25e16c0

Browse files
authored
Add RedCardsSpec (#1769)
1 parent fecb62b commit 25e16c0

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.gu.mobile.notifications.football.models
2+
3+
import org.specs2.mutable.Specification
4+
import org.specs2.specification.Scope
5+
import pa.{MatchDayTeam, Player}
6+
7+
class RedCardsSpec extends Specification {
8+
9+
"RedCards.fromDismissals" should {
10+
11+
"return zero red cards for both teams when there are no dismissals" in new RedCardsScope {
12+
val result = RedCards.fromDismissals(home, away, List.empty)
13+
result mustEqual RedCards(0, 0)
14+
}
15+
16+
"count a red card for the home team" in new RedCardsScope {
17+
val dismissals = List(homeDismissal("event-1", "player-1"))
18+
val result = RedCards.fromDismissals(home, away, dismissals)
19+
result mustEqual RedCards(home = 1, away = 0)
20+
}
21+
22+
"count a red card for the away team" in new RedCardsScope {
23+
val dismissals = List(awayDismissal("event-2", "player-2"))
24+
val result = RedCards.fromDismissals(home, away, dismissals)
25+
result mustEqual RedCards(home = 0, away = 1)
26+
}
27+
28+
"count red cards for both teams independently" in new RedCardsScope {
29+
val dismissals = List(
30+
homeDismissal("event-1", "player-1"),
31+
awayDismissal("event-2", "player-2"),
32+
awayDismissal("event-3", "player-3")
33+
)
34+
val result = RedCards.fromDismissals(home, away, dismissals)
35+
result mustEqual RedCards(home = 1, away = 2)
36+
}
37+
}
38+
39+
trait RedCardsScope extends Scope {
40+
val home = MatchDayTeam(
41+
id = "home-1",
42+
name = "Home Side",
43+
score = None,
44+
htScore = None,
45+
aggregateScore = None,
46+
scorers = None
47+
)
48+
val away = MatchDayTeam(
49+
id = "away-1",
50+
name = "Away Side",
51+
score = None,
52+
htScore = None,
53+
aggregateScore = None,
54+
scorers = None
55+
)
56+
57+
def homeDismissal(eventId: String, playerName: String) =
58+
Dismissal(eventId, playerName, home, 80, None)
59+
60+
def awayDismissal(eventId: String, playerName: String) =
61+
Dismissal(eventId, playerName, away, 75, None)
62+
}
63+
}
64+

0 commit comments

Comments
 (0)