mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-16 12:05:07 +08:00
Merge branch 'feature/mall_product_tmp' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/mall_product
# Conflicts: # yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceTest.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java # yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java
This commit is contained in:
@ -0,0 +1,148 @@
|
||||
package cn.iocoder.yudao.module.system.service.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_CLIENT_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link SocialClientServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(SocialClientServiceImpl.class)
|
||||
public class SocialClientServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private SocialClientServiceImpl socialClientService;
|
||||
|
||||
@Resource
|
||||
private SocialClientMapper socialClientMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateSocialClient_success() {
|
||||
// 准备参数
|
||||
SocialClientCreateReqVO reqVO = randomPojo(SocialClientCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long socialClientId = socialClientService.createSocialClient(reqVO);
|
||||
// 断言
|
||||
assertNotNull(socialClientId);
|
||||
// 校验记录的属性是否正确
|
||||
SocialClientDO socialClient = socialClientMapper.selectById(socialClientId);
|
||||
assertPojoEquals(reqVO, socialClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSocialClient_success() {
|
||||
// mock 数据
|
||||
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class);
|
||||
socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class, o -> {
|
||||
o.setId(dbSocialClient.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
socialClientService.updateSocialClient(reqVO);
|
||||
// 校验是否更新正确
|
||||
SocialClientDO socialClient = socialClientMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, socialClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSocialClient_notExists() {
|
||||
// 准备参数
|
||||
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> socialClientService.updateSocialClient(reqVO), SOCIAL_CLIENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSocialClient_success() {
|
||||
// mock 数据
|
||||
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class);
|
||||
socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbSocialClient.getId();
|
||||
|
||||
// 调用
|
||||
socialClientService.deleteSocialClient(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(socialClientMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSocialClient_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> socialClientService.deleteSocialClient(id), SOCIAL_CLIENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetSocialClientPage() {
|
||||
// mock 数据
|
||||
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setSocialType(null);
|
||||
o.setUserType(null);
|
||||
o.setClientId(null);
|
||||
o.setClientSecret(null);
|
||||
o.setStatus(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
socialClientMapper.insert(dbSocialClient);
|
||||
// 测试 name 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setName(null)));
|
||||
// 测试 socialType 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setSocialType(null)));
|
||||
// 测试 userType 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setUserType(null)));
|
||||
// 测试 clientId 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setClientId(null)));
|
||||
// 测试 clientSecret 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setClientSecret(null)));
|
||||
// 测试 status 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setStatus(null)));
|
||||
// 测试 createTime 不匹配
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
SocialClientPageReqVO reqVO = new SocialClientPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setSocialType(null);
|
||||
reqVO.setUserType(null);
|
||||
reqVO.setClientId(null);
|
||||
reqVO.setClientSecret(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSocialClient, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,7 @@ DELETE FROM "system_sms_template";
|
||||
DELETE FROM "system_sms_log";
|
||||
DELETE FROM "system_sms_code";
|
||||
DELETE FROM "system_error_code";
|
||||
DELETE FROM "system_social_client";
|
||||
DELETE FROM "system_social_user";
|
||||
DELETE FROM "system_social_user_bind";
|
||||
DELETE FROM "system_tenant";
|
||||
|
@ -354,8 +354,25 @@ CREATE TABLE IF NOT EXISTS "system_error_code" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '错误码表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_client" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"social_type" int NOT NULL,
|
||||
"user_type" int NOT NULL,
|
||||
"client_id" varchar(255) NOT NULL,
|
||||
"client_secret" varchar(255) NOT NULL,
|
||||
"status" int NOT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '社交客户端表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_user" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"type" tinyint NOT NULL,
|
||||
"openid" varchar(64) NOT NULL,
|
||||
"token" varchar(256) DEFAULT NULL,
|
||||
@ -374,7 +391,7 @@ CREATE TABLE IF NOT EXISTS "system_social_user" (
|
||||
) COMMENT '社交用户';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_user_bind" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"user_id" bigint NOT NULL,
|
||||
"user_type" tinyint NOT NULL,
|
||||
"social_type" tinyint NOT NULL,
|
||||
|
Reference in New Issue
Block a user