package com.ruoyi.web.modules.booking.mapper;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("AppMyAppointmentMapper.xml")
class AppMyAppointmentMapperXmlTest
{

    @Test
    @DisplayName("列表筛选与取消 SQL")
    void listSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("create_by = #{createBy}"));
        assertTrue(xml.contains("statusTab == 'notStarted'"));
        assertTrue(xml.contains("statusTab == 'pendingReview'"));
        assertTrue(xml.contains("biz_service_appointment_review"));
        assertTrue(xml.contains("cancelMyAppointment"));
        assertTrue(xml.contains("status in (0, 1, 5)"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = AppMyAppointmentMapperXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/booking/AppMyAppointmentMapper.xml"))
        {
            if (in == null)
            {
                throw new IllegalStateException("mapper xml not found");
            }
            return IOUtils.toString(in, StandardCharsets.UTF_8);
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }
    }
}
