feat: 添加面试邀约删除接口及相关服务实现

This commit is contained in:
2026-07-23 16:41:57 +08:00
parent 397e36144a
commit ba9f32fd02
6 changed files with 354 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
package com.ruoyi.cms.controller.app;
import com.ruoyi.cms.service.InterviewInvitationService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.domain.model.LoginSiteUser;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import java.lang.reflect.Field;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class AppInterviewControllerTest {
@AfterEach
void clearSecurityContext() {
SecurityContextHolder.clearContext();
}
@Test
void loggedInUserCanDeleteOneOrMoreOwnInvitations() throws Exception {
InterviewInvitationService service = mock(InterviewInvitationService.class);
when(service.deleteInterviewInvitationIdsByUserId(any(Long[].class), eq(12L))).thenReturn(2);
authenticateSiteUser(12L);
AppInterviewController controller = controllerWith(service);
AjaxResult result = controller.remove(new Long[]{10L, 11L});
ArgumentCaptor<Long[]> idsCaptor = ArgumentCaptor.forClass(Long[].class);
verify(service).deleteInterviewInvitationIdsByUserId(idsCaptor.capture(), eq(12L));
assertArrayEquals(new Long[]{10L, 11L}, idsCaptor.getValue());
assertEquals(200, result.get(AjaxResult.CODE_TAG));
}
@Test
void anonymousUserCannotDeleteInvitations() throws Exception {
InterviewInvitationService service = mock(InterviewInvitationService.class);
AppInterviewController controller = controllerWith(service);
AjaxResult result = controller.remove(new Long[]{10L});
assertEquals(500, result.get(AjaxResult.CODE_TAG));
assertEquals("未登录", result.get(AjaxResult.MSG_TAG));
verify(service, never()).deleteInterviewInvitationIdsByUserId(new Long[]{10L}, 12L);
}
private AppInterviewController controllerWith(InterviewInvitationService service) throws Exception {
AppInterviewController controller = new AppInterviewController();
Field field = AppInterviewController.class.getDeclaredField("interviewInvitationService");
field.setAccessible(true);
field.set(controller, service);
return controller;
}
private void authenticateSiteUser(Long userId) {
LoginSiteUser loginUser = new LoginSiteUser(userId, new AppUser());
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
loginUser, null, Collections.emptyList());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
}