package com.ruoyi.web.modules.farming.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("BizServiceAppointmentReviewMapper.xml")
class BizServiceAppointmentReviewMapperXmlTest
{
    @Test
    @DisplayName("评价查询 SQL")
    void reviewSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("selectReviewListByAppointmentId"));
        assertTrue(xml.contains("selectLatestReviewByAppointmentId"));
        assertTrue(xml.contains("appointment_id = #{appointmentId}"));
        assertTrue(xml.contains("punctuality_score"));
        assertTrue(xml.contains("order by review_time desc"));
        assertTrue(xml.contains("selectExpertRatingScoreByProviderId"));
        assertTrue(xml.contains("sum(r.punctuality_score)"));
        assertTrue(xml.contains("selectExpertProviderIdsForRatingSync"));
    }

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