package com.dtourolle.jellytau.player

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

/**
 * Who owns recovery for the stream that is loaded.
 *
 * TRACES: UR-040, UR-004 | DR-203 | UT-200
 */
class StreamRetryDecisionTest {

    /** Nothing loaded yet is an ordinary stream: the player retries as it always has. */
    @Test
    fun `starts allowing the player to retry`() {
        assertTrue(StreamRetryDecision().playerMayRetry)
    }

    /**
     * The reported bug: the length-less handoff transcode can only be "retried"
     * from its beginning, which replays the episode from the handoff point
     * without reporting anything. The player must not be allowed to try.
     */
    @Test
    fun `a non-resumable stream refuses the player its retry`() {
        val decision = StreamRetryDecision()
        decision.onLoad(nonResumable = true)
        assertFalse(decision.playerMayRetry)
    }

    @Test
    fun `an ordinary stream keeps the player retry`() {
        val decision = StreamRetryDecision()
        decision.onLoad(nonResumable = false)
        assertTrue(decision.playerMayRetry)
    }

    /** The next load decides for itself — the handoff must not outlive its item. */
    @Test
    fun `loading an ordinary stream after a handoff restores the retry`() {
        val decision = StreamRetryDecision()
        decision.onLoad(nonResumable = true)
        decision.onLoad(nonResumable = false)
        assertTrue(decision.playerMayRetry)
    }
}
