This commit is contained in:
jack ning
2024-03-29 16:26:33 +08:00
parent 36c54949d8
commit 4b6ecab453
1002 changed files with 130707 additions and 240 deletions

View File

@@ -0,0 +1,84 @@
/*
* @Author: jackning 270580156@qq.com
* @Date: 2024-02-02 09:13:26
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-02-02 10:12:12
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* 仅支持企业内部员工自用严禁私自用于销售、二次销售或者部署SaaS方式销售
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
* contact: 270580156@qq.com
* 联系270580156@qq.com
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
*/
package com.bytedesk.team;
import com.bytedesk.team.department.DepartmentController;
import com.bytedesk.team.department.DepartmentRequest;
import com.bytedesk.team.department.DepartmentService;
import com.bytedesk.core.utils.JsonResult;
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.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(SpringExtension.class)
public class DepartmentControllerTests {
@InjectMocks
private DepartmentController departmentController;
@Mock
private DepartmentService departmentService;
@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
}
@SuppressWarnings("null")
@Test
public void testCreateSuccess() {
// Arrange
DepartmentRequest departmentRequest = new DepartmentRequest();
departmentRequest.setNickname("Test Department");
departmentRequest.setParent_did(null);
departmentRequest.setOrg_oid("f01f5444ecbc437cb5b8de7ca7dd023c");
// Act
ResponseEntity<JsonResult<?>> response = departmentController.create(departmentRequest);
// Assert
assertEquals(200, response.getStatusCode().value());
JsonResult<?> result = response.getBody();
assertEquals("创建成功", result.getMessage());
assertEquals(200, result.getCode());
}
@SuppressWarnings("null")
@Test
public void testCreateFailure() {
// Arrange
DepartmentRequest departmentRequest = new DepartmentRequest();
departmentRequest.setDid("testDid");
departmentRequest.setParent_did(null);
departmentRequest.setOrg_oid("testOrgOid");
// Act
ResponseEntity<JsonResult<?>> response = departmentController.create(departmentRequest);
// Assert
assertEquals(200, response.getStatusCode().value());
JsonResult<?> result = response.getBody();
assertEquals("create dep failed", result.getMessage());
assertEquals(-1, result.getCode());
assertEquals(false, result.getData());
}
}

View File

@@ -0,0 +1,101 @@
package com.bytedesk.team;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import com.bytedesk.core.auth.AuthService;
import com.bytedesk.core.rbac.user.User;
import com.bytedesk.team.department.Department;
import com.bytedesk.team.department.DepartmentRepository;
import com.bytedesk.team.department.DepartmentRequest;
import com.bytedesk.team.department.DepartmentService;
import com.bytedesk.team.organization.Organization;
import com.bytedesk.team.organization.OrganizationService;
import com.bytedesk.core.utils.Utils;
@SpringBootTest
@ActiveProfiles("test")
public class DepartmentServiceTests {
@Autowired
private DepartmentService departmentService;
@MockBean
private ModelMapper modelMapper;
@MockBean
private AuthService authService;
@MockBean
private OrganizationService organizationService;
@MockBean
private DepartmentRepository departmentRepository;
private DepartmentRequest departmentRequest;
private User user;
private Organization organization;
@BeforeEach
public void setUp() {
departmentRequest = new DepartmentRequest();
departmentRequest.setDescription("Test department");
departmentRequest.setParent_did("parentDid");
departmentRequest.setOrg_oid("f01f5444ecbc437cb5b8de7ca7dd023c");
departmentRequest.setId(1L);
departmentRequest.setDid(Utils.getUid());
departmentRequest.setNickname("Test Department");
departmentRequest.setAvatar("testAvatar");
user = new User();
user.setUsername("testUser");
organization = new Organization();
when(authService.getCurrentUser()).thenReturn(user);
when(organizationService.findByOid(departmentRequest.getOrg_oid())).thenReturn(Optional.of(organization));
when(modelMapper.map(departmentRequest, Department.class)).thenAnswer(invocation -> {
Department dept = new Department();
dept.setDid(departmentRequest.getDid());
dept.setOrganization(organization);
dept.setUser(user);
return dept;
});
}
@Test
public void testCreateDepartmentWithValidRequest() {
// Act
Department createdDepartment = departmentService.create(departmentRequest);
// Assert
assertNotNull(createdDepartment);
assertEquals(departmentRequest.getDid(), createdDepartment.getDid());
assertEquals(organization, createdDepartment.getOrganization());
assertEquals(user, createdDepartment.getUser());
// Verify that the repository's save method is called
// verify(departmentRepository).save(any(Department.class));
}
@Test
public void testCreateDepartmentWithNonExistingOrgOid() {
// Arrange
when(organizationService.findByOid(departmentRequest.getOrg_oid())).thenReturn(Optional.empty());
// Act & Assert
// Department createdDepartment = departmentService.create(departmentRequest);
// assertNull(createdDepartment);
}
}

View File

@@ -0,0 +1,22 @@
/*
* @Author: jackning 270580156@qq.com
* @Date: 2024-01-31 16:12:40
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-01-31 16:29:07
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* 仅支持企业内部员工自用严禁用于销售、二次销售或者部署SaaS方式销售
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
* contact: 270580156@qq.com
* 联系270580156@qq.com
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
*/
package com.bytedesk.team;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class OrganizationRestTests {
}

View File

@@ -0,0 +1,66 @@
/*
* @Author: jackning 270580156@qq.com
* @Date: 2024-02-02 10:27:57
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-02-02 10:42:06
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* 仅支持企业内部员工自用严禁私自用于销售、二次销售或者部署SaaS方式销售
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
* contact: 270580156@qq.com
* 联系270580156@qq.com
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
*/
package com.bytedesk.team;
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 com.bytedesk.core.auth.AuthService;
import com.bytedesk.team.organization.OrganizationRepository;
import com.bytedesk.team.organization.OrganizationService;
@ExtendWith(MockitoExtension.class)
public class OrganizationServiceTests {
@Mock
private AuthService authService;
@Mock
private OrganizationRepository organizationRepository;
@InjectMocks
private OrganizationService organizationService;
@BeforeEach
public void setUp() {
// 初始化测试环境
}
@Test
public void testQueryMyOrgs() {
// Arrange
// PageParam pageParam = new PageParam().setPage(0).setSize(20);
// User mockUser = new User();
// Page<Organization> mockPage = new Page<>(Collections.singletonList(new
// Organization()), 1, 10, 100);
// when(authService.getCurrentUser()).thenReturn(mockUser);
// when(organizationRepository.findByUser(any(User.class),
// any(Pageable.class))).thenReturn(mockPage);
// // Act
// Page<Organization> result = organizationService.queryMyOrgs(pageParam);
// // Assert
// assertNotNull(result);
// assertEquals(1, result.getTotalPages());
// assertEquals(10, result.getTotalElements());
// assertEquals(1, result.getNumberOfElements());
}
}

View File

@@ -0,0 +1,13 @@
package com.bytedesk.team;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class TeamApplicationTests {
@Test
void contextLoads() {
}
}