package com.ruoyi.web.modules.account.facade;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.web.modules.account.constant.MemberConstants;
import com.ruoyi.web.modules.account.domain.BizMember;
import com.ruoyi.web.modules.account.facade.impl.MemberFacadeImpl;
import com.ruoyi.web.modules.account.mapper.BizMemberMapper;
import com.ruoyi.web.modules.account.service.IMemberConsumptionService;

@ExtendWith(MockitoExtension.class)
class MemberFacadeImplTest
{
    @Mock
    private BizMemberMapper memberMapper;

    @Mock
    private IMemberConsumptionService consumptionService;

    @InjectMocks
    private MemberFacadeImpl memberFacade;

    @Test
    void isMemberEnabled_whenEnabled_true()
    {
        BizMember m = new BizMember();
        m.setStatus(MemberConstants.STATUS_ENABLED);
        when(memberMapper.selectById(1L)).thenReturn(m);

        assertTrue(memberFacade.isMemberEnabled(1L));
    }

    @Test
    void isMemberEnabled_whenDisabled_false()
    {
        BizMember m = new BizMember();
        m.setStatus(MemberConstants.STATUS_DISABLED);
        when(memberMapper.selectById(1L)).thenReturn(m);

        assertFalse(memberFacade.isMemberEnabled(1L));
    }

    @Test
    void refreshConsumption_delegates()
    {
        memberFacade.refreshConsumption(1L);
        verify(consumptionService).refreshConsumption(1L);
    }
}
