| 1 |
package io.oxygenhub.android.alerts |
| 2 |
|
| 3 |
import io.oxygenhub.android.api.ProposalBrief |
| 4 |
import org.junit.Assert.assertEquals |
| 5 |
import org.junit.Test |
| 6 |
|
| 7 |
class LandAlertsTest { |
| 8 |
private fun p(repository: String, number: Long) = ProposalBrief(repository, number, title = "P$number") |
| 9 |
|
| 10 |
@Test |
| 11 |
fun a_proposal_is_said_once_while_it_stays_landable() { |
| 12 |
val (first, seen) = LandAlerts.fresh(emptySet(), listOf(p("andy/demo", 2), p("andy/web", 7))) |
| 13 |
assertEquals(listOf(2L, 7L), first.map { it.number }) |
| 14 |
val (second, still) = LandAlerts.fresh(seen, listOf(p("andy/demo", 2), p("andy/web", 7))) |
| 15 |
assertEquals(emptyList<ProposalBrief>(), second) |
| 16 |
assertEquals(seen, still) |
| 17 |
} |
| 18 |
|
| 19 |
@Test |
| 20 |
fun a_proposal_that_becomes_landable_again_is_said_again() { |
| 21 |
val (_, seen) = LandAlerts.fresh(emptySet(), listOf(p("andy/demo", 2))) |
| 22 |
// A new commit made it wait for its checks again: no longer landable. |
| 23 |
val (none, waiting) = LandAlerts.fresh(seen, emptyList()) |
| 24 |
assertEquals(emptyList<ProposalBrief>(), none) |
| 25 |
assertEquals(emptySet<String>(), waiting) |
| 26 |
val (again, _) = LandAlerts.fresh(waiting, listOf(p("andy/demo", 2))) |
| 27 |
assertEquals(listOf("andy/demo#2"), again.map { "${it.repository}#${it.number}" }) |
| 28 |
} |
| 29 |
|
| 30 |
@Test |
| 31 |
fun the_same_number_in_two_repositories_is_two_proposals() { |
| 32 |
val (_, seen) = LandAlerts.fresh(emptySet(), listOf(p("andy/demo", 2))) |
| 33 |
val (said, _) = LandAlerts.fresh(seen, listOf(p("andy/demo", 2), p("andy/web", 2))) |
| 34 |
assertEquals(listOf("andy/web"), said.map { it.repository }) |
| 35 |
} |
| 36 |
} |