package org.raddatz.familienarchiv.config;

import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockEnvironment;

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

class FlywayConfigTest {

    @Test
    void resolveGrafanaDbPassword_throws_when_env_unset() {
        FlywayConfig config = new FlywayConfig(null, new MockEnvironment());

        assertThatThrownBy(config::resolveGrafanaDbPassword)
                .isInstanceOf(IllegalStateException.class)
                .hasMessageContaining("GRAFANA_DB_PASSWORD is required");
    }

    @Test
    void resolveGrafanaDbPassword_throws_when_env_blank() {
        MockEnvironment env = new MockEnvironment().withProperty("GRAFANA_DB_PASSWORD", "   ");
        FlywayConfig config = new FlywayConfig(null, env);

        assertThatThrownBy(config::resolveGrafanaDbPassword)
                .isInstanceOf(IllegalStateException.class)
                .hasMessageContaining("GRAFANA_DB_PASSWORD is required");
    }

    @Test
    void resolveGrafanaDbPassword_returns_value_when_env_set() {
        MockEnvironment env = new MockEnvironment().withProperty("GRAFANA_DB_PASSWORD", "abc");
        FlywayConfig config = new FlywayConfig(null, env);

        assertThat(config.resolveGrafanaDbPassword()).isEqualTo("abc");
    }
}
