优化布局

This commit is contained in:
supernijia
2026-07-24 13:26:37 +08:00
parent bca1335dc6
commit f1b7a7aae8
8 changed files with 192 additions and 43 deletions
@@ -0,0 +1,83 @@
package com.nanri.aiimage.modules.ziniao.service;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.modules.shopkey.service.ShopManageService;
import com.nanri.aiimage.modules.ziniao.model.vo.ZiniaoShopMatchResultVo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ZiniaoShopSwitchServiceTest {
@Mock
private ZiniaoAuthService ziniaoAuthService;
@Mock
private ZiniaoShopIndexService ziniaoShopIndexService;
@Mock
private ShopManageService shopManageService;
@Test
void missingManagedShopStopsIndexedLookup() {
String message = "后台店铺管理中未找到店铺:缺失店铺,请先添加店铺信息";
when(shopManageService.requireShopByName("缺失店铺"))
.thenThrow(new BusinessException(message));
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
BusinessException exception = assertThrows(BusinessException.class,
() -> service.findIndexedStoreByName("缺失店铺", false));
assertEquals(message, exception.getMessage());
verifyNoInteractions(ziniaoShopIndexService);
}
@Test
void managedShopIsCheckedBeforeIndexedLookup() {
ZiniaoShopMatchResultVo expected = new ZiniaoShopMatchResultVo();
expected.setMatched(true);
when(ziniaoShopIndexService.findIndexedStoreByName("测试店铺", false)).thenReturn(expected);
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
ZiniaoShopMatchResultVo actual = service.findIndexedStoreByName(" 测试店铺 ", false);
assertSame(expected, actual);
InOrder order = inOrder(shopManageService, ziniaoShopIndexService);
order.verify(shopManageService).requireShopByName("测试店铺");
order.verify(ziniaoShopIndexService).findIndexedStoreByName("测试店铺", false);
}
@Test
void missingManagedShopStopsDirectStaffMatch() {
when(shopManageService.requireShopByName("缺失店铺"))
.thenThrow(new BusinessException("后台店铺管理中未找到店铺:缺失店铺,请先添加店铺信息"));
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
assertThrows(BusinessException.class,
() -> service.matchStoreByNameAcrossStaff("缺失店铺", 12L));
verifyNoInteractions(ziniaoAuthService);
}
@Test
void blankShopNameDoesNotQueryManagedShopOrZiniao() {
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
ZiniaoShopMatchResultVo result = service.findIndexedStoreByName("  ", false);
assertEquals(ZiniaoShopIndexService.MATCH_STATUS_PENDING, result.getMatchStatus());
assertEquals("店铺名为空,无法匹配索引", result.getMatchMessage());
verifyNoInteractions(shopManageService, ziniaoShopIndexService, ziniaoAuthService);
}
}