package dev.lions.unionflow.server.resource;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.security.TestSecurity;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@QuarkusTest
class FeedbackResourceTest {

    @Test
    @TestSecurity(user = "user@unionflow.com", roles = { "USER" })
    @DisplayName("POST /api/feedback avec message valide retourne 201")
    void sendFeedback_valid_returns201() {
        given()
                .contentType(ContentType.JSON)
                .body("{\"subject\":\"Sujet\",\"message\":\"Message feedback\"}")
                .when()
                .post("/api/feedback")
                .then()
                .statusCode(201)
                .body("success", equalTo(true))
                .body("id", notNullValue());
    }

    @Test
    @TestSecurity(user = "user@unionflow.com", roles = { "USER" })
    @DisplayName("POST /api/feedback sans message retourne 400")
    void sendFeedback_emptyMessage_returns400() {
        given()
                .contentType(ContentType.JSON)
                .body("{\"subject\":\"Sujet\",\"message\":\"\"}")
                .when()
                .post("/api/feedback")
                .then()
                .statusCode(400)
                .body("error", equalTo("Le message est obligatoire"));
    }

    @Test
    @TestSecurity(user = "user@unionflow.com", roles = { "USER" })
    @DisplayName("POST /api/feedback sans body retourne 400")
    void sendFeedback_nullMessage_returns400() {
        given()
                .contentType(ContentType.JSON)
                .body("{}")
                .when()
                .post("/api/feedback")
                .then()
                .statusCode(400);
    }
}
