package cloud.nstart.terravault.ordinis.restapi.service.reference;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class OnCloseActionTest {

  @Test
  void nullDefaultsToBlock() {
    assertThat(OnCloseAction.fromString(null)).isEqualTo(OnCloseAction.BLOCK);
  }

  @Test
  void blankDefaultsToBlock() {
    assertThat(OnCloseAction.fromString("")).isEqualTo(OnCloseAction.BLOCK);
    assertThat(OnCloseAction.fromString("   ")).isEqualTo(OnCloseAction.BLOCK);
  }

  @Test
  void caseInsensitiveAndTrimmed() {
    assertThat(OnCloseAction.fromString("BLOCK")).isEqualTo(OnCloseAction.BLOCK);
    assertThat(OnCloseAction.fromString("block")).isEqualTo(OnCloseAction.BLOCK);
    assertThat(OnCloseAction.fromString(" Warn ")).isEqualTo(OnCloseAction.WARN);
    assertThat(OnCloseAction.fromString("CaScAdE")).isEqualTo(OnCloseAction.CASCADE);
  }

  @Test
  void unknownThrows() {
    assertThatThrownBy(() -> OnCloseAction.fromString("yolo"))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessageContaining("[block, warn, cascade]")
        .hasMessageContaining("yolo");
  }
}
