package com.ponzischeme89.memby.update

import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

class RequiredUpdateSignalTest {

    @Test
    fun `a refusal reported before anybody listens is still delivered`() = runTest {
        // The gateway retires a build on whichever request is in flight, which on a cold
        // start can be before AppRoot's check loop is waiting. A signal nobody heard would
        // leave the television on a sign-in form the gateway is about to refuse.
        RequiredUpdateSignal.report("0.2.46")

        assertEquals("0.2.46", RequiredUpdateSignal.required.first())
    }

    @Test
    fun `the newest refusal wins and a blank header says nothing`() = runTest {
        RequiredUpdateSignal.report("0.2.46")
        RequiredUpdateSignal.report("  ")
        RequiredUpdateSignal.report(" 0.2.47 ")

        assertEquals("0.2.47", RequiredUpdateSignal.required.first())
    }
}
