package com.ponzischeme89.memby.update

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class RequiredUpdateStateTest {

    @Test
    fun `the build the gateway asked for satisfies the refusal`() {
        assertTrue(requiredUpdateSatisfied("0.2.46", "0.2.46"))
    }

    @Test
    fun `a later build satisfies it too`() {
        // The update installs and the app restarts before its first check comes back. The
        // refusal is about the APK that was retired, and that APK is gone.
        assertTrue(requiredUpdateSatisfied("0.2.47", "0.2.46"))
        assertTrue(requiredUpdateSatisfied("0.3.0", "0.2.46"))
    }

    @Test
    fun `the build that was retired does not`() {
        assertFalse(requiredUpdateSatisfied("0.2.45", "0.2.46"))
        assertFalse(requiredUpdateSatisfied("0.2.9", "0.2.46"))
    }

    @Test
    fun `missing components count as zero`() {
        assertTrue(requiredUpdateSatisfied("0.2", "0.2.0"))
        assertFalse(requiredUpdateSatisfied("0.2", "0.2.1"))
    }

    @Test
    fun `a suffix is ignored, and an unreadable version keeps the refusal standing`() {
        assertTrue(requiredUpdateSatisfied("0.2.46-beta", "0.2.46"))
        // Refusing to guess: a version neither end can parse must not be what lets a
        // retired television back onto the launcher.
        assertFalse(requiredUpdateSatisfied("0.2.46", "latest"))
        assertFalse(requiredUpdateSatisfied("", "0.2.46"))
    }
}
