package com.ponzischeme89.memby.update

import org.junit.Assert.assertEquals
import org.junit.Test

class UpdateCheckScheduleTest {
    @Test
    fun `a real verdict uses the regular live policy poll`() {
        assertEquals(30_000L, delay(requiredAttempts = 0, failedAttempts = 0))
    }

    @Test
    fun `a timed out launch check retries promptly`() {
        assertEquals(5_000L, delay(requiredAttempts = 0, failedAttempts = 1))
    }

    @Test
    fun `repeated failures settle onto bounded backoff`() {
        assertEquals(60_000L, delay(requiredAttempts = 0, failedAttempts = 5))
    }

    @Test
    fun `a retired build keeps the urgent schedule even after a successful empty check`() {
        assertEquals(5_000L, delay(requiredAttempts = 1, failedAttempts = 0))
    }

    private fun delay(requiredAttempts: Int, failedAttempts: Int) = nextUpdateCheckDelay(
        requiredAttempts = requiredAttempts,
        failedAttempts = failedAttempts,
        fastAttempts = 4,
        fastRetryMillis = 5_000L,
        backoffMillis = 60_000L,
        regularPollMillis = 30_000L,
    )
}
