package com.ruoyi.web.modules.store.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
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.store.mapper.BizShopStatsMapper;
import com.ruoyi.web.modules.store.service.impl.ShopRatingRefreshServiceImpl;

@ExtendWith(MockitoExtension.class)
class ShopRatingRefreshServiceImplTest
{
    @Mock
    private BizShopStatsMapper shopStatsMapper;

    @InjectMocks
    private ShopRatingRefreshServiceImpl shopRatingRefreshService;

    @Test
    void refreshAllShopRatings_insertsThenUpdates()
    {
        when(shopStatsMapper.insertStatsForShopsWithReviews()).thenReturn(1);
        when(shopStatsMapper.updateAllShopRatings()).thenReturn(5);

        int affected = shopRatingRefreshService.refreshAllShopRatings();

        assertEquals(6, affected);
        verify(shopStatsMapper).insertStatsForShopsWithReviews();
        verify(shopStatsMapper).updateAllShopRatings();
    }
}
