package com.red.circle.live.app.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.red.circle.live.app.service.AgoraMicMissingConfirmService.MissingState;
import org.junit.Test;

public class AgoraMicMissingConfirmServiceTest {

  @Test
  public void firstMissingShouldOnlyRecordState() {
    MissingState state = MissingState.next(null, 1_000L);

    assertFalse(state.shouldCleanup(1_000L));
    assertEquals("1:1000", state.serialize());
  }

  @Test
  public void secondConsecutiveMissingShouldCleanup() {
    MissingState state = MissingState.next("1:1000", 2_000L);

    assertTrue(state.shouldCleanup(2_000L));
    assertEquals("2:1000", state.serialize());
  }

  @Test
  public void delayedMissingShouldCleanupAfterConfirmWindow() {
    MissingState state = MissingState.next("1:1000", 6_000L);

    assertTrue(state.shouldCleanup(6_000L));
  }

  @Test
  public void malformedStateShouldRestartConfirmWindow() {
    MissingState state = MissingState.next("bad-value", 3_000L);

    assertFalse(state.shouldCleanup(3_000L));
    assertEquals("1:3000", state.serialize());
  }
}
