package cn.nianxx.thhotel.platform.documentconversion.control;

import cn.nianxx.thhotel.platform.documentconversion.common.result.DocumentConversionErrorResponse;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

class DocumentConversionControllerAdviceTest {

    @Test
    void shouldMapFrameworkUploadLimitToSafeJsonError() {
        DocumentConversionControllerAdvice advice = new DocumentConversionControllerAdvice();

        ResponseEntity<DocumentConversionErrorResponse> response =
                advice.handleMaxUploadSizeExceeded(new MaxUploadSizeExceededException(1024));

        org.assertj.core.api.Assertions.assertThat(response.getStatusCode())
                .isEqualTo(HttpStatus.PAYLOAD_TOO_LARGE);
        org.assertj.core.api.Assertions.assertThat(response.getBody())
                .isNotNull()
                .extracting(DocumentConversionErrorResponse::errorCode)
                .isEqualTo("DOCUMENT_CONVERSION_FILE_TOO_LARGE");
    }
}
