package com.estate.expert.admin.service;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.estate.expert.admin.domain.user.User;
|
import com.estate.expert.admin.domain.user.UserDto;
|
import com.estate.expert.admin.domain.user.UserState;
|
import com.estate.expert.admin.domain.common.request.PageReq;
|
import com.estate.expert.common.utils.PasswordUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
|
/**
|
* 用户服务测试
|
**/
|
@Slf4j
|
@SpringBootTest
|
@ExtendWith(SpringExtension.class)
|
@Transactional
|
public class UserServiceTest {
|
|
@Autowired
|
private UserService userService;
|
|
private User currentUser;
|
|
@BeforeEach
|
public void setUp() {
|
User request = new User();
|
request.setName("Lily");
|
request.setMobile("13814085622");
|
request.setDepartmentPath("K");
|
currentUser = userService.add(null , request);
|
}
|
|
@AfterEach
|
public void tearDown() {
|
userService.deleteAllById(List.of(currentUser.getId()));
|
}
|
|
@Test
|
public void testList() {
|
var response = userService.list("", PageReq.defaultPageReq());
|
Assertions.assertTrue(response.getTotalElements() > 0);
|
|
response = userService.list("Lily", PageReq.defaultPageReq());
|
Assertions.assertTrue(response.getTotalElements() > 0);
|
|
response = userService.list("xxccsd", PageReq.defaultPageReq());
|
Assertions.assertEquals(0, response.getTotalElements());
|
log.info("response: {}", JSONObject.toJSONString(response));
|
}
|
|
@Test
|
public void testOptions(){
|
var response = userService.options(null);
|
Assertions.assertFalse(response.isEmpty());
|
log.info("response: {}", JSONObject.toJSONString(response));
|
}
|
|
@Test
|
public void testEditUser() {
|
UserDto request = UserDto.builder()
|
.id(currentUser.getId())
|
.name("小小木")
|
.mobile("18501373727")
|
.state(UserState.DISABLE)
|
.departmentPath("K")
|
.avatar("avatar").build();
|
userService.edit(request);
|
|
User user = userService.get(currentUser.getId());
|
Assertions.assertEquals("小小木", user.getName());
|
// mobile 不可修改
|
Assertions.assertNotEquals("18501373727", user.getMobile());
|
}
|
|
@Test
|
public void testResetPass() {
|
userService.resetPass(currentUser.getId());
|
}
|
|
@Test
|
public void testModifyState() {
|
userService.modifyState(currentUser.getId(), UserState.DISABLE);
|
User user = userService.get(currentUser.getId());
|
Assertions.assertEquals(UserState.DISABLE, user.getState());
|
}
|
|
@Test
|
public void testPass() {
|
String defaultPass = "123456";
|
System.out.println(PasswordUtils.generate(defaultPass));
|
}
|
|
}
|