下线店铺管理-检测店铺密码功能:后台 UI 按钮/徽标、Python 代理路由、Java 接口与 service 全套移除,V105 迁移删除 biz_shop_credential_check 表及历史记录
Build Backend JAR / build (push) Has been cancelled
Build Backend JAR / build (push) Has been cancelled
This commit is contained in:
-147
@@ -1,147 +0,0 @@
|
||||
package com.nanri.aiimage.modules.shopkey.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopCredentialCheckMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.dto.ShopCredentialCheckReportRequest;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopCredentialCheckEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.model.vo.ShopCredentialCheckClaimVo;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ShopCredentialCheckServiceTest {
|
||||
|
||||
@Mock
|
||||
private ShopCredentialCheckMapper shopCredentialCheckMapper;
|
||||
@Mock
|
||||
private ShopManageMapper shopManageMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ShopCredentialCheckService service;
|
||||
|
||||
@BeforeEach
|
||||
void initTableInfo() {
|
||||
// MyBatis-Plus Lambda 缓存依赖 TableInfo,单测环境需手动初始化(对应实体)
|
||||
initTable(ShopCredentialCheckEntity.class);
|
||||
initTable(ShopManageEntity.class);
|
||||
}
|
||||
|
||||
private void initTable(Class<?> entityClass) {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, entityClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createReusesActiveTaskForSameShop() {
|
||||
ShopManageEntity shop = new ShopManageEntity();
|
||||
shop.setId(7L);
|
||||
shop.setShopName("美国站-主营");
|
||||
when(shopManageMapper.selectOne(any())).thenReturn(shop);
|
||||
ShopCredentialCheckEntity active = new ShopCredentialCheckEntity();
|
||||
active.setId(3L);
|
||||
active.setShopId(7L);
|
||||
active.setShopName("美国站-主营");
|
||||
active.setStatus(ShopCredentialCheckService.STATUS_RUNNING);
|
||||
when(shopCredentialCheckMapper.selectOne(any())).thenReturn(active);
|
||||
|
||||
var vo = service.create("美国站-主营");
|
||||
|
||||
assertEquals(3L, vo.getId());
|
||||
assertEquals("RUNNING", vo.getStatus());
|
||||
verify(shopCredentialCheckMapper, never()).insert(any(ShopCredentialCheckEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsUnknownShop() {
|
||||
when(shopManageMapper.selectOne(any())).thenReturn(null);
|
||||
|
||||
BusinessException ex = assertThrows(BusinessException.class, () -> service.create("不存在店铺"));
|
||||
assertEquals("后台店铺管理中未找到店铺:不存在店铺,请先添加店铺信息", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void claimSetsRunningAndReturnsZnUsername() {
|
||||
ShopCredentialCheckEntity pending = new ShopCredentialCheckEntity();
|
||||
pending.setId(9L);
|
||||
pending.setShopName("店铺-测试");
|
||||
when(shopCredentialCheckMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(java.util.List.of());
|
||||
when(shopCredentialCheckMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(pending);
|
||||
when(shopCredentialCheckMapper.update(any(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
||||
ShopManageEntity shop = new ShopManageEntity();
|
||||
shop.setZnUsername("zn-user-1");
|
||||
when(shopManageMapper.selectOne(any())).thenReturn(shop);
|
||||
|
||||
ShopCredentialCheckClaimVo vo = service.claimForClient("PC-01");
|
||||
|
||||
assertNotNull(vo);
|
||||
assertEquals(9L, vo.getId());
|
||||
assertEquals("店铺-测试", vo.getShopName());
|
||||
assertEquals("zn-user-1", vo.getZnUsername());
|
||||
verify(shopCredentialCheckMapper, times(1)).update(any(), any(LambdaUpdateWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void claimReturnsNullWhenNothingPending() {
|
||||
when(shopCredentialCheckMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(java.util.List.of());
|
||||
when(shopCredentialCheckMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(null);
|
||||
|
||||
assertNull(service.claimForClient("PC-01"));
|
||||
verify(shopCredentialCheckMapper, never()).update(any(), any(LambdaUpdateWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportIgnoresStaleStatus() {
|
||||
ShopCredentialCheckEntity finished = new ShopCredentialCheckEntity();
|
||||
finished.setId(5L);
|
||||
finished.setStatus(ShopCredentialCheckService.STATUS_SUCCESS);
|
||||
when(shopCredentialCheckMapper.selectById(5L)).thenReturn(finished);
|
||||
|
||||
ShopCredentialCheckReportRequest request = new ShopCredentialCheckReportRequest();
|
||||
request.setStatus(ShopCredentialCheckService.STATUS_FAILED);
|
||||
request.setDetail("密码错误");
|
||||
service.report(5L, request);
|
||||
|
||||
verify(shopCredentialCheckMapper, never()).updateById(any(ShopCredentialCheckEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportRecordsFailureDetail() {
|
||||
ShopCredentialCheckEntity running = new ShopCredentialCheckEntity();
|
||||
running.setId(6L);
|
||||
running.setStatus(ShopCredentialCheckService.STATUS_RUNNING);
|
||||
when(shopCredentialCheckMapper.selectById(6L)).thenReturn(running);
|
||||
|
||||
ShopCredentialCheckReportRequest request = new ShopCredentialCheckReportRequest();
|
||||
request.setStatus(ShopCredentialCheckService.STATUS_FAILED);
|
||||
request.setDetail("账号或密码错误");
|
||||
request.setClientHost("PC-02");
|
||||
service.report(6L, request);
|
||||
|
||||
verify(shopCredentialCheckMapper, times(1)).updateById(running);
|
||||
assertEquals(ShopCredentialCheckService.STATUS_FAILED, running.getStatus());
|
||||
assertEquals("账号或密码错误", running.getDetail());
|
||||
assertEquals("PC-02", running.getClientHost());
|
||||
assertNotNull(running.getCheckFinishedAt());
|
||||
}
|
||||
}
|
||||
-3
@@ -2,7 +2,6 @@ package com.nanri.aiimage.modules.shopkey.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopCredentialCheckMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -26,8 +25,6 @@ class ShopManageServiceTest {
|
||||
private ShopManageGroupService shopManageGroupService;
|
||||
@Mock
|
||||
private ShopCredentialCryptoService shopCredentialCryptoService;
|
||||
@Mock
|
||||
private ShopCredentialCheckMapper shopCredentialCheckMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ShopManageService service;
|
||||
|
||||
Reference in New Issue
Block a user