|
|
@@ -1,8 +1,13 @@
|
|
|
package com.yimeng.okr.service;
|
|
|
+import org.mockito.junit.jupiter.MockitoSettings;
|
|
|
+import org.mockito.quality.Strictness;
|
|
|
|
|
|
import com.yimeng.okr.entity.AssessmentPeriod;
|
|
|
import com.yimeng.okr.entity.AuditCorrection;
|
|
|
import com.yimeng.okr.entity.PerformanceScore;
|
|
|
+import com.yimeng.okr.entity.PerformanceFeedback;
|
|
|
+import com.yimeng.okr.dto.OkrDetailDto;
|
|
|
+import com.yimeng.okr.dto.ScoringDto;
|
|
|
import com.yimeng.okr.entity.SysUser;
|
|
|
import com.yimeng.okr.enums.PeriodStatus;
|
|
|
import com.yimeng.okr.enums.ScoreType;
|
|
|
@@ -24,6 +29,7 @@ import static org.mockito.ArgumentMatchers.*;
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
+@MockitoSettings(strictness = Strictness.LENIENT)
|
|
|
class PerformanceServiceTest {
|
|
|
|
|
|
@Mock PerformanceScoreMapper scoreMapper;
|
|
|
@@ -35,6 +41,11 @@ class PerformanceServiceTest {
|
|
|
@Mock OkrService okrService;
|
|
|
@Mock AuthorizationService authorizationService;
|
|
|
@Mock ApplicationEventPublisher publisher;
|
|
|
+ private PerformanceScore selfScore;
|
|
|
+ private PerformanceScore finalScore;
|
|
|
+ private PerformanceFeedback feedback;
|
|
|
+ private PerformanceScoreItem sampleItem;
|
|
|
+ private OkrDetailDto okrDetail;
|
|
|
@InjectMocks PerformanceService performanceService;
|
|
|
|
|
|
@Test
|
|
|
@@ -245,7 +256,7 @@ class PerformanceServiceTest {
|
|
|
|
|
|
private AssessmentPeriod period() {
|
|
|
AssessmentPeriod period = new AssessmentPeriod();
|
|
|
- period.setId(1L);
|
|
|
+ period.setId(1L); period.setStartDate(java.time.LocalDate.of(2026,1,1)); period.setEndDate(java.time.LocalDate.of(2026,12,31));
|
|
|
period.setStatus(PeriodStatus.ASSESSING);
|
|
|
return period;
|
|
|
}
|
|
|
@@ -300,4 +311,96 @@ class PerformanceServiceTest {
|
|
|
assertEquals(8.0, dimItem.getScore());
|
|
|
assertEquals(10.0, dimItem.getMaxScore());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void selfCannotSeeUnpublishedFinalItems() {
|
|
|
+ setupPrivacyMocks(1L, 2L, 2L, "SELF_SUBMITTED", "PENDING_PUBLISH");
|
|
|
+
|
|
|
+ ScoringDto dto = performanceService.getScoringPage(1L, 2L, 2L);
|
|
|
+
|
|
|
+ assertNull(dto.getFinalScore(), "Self should not see unpublished final score");
|
|
|
+ assertNull(dto.getFinalItems(), "Self should not see unpublished final items");
|
|
|
+ assertNotNull(dto.getSelfScore(), "Self can see their self score");
|
|
|
+ assertNotNull(dto.getSelfItems(), "Self can see their self items");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void superiorCannotSeeSelfItems() {
|
|
|
+ setupPrivacyMocks(1L, 2L, 3L, "SELF_SUBMITTED", "PUBLISHED");
|
|
|
+
|
|
|
+ ScoringDto dto = performanceService.getScoringPage(1L, 2L, 3L);
|
|
|
+
|
|
|
+ assertNotNull(dto.getSelfScore(), "Superior can see self score exists");
|
|
|
+ assertNull(dto.getSelfScore().getCommentsJson(), "Superior should not see self commentsJson");
|
|
|
+ assertNull(dto.getSelfItems(), "Superior should not see selfItems");
|
|
|
+ assertNotNull(dto.getFinalScore(), "Superior can see final score");
|
|
|
+ assertNotNull(dto.getFinalItems(), "Superior can see final items");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void hrCanSeeAllItems() {
|
|
|
+ setupPrivacyMocks(1L, 2L, 99L, "SELF_SUBMITTED", "PUBLISHED"); when(authorizationService.isHrOrAbove(99L)).thenReturn(true);
|
|
|
+
|
|
|
+ ScoringDto dto = performanceService.getScoringPage(1L, 2L, 99L);
|
|
|
+
|
|
|
+ assertNotNull(dto.getSelfScore());
|
|
|
+ assertNotNull(dto.getSelfItems());
|
|
|
+ assertNotNull(dto.getFinalScore());
|
|
|
+ assertNotNull(dto.getFinalItems());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void selfCanSeePublishedFinalItems() {
|
|
|
+ setupPrivacyMocks(1L, 2L, 2L, "SELF_SUBMITTED", "PUBLISHED");
|
|
|
+
|
|
|
+ ScoringDto dto = performanceService.getScoringPage(1L, 2L, 2L);
|
|
|
+
|
|
|
+ assertNotNull(dto.getFinalScore(), "Self can see published final score");
|
|
|
+ assertNotNull(dto.getFinalItems(), "Self can see published final items");
|
|
|
+ assertNotNull(dto.getSelfScore(), "Self can see their self score");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setupPrivacyMocks(Long periodId, Long userId, Long actorId,
|
|
|
+ String selfStatus, String finalStatus) {
|
|
|
+ lenient().when(periodMapper.selectById(periodId)).thenReturn(period());
|
|
|
+ SysUser targetUser = user(userId, 3L);
|
|
|
+ lenient().when(userMapper.selectById(userId)).thenReturn(targetUser);
|
|
|
+ lenient().doNothing().when(authorizationService).requireCanViewUserData(actorId, userId);
|
|
|
+
|
|
|
+ selfScore = new PerformanceScore();
|
|
|
+ selfScore.setId(10L);
|
|
|
+ selfScore.setPeriodId(periodId);
|
|
|
+ selfScore.setUserId(userId);
|
|
|
+ selfScore.setType(ScoreType.SELF);
|
|
|
+ selfScore.setStatus(selfStatus);
|
|
|
+ selfScore.setOkrScore(50.0);
|
|
|
+ selfScore.setKpiScore(30.0);
|
|
|
+ selfScore.setCommentsJson("{\"details\":\"self\"}");
|
|
|
+
|
|
|
+ finalScore = new PerformanceScore();
|
|
|
+ finalScore.setId(20L);
|
|
|
+ finalScore.setPeriodId(periodId);
|
|
|
+ finalScore.setUserId(userId);
|
|
|
+ finalScore.setType(ScoreType.FINAL);
|
|
|
+ finalScore.setStatus(finalStatus);
|
|
|
+ finalScore.setTotal(80.0);
|
|
|
+ finalScore.setGrade(com.yimeng.okr.enums.Grade.A);
|
|
|
+
|
|
|
+ sampleItem = new PerformanceScoreItem();
|
|
|
+ sampleItem.setId(1L);
|
|
|
+ sampleItem.setScoreId(10L);
|
|
|
+ sampleItem.setItemType("KR");
|
|
|
+ sampleItem.setScore(0.8);
|
|
|
+
|
|
|
+ okrDetail = new OkrDetailDto();
|
|
|
+ okrDetail.setUserId(userId);
|
|
|
+ okrDetail.setPeriodId(periodId);
|
|
|
+
|
|
|
+ lenient().when(scoreMapper.selectOne(any())).thenReturn(selfScore, finalScore);
|
|
|
+ lenient().when(scoreItemMapper.selectList(any())).thenReturn(List.of(sampleItem));
|
|
|
+ lenient().when(okrService.getMyOkr(periodId, userId)).thenReturn(okrDetail);
|
|
|
+ feedback = new PerformanceFeedback();
|
|
|
+ lenient().when(feedbackMapper.selectOne(any())).thenReturn(feedback);
|
|
|
+ }
|
|
|
+
|
|
|
}
|