package com.codebyte.api;

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

import com.codebyte.api.support.AbstractPostgresIT;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * Smoke test: boots the full application against the shared PostgreSQL container and asserts the
 * Actuator health endpoint reports {@code UP}. Because the datasource health contributor is active,
 * an overall {@code UP} proves the app has a live database connection.
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ActuatorHealthSmokeIT extends AbstractPostgresIT {

    @Autowired private TestRestTemplate restTemplate;

    @Test
    void should_report_status_up_when_actuator_health_queried() {
        ResponseEntity<String> response =
                restTemplate.getForEntity("/actuator/health", String.class);

        assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(response.getBody()).contains("\"status\":\"UP\"");
    }
}
