package com.ruoyi.info.collection.mapper;

import org.junit.jupiter.api.Test;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertTrue;

class CcdiBaseStaffMapperTest {

    @Test
    void mapperXml_shouldContainAnnualIncomeColumnsInCustomSql() throws Exception {
        try (InputStream inputStream = getClass().getClassLoader()
                .getResourceAsStream("mapper/info/collection/CcdiBaseStaffMapper.xml")) {
            String xml = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);

            assertTrue(xml.contains("annual_income"), xml);
            assertTrue(xml.contains("#{item.annualIncome}"), xml);
            assertTrue(xml.contains("is_party_member"), xml);
            assertTrue(xml.contains("#{item.partyMember}"), xml);
        }
    }

    @Test
    void mapperXml_shouldUseStableOrderForBaseStaffPagination() throws Exception {
        try (InputStream inputStream = getClass().getClassLoader()
                .getResourceAsStream("mapper/info/collection/CcdiBaseStaffMapper.xml")) {
            String xml = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8)
                    .replaceAll("\\s+", " ");

            assertTrue(xml.contains("ORDER BY e.create_time DESC, e.staff_id DESC"), xml);
        }
    }
}
