code review:签到配置

This commit is contained in:
YunaiV 2023-08-20 19:26:31 +08:00
parent 4257cad46a
commit c5e85f3bfb
13 changed files with 133 additions and 135 deletions

View File

@ -1640,11 +1640,11 @@ INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_i
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2276, '积分设置查询', 'member:point:config:get', 3, 1, 2275, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 02:07:44', '', '2023-06-10 02:07:44', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2277, '积分设置创建', 'member:point:config:save', 3, 2, 2275, '', '', '', '', 0, b'1', b'1', b'1', '', '2023-06-10 02:07:44', '1', '2023-06-27 20:32:31', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2281, '签到配置', '', 2, 2, 2300, 'sign-in-config', '', 'member/signin/config/index', 'SignInConfig', 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '1', '2023-07-02 15:04:15', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2282, '积分签到规则查询', 'member:point:sign-in-config:query', 3, 1, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2283, '积分签到规则创建', 'member:point:sign-in-config:create', 3, 2, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2284, '积分签到规则更新', 'member:point:sign-in-config:update', 3, 3, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2285, '积分签到规则删除', 'member:point:sign-in-config:delete', 3, 4, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2286, '积分签到规则获取', 'member:point:sign-in-config:get', 3, 5, 2281, '', '', '', '', 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '1', '2023-08-19 09:48:32', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2282, '签到规则查询', 'member:point:sign-in-config:query', 3, 1, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2283, '签到规则创建', 'member:point:sign-in-config:create', 3, 2, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2284, '签到规则更新', 'member:point:sign-in-config:update', 3, 3, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2285, '签到规则删除', 'member:point:sign-in-config:delete', 3, 4, 2281, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '', '2023-06-10 03:26:12', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2286, '签到规则获取', 'member:point:sign-in-config:get', 3, 5, 2281, '', '', '', '', 0, b'1', b'1', b'1', '', '2023-06-10 03:26:12', '1', '2023-08-19 09:48:32', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2287, '积分记录', '', 2, 1, 2299, 'record', '', 'member/point/record/index', 'PointRecord', 0, b'1', b'1', b'1', '', '2023-06-10 04:18:50', '1', '2023-06-27 22:51:07', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2288, '用户积分记录查询', 'member:point:record:query', 3, 1, 2287, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-06-10 04:18:50', '', '2023-06-10 04:18:50', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2293, '签到记录', '', 2, 3, 2300, 'sign-in-record', '', 'member/signin/record/index', 'SignInRecord', 0, b'1', b'1', b'1', '', '2023-06-10 04:48:22', '1', '2023-07-02 15:04:10', b'0');

View File

@ -20,7 +20,7 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 积分签到规则")
@Tag(name = "管理后台 - 签到规则")
@RestController
@RequestMapping("/member/point/sign-in-config")
@Validated
@ -30,14 +30,14 @@ public class MemberSignInConfigController {
private MemberSignInConfigService signInConfigService;
@PostMapping("/create")
@Operation(summary = "创建积分签到规则")
@Operation(summary = "创建签到规则")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:create')")
public CommonResult<Long> createSignInConfig(@Valid @RequestBody MemberSignInConfigCreateReqVO createReqVO) {
return success(signInConfigService.createSignInConfig(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新积分签到规则")
@Operation(summary = "更新签到规则")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:update')")
public CommonResult<Boolean> updateSignInConfig(@Valid @RequestBody MemberSignInConfigUpdateReqVO updateReqVO) {
signInConfigService.updateSignInConfig(updateReqVO);
@ -45,7 +45,7 @@ public class MemberSignInConfigController {
}
@DeleteMapping("/delete")
@Operation(summary = "删除积分签到规则")
@Operation(summary = "删除签到规则")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('point:sign-in-config:delete')")
public CommonResult<Boolean> deleteSignInConfig(@RequestParam("id") Long id) {
@ -54,7 +54,7 @@ public class MemberSignInConfigController {
}
@GetMapping("/get")
@Operation(summary = "获得积分签到规则")
@Operation(summary = "获得签到规则")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:query')")
public CommonResult<MemberSignInConfigRespVO> getSignInConfig(@RequestParam("id") Long id) {
@ -63,7 +63,7 @@ public class MemberSignInConfigController {
}
@GetMapping("/list")
@Operation(summary = "获得积分签到规则分页")
@Operation(summary = "获得签到规则列表")
@PreAuthorize("@ss.hasPermission('point:sign-in-config:query')")
public CommonResult<List<MemberSignInConfigRespVO>> getSignInConfigList() {
List<MemberSignInConfigDO> pageResult = signInConfigService.getSignInConfigList();

View File

@ -1,17 +1,19 @@
package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 积分签到规则 Base VO提供给添加修改详细的子 VO 使用
* 签到规则 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class MemberSignInConfigBaseVO {
@Schema(description = "签到第 x 天", requiredMode = Schema.RequiredMode.REQUIRED, example = "7")
@NotNull(message = "签到天数不能为空")
private Integer day;
@ -20,8 +22,9 @@ public class MemberSignInConfigBaseVO {
@NotNull(message = "奖励积分不能为空")
private Integer point;
@NotNull
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Boolean enable;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(CommonStatusEnum.class)
private Integer status;
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.member.controller.admin.signin.vo.config;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "管理后台 - 积分签到规则创建 Request VO")
@Schema(description = "管理后台 - 签到规则创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

View File

@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 积分签到规则 Response VO")
@Schema(description = "管理后台 - 签到规则 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

View File

@ -5,7 +5,7 @@ import lombok.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 积分签到规则更新 Request VO")
@Schema(description = "管理后台 - 签到规则更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

View File

@ -10,7 +10,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 积分签到规则 Convert
* 签到规则 Convert
*
* @author QingX
*/

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.member.dal.dataobject.signin;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
@ -7,7 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 积分签到规则 DO
* 签到规则 DO
*
* @author QingX
*/
@ -27,7 +28,7 @@ public class MemberSignInConfigDO extends BaseDO {
@TableId
private Long id;
/**
* 签到第x天
* 签到第 x
*/
private Integer day;
/**
@ -36,8 +37,10 @@ public class MemberSignInConfigDO extends BaseDO {
private Integer point;
/**
* 是否启用
* 状态
*
* 枚举 {@link CommonStatusEnum}
*/
private Boolean enable;
private Integer status;
}

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO
import org.apache.ibatis.annotations.Mapper;
/**
* 积分签到规则 Mapper
* 签到规则 Mapper
*
* @author QingX
*/

View File

@ -8,14 +8,14 @@ import javax.validation.Valid;
import java.util.List;
/**
* 积分签到规则 Service 接口
* 签到规则 Service 接口
*
* @author QingX
*/
public interface MemberSignInConfigService {
/**
* 创建积分签到规则
* 创建签到规则
*
* @param createReqVO 创建信息
* @return 编号
@ -23,31 +23,31 @@ public interface MemberSignInConfigService {
Long createSignInConfig(@Valid MemberSignInConfigCreateReqVO createReqVO);
/**
* 更新积分签到规则
* 更新签到规则
*
* @param updateReqVO 更新信息
*/
void updateSignInConfig(@Valid MemberSignInConfigUpdateReqVO updateReqVO);
/**
* 删除积分签到规则
* 删除签到规则
*
* @param id 编号
*/
void deleteSignInConfig(Long id);
/**
* 获得积分签到规则
* 获得签到规则
*
* @param id 编号
* @return 积分签到规则
* @return 签到规则
*/
MemberSignInConfigDO getSignInConfig(Long id);
/**
* 获得积分签到规则分页
* 获得签到规则分页
*
* @return 积分签到规则分页
* @return 签到规则分页
*/
List<MemberSignInConfigDO> getSignInConfigList();

View File

@ -17,7 +17,7 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CO
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.SIGN_IN_CONFIG_NOT_EXISTS;
/**
* 积分签到规则 Service 实现类
* 签到规则 Service 实现类
*
* @author QingX
*/
@ -73,13 +73,13 @@ public class MemberSignInConfigServiceImpl implements MemberSignInConfigService
* @param id 编号只有更新的时候会传递
*/
private void validateSignInConfigDayDuplicate(Integer day, Long id) {
MemberSignInConfigDO configDO = signInConfigMapper.selectByDay(day);
// 1. 新增时configDO 非空则说明重复
if (id == null && configDO != null) {
MemberSignInConfigDO config = signInConfigMapper.selectByDay(day);
// 1. 新增时config 非空则说明重复
if (id == null && config != null) {
throw exception(SIGN_IN_CONFIG_EXISTS);
}
// 2. 更新时如果 configDO 非空 id 不相等则说明重复
if (id != null && configDO != null && !configDO.getId().equals(id)) {
// 2. 更新时如果 config 非空 id 不相等则说明重复
if (id != null && config != null && !config.getId().equals(id)) {
throw exception(SIGN_IN_CONFIG_EXISTS);
}
}

View File

@ -5,16 +5,13 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbAndRedisUnitTest;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserResetPasswordReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdatePasswordReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
import cn.iocoder.yudao.module.system.api.logger.LoginLogApi;
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.password.PasswordEncoder;
@ -23,11 +20,8 @@ import javax.annotation.Resource;
import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.hutool.core.util.RandomUtil.randomNumbers;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
// TODO @芋艿单测的 review等逻辑都达成一致后
/**
@ -61,55 +55,56 @@ public class MemberAuthServiceTest extends BaseDbAndRedisUnitTest {
@Resource
private MemberUserMapper memberUserMapper;
@Test
public void testUpdatePassword_success(){
// 准备参数
MemberUserDO userDO = randomUserDO();
memberUserMapper.insert(userDO);
// 新密码
String newPassword = randomString();
// 请求实体
AppMemberUserUpdatePasswordReqVO reqVO = AppMemberUserUpdatePasswordReqVO.builder()
.oldPassword(userDO.getPassword())
.password(newPassword)
.build();
// 测试桩
// 这两个相等是为了返回ture这个结果
when(passwordEncoder.matches(reqVO.getOldPassword(),reqVO.getOldPassword())).thenReturn(true);
when(passwordEncoder.encode(newPassword)).thenReturn(newPassword);
// 更新用户密码
authService.updatePassword(userDO.getId(), reqVO);
assertEquals(memberUserMapper.selectById(userDO.getId()).getPassword(),newPassword);
}
@Test
public void testResetPassword_success(){
// 准备参数
MemberUserDO userDO = randomUserDO();
memberUserMapper.insert(userDO);
// 随机密码
String password = randomNumbers(11);
// 随机验证码
String code = randomNumbers(4);
// mock
when(passwordEncoder.encode(password)).thenReturn(password);
// 更新用户密码
AppMemberUserResetPasswordReqVO reqVO = new AppMemberUserResetPasswordReqVO();
reqVO.setMobile(userDO.getMobile());
reqVO.setPassword(password);
reqVO.setCode(code);
authService.resetPassword(reqVO);
assertEquals(memberUserMapper.selectById(userDO.getId()).getPassword(),password);
}
// TODO 芋艿后续重构这个单测
// @Test
// public void testUpdatePassword_success(){
// // 准备参数
// MemberUserDO userDO = randomUserDO();
// memberUserMapper.insert(userDO);
//
// // 新密码
// String newPassword = randomString();
//
// // 请求实体
// AppMemberUserUpdatePasswordReqVO reqVO = AppMemberUserUpdatePasswordReqVO.builder()
// .oldPassword(userDO.getPassword())
// .password(newPassword)
// .build();
//
// // 测试桩
// // 这两个相等是为了返回ture这个结果
// when(passwordEncoder.matches(reqVO.getOldPassword(),reqVO.getOldPassword())).thenReturn(true);
// when(passwordEncoder.encode(newPassword)).thenReturn(newPassword);
//
// // 更新用户密码
// authService.updatePassword(userDO.getId(), reqVO);
// assertEquals(memberUserMapper.selectById(userDO.getId()).getPassword(),newPassword);
// }
// TODO 芋艿后续重构这个单测
// @Test
// public void testResetPassword_success(){
// // 准备参数
// MemberUserDO userDO = randomUserDO();
// memberUserMapper.insert(userDO);
//
// // 随机密码
// String password = randomNumbers(11);
// // 随机验证码
// String code = randomNumbers(4);
//
// // mock
// when(passwordEncoder.encode(password)).thenReturn(password);
//
// // 更新用户密码
// AppMemberUserResetPasswordReqVO reqVO = new AppMemberUserResetPasswordReqVO();
// reqVO.setMobile(userDO.getMobile());
// reqVO.setPassword(password);
// reqVO.setCode(code);
//
// authService.resetPassword(reqVO);
// assertEquals(memberUserMapper.selectById(userDO.getId()).getPassword(),password);
// }
// ========== 随机对象 ==========

View File

@ -18,15 +18,12 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.hutool.core.util.RandomUtil.randomNumbers;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.when;
// TODO @芋艿单测的 review等逻辑都达成一致后
/**
@ -57,41 +54,42 @@ public class MemberUserServiceImplTest extends BaseDbAndRedisUnitTest {
@MockBean
private FileApi fileApi;
@Test
public void testUpdateNickName_success(){
// mock 数据
MemberUserDO userDO = randomUserDO();
userMapper.insert(userDO);
// 随机昵称
String newNickName = randomString();
// 调用接口修改昵称
memberUserService.updateUser(userDO.getId(),newNickName);
// 查询新修改后的昵称
String nickname = memberUserService.getUser(userDO.getId()).getNickname();
// 断言
assertEquals(newNickName,nickname);
}
@Test
public void testUpdateAvatar_success() throws Exception {
// mock 数据
MemberUserDO dbUser = randomUserDO();
userMapper.insert(dbUser);
// 准备参数
Long userId = dbUser.getId();
byte[] avatarFileBytes = randomBytes(10);
ByteArrayInputStream avatarFile = new ByteArrayInputStream(avatarFileBytes);
// mock 方法
String avatar = randomString();
when(fileApi.createFile(eq(avatarFileBytes))).thenReturn(avatar);
// 调用
String str = memberUserService.updateUserAvatar(userId, avatarFile);
// 断言
assertEquals(avatar, str);
}
// TODO 芋艿后续重构这个单测
// @Test
// public void testUpdateNickName_success(){
// // mock 数据
// MemberUserDO userDO = randomUserDO();
// userMapper.insert(userDO);
//
// // 随机昵称
// String newNickName = randomString();
//
// // 调用接口修改昵称
// memberUserService.updateUser(userDO.getId(),newNickName);
// // 查询新修改后的昵称
// String nickname = memberUserService.getUser(userDO.getId()).getNickname();
// // 断言
// assertEquals(newNickName,nickname);
// }
//
// @Test
// public void testUpdateAvatar_success() throws Exception {
// // mock 数据
// MemberUserDO dbUser = randomUserDO();
// userMapper.insert(dbUser);
//
// // 准备参数
// Long userId = dbUser.getId();
// byte[] avatarFileBytes = randomBytes(10);
// ByteArrayInputStream avatarFile = new ByteArrayInputStream(avatarFileBytes);
// // mock 方法
// String avatar = randomString();
// when(fileApi.createFile(eq(avatarFileBytes))).thenReturn(avatar);
// // 调用
// String str = memberUserService.updateUserAvatar(userId, avatarFile);
// // 断言
// assertEquals(avatar, str);
// }
@Test
public void updateMobile_success(){
@ -117,7 +115,6 @@ public class MemberUserServiceImplTest extends BaseDbAndRedisUnitTest {
AppMemberUserUpdateMobileReqVO reqVO = new AppMemberUserUpdateMobileReqVO();
reqVO.setMobile(newMobile);
reqVO.setCode(newCode);
reqVO.setOldMobile(oldMobile);
reqVO.setOldCode(oldCode);
memberUserService.updateUserMobile(userDO.getId(),reqVO);