package com.ruoyi.web.modules.trading.service.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.ruoyi.web.modules.trading.domain.BizIsolationSetting;
import com.ruoyi.web.modules.trading.mapper.BizIsolationSettingMapper;
import com.ruoyi.web.modules.trading.support.IsolationPenRules;
import org.junit.jupiter.api.DisplayName;
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;

@ExtendWith(MockitoExtension.class)
@DisplayName("BizIsolationSettingServiceImpl")
class BizIsolationSettingServiceImplTest
{
    @Mock
    private BizIsolationSettingMapper mapper;

    @InjectMocks
    private BizIsolationSettingServiceImpl service;

    @Test
    @DisplayName("首次插入配置")
    void insertSetting()
    {
        when(mapper.selectBizIsolationSettingById(IsolationPenRules.SETTING_SINGLETON_ID)).thenReturn(null);
        when(mapper.insertBizIsolationSetting(any())).thenReturn(1);
        BizIsolationSetting row = new BizIsolationSetting();
        row.setDefaultDays(7);
        assertEquals(1, service.saveSetting(row, "admin"));
        verify(mapper).insertBizIsolationSetting(any());
    }

    @Test
    @DisplayName("更新配置")
    void updateSetting()
    {
        BizIsolationSetting existing = new BizIsolationSetting();
        existing.setId(1L);
        existing.setDefaultDays(7);
        when(mapper.selectBizIsolationSettingById(IsolationPenRules.SETTING_SINGLETON_ID)).thenReturn(existing);
        when(mapper.updateBizIsolationSetting(any())).thenReturn(1);
        BizIsolationSetting row = new BizIsolationSetting();
        row.setDefaultDays(14);
        assertEquals(1, service.saveSetting(row, "admin"));
        verify(mapper).updateBizIsolationSetting(any());
    }
}
