|
|
|
@ -12,6 +12,7 @@ import com.mydreamjob.job.JobService; |
|
|
|
import com.mydreamjob.review.dto.AdminCompanyReviewReplyResponse; |
|
|
|
import com.mydreamjob.review.dto.CompanyReviewReplyCreateRequest; |
|
|
|
import com.mydreamjob.review.dto.CompanyReviewReplyUpdateRequest; |
|
|
|
import com.mydreamjob.review.dto.ReviewReplyStatsResponse; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
@ -395,6 +396,71 @@ class CompanyReviewReplyServiceTest { |
|
|
|
assertEquals(COMPANY_USER_ID, v.getCompanyUserId()); |
|
|
|
} |
|
|
|
|
|
|
|
// ── 回复率统计(企业侧) ──────────────────────────────────
|
|
|
|
|
|
|
|
@Test void getReviewReplyStats_shouldComputeMonthRateAndIndustryAvg() { |
|
|
|
when(companyRepository.findByOwnerUserId(COMPANY_USER_ID)) |
|
|
|
.thenReturn(Optional.of(Company.builder().id(COMPANY_ID) |
|
|
|
.ownerUserId(COMPANY_USER_ID).industry("IT").build())); |
|
|
|
when(replyRepository.findMonthlyReplyStats(any(), any(), any(), any())).thenReturn(List.of( |
|
|
|
new Object[]{COMPANY_ID, 5L, 4L}, // 当前企业:80%
|
|
|
|
new Object[]{OTHER_COMPANY_ID, 4L, 2L})); // 同行企业:50%
|
|
|
|
|
|
|
|
ReviewReplyStatsResponse r = replyService.getReviewReplyStats(COMPANY_USER_ID); |
|
|
|
|
|
|
|
assertEquals(80, r.getMonthReplyRate()); |
|
|
|
assertEquals(65, r.getIndustryAvgReplyRate()); // (0.8+0.5)/2 = 0.65
|
|
|
|
assertEquals(1, r.getUnrepliedCount()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test void getReviewReplyStats_noReplies_shouldReturnZeroRate() { |
|
|
|
when(companyRepository.findByOwnerUserId(COMPANY_USER_ID)) |
|
|
|
.thenReturn(Optional.of(Company.builder().id(COMPANY_ID) |
|
|
|
.ownerUserId(COMPANY_USER_ID).industry("IT").build())); |
|
|
|
when(replyRepository.findMonthlyReplyStats(any(), any(), any(), any())) |
|
|
|
.thenReturn(List.<Object[]>of(new Object[]{COMPANY_ID, 2L, 0L})); |
|
|
|
|
|
|
|
ReviewReplyStatsResponse r = replyService.getReviewReplyStats(COMPANY_USER_ID); |
|
|
|
|
|
|
|
assertEquals(0, r.getMonthReplyRate()); |
|
|
|
assertEquals(2, r.getUnrepliedCount()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test void getReviewReplyStats_noReviewsThisMonth_shouldReturnZeros() { |
|
|
|
when(companyRepository.findByOwnerUserId(COMPANY_USER_ID)) |
|
|
|
.thenReturn(Optional.of(Company.builder().id(COMPANY_ID) |
|
|
|
.ownerUserId(COMPANY_USER_ID).industry("IT").build())); |
|
|
|
when(replyRepository.findMonthlyReplyStats(any(), any(), any(), any())).thenReturn(List.of()); |
|
|
|
|
|
|
|
ReviewReplyStatsResponse r = replyService.getReviewReplyStats(COMPANY_USER_ID); |
|
|
|
|
|
|
|
assertEquals(0, r.getMonthReplyRate()); |
|
|
|
assertEquals(0, r.getIndustryAvgReplyRate()); |
|
|
|
assertEquals(0, r.getUnrepliedCount()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test void getReviewReplyStats_companyWithoutIndustry_shouldSetIndustryAvgZero() { |
|
|
|
when(companyRepository.findByOwnerUserId(COMPANY_USER_ID)) |
|
|
|
.thenReturn(Optional.of(Company.builder().id(COMPANY_ID) |
|
|
|
.ownerUserId(COMPANY_USER_ID).industry(null).build())); |
|
|
|
when(replyRepository.findMonthlyReplyStats(any(), any(), any(), any())) |
|
|
|
.thenReturn(List.<Object[]>of(new Object[]{COMPANY_ID, 5L, 4L})); |
|
|
|
|
|
|
|
ReviewReplyStatsResponse r = replyService.getReviewReplyStats(COMPANY_USER_ID); |
|
|
|
|
|
|
|
assertEquals(80, r.getMonthReplyRate()); |
|
|
|
assertEquals(0, r.getIndustryAvgReplyRate()); |
|
|
|
assertEquals(1, r.getUnrepliedCount()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test void getReviewReplyStats_companyUserWithoutCompany_shouldReturn403() { |
|
|
|
when(companyRepository.findByOwnerUserId(COMPANY_USER_ID)).thenReturn(Optional.empty()); |
|
|
|
|
|
|
|
BusinessException ex = assertThrows(BusinessException.class, |
|
|
|
() -> replyService.getReviewReplyStats(COMPANY_USER_ID)); |
|
|
|
assertEquals(ErrorCode.FORBIDDEN.getCode(), ex.getErrorCodeInt()); |
|
|
|
} |
|
|
|
|
|
|
|
private Long ADMIN_ROLE_ID() { |
|
|
|
return 1L; |
|
|
|
} |
|
|
|
|