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("AppAppointmentResourceMapper.xml")
class AppAppointmentResourceMapperXmlTest
{

    @Test
    @DisplayName("视图查询与周几筛选")
    void viewSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("v_appointment_resource"));
        assertTrue(xml.contains("resource_type = #{resourceType}"));
        assertTrue(xml.contains("FIND_IN_SET(#{weekday}, service_weekdays)"));
        assertTrue(xml.contains("expert_rating"));
        assertTrue(xml.contains("photo_file_url"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = AppAppointmentResourceMapperXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/booking/AppAppointmentResourceMapper.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);
        }
    }
}
