Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…p3/Team8_BE into Feat/issue-#127
  • Loading branch information
GitJIHO committed Oct 31, 2024
2 parents 8d19e08 + 53151a3 commit b6e5599
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ public CallbackForSinittoResponse getCallbackForSinitto(Long memberId, Long call
Callback callback = callbackRepository.findById(callbackId)
.orElseThrow(() -> new NotFoundException("ν•΄λ‹Ή 콜백 id에 ν•΄λ‹Ήν•˜λŠ” 콜백이 μ—†μŠ΅λ‹ˆλ‹€."));

if (callback.getAssignedMemberId().equals(memberId)) {
return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), true, callback.getSenior().getPhoneNumber());
if (!callback.getStatus().equals(Callback.Status.WAITING.toString())) {
if (callback.getAssignedMemberId() != null && callback.getAssignedMemberId().equals(memberId)) {
return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), true, callback.getSenior().getPhoneNumber());
}
throw new ForbiddenException("λŒ€κΈ°μ€‘μΈ 콜백이 μ•„λ‹Œκ²½μš° 였직 할당받은 μ‹œλ‹ˆλ˜λ§Œμ΄ μ½œλ°±μ„ μ‘°νšŒν•  수 μžˆμŠ΅λ‹ˆλ‹€.");
}

return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), false, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void localDateTimeBeforeCalculateTest() {
}

@Test
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - api ν˜ΈμΆœν•œ μ‹œλ‹ˆλ˜ 본인이 ν• λ‹Ήλœ 콜백일 경우")
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - 1.λŒ€κΈ°μƒνƒœ μ•„λ‹˜ 2.AssignedMemberId 이 null μ•„λ‹˜ + ν•΄λ‹Ή μ½œλ°±μ— ν• λ‹Ή 된 μ‹œλ‹ˆλ˜ 맞음 ")
void getCallbackForSinitto() {
//given
Long memberId = 1L;
Expand All @@ -415,11 +415,12 @@ void getCallbackForSinitto() {
Senior senior = mock(Senior.class);

when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback));

when(callback.getStatus()).thenReturn(Callback.Status.IN_PROGRESS.toString());
when(callback.getAssignedMemberId()).thenReturn(1L);
when(callback.getId()).thenReturn(1L);
when(callback.getSeniorName()).thenReturn("SeniorName");
when(callback.getPostTime()).thenReturn(LocalDateTime.now());
when(callback.getStatus()).thenReturn(Callback.Status.WAITING.toString());
when(callback.getSeniorId()).thenReturn(1L);
when(callback.getSenior()).thenReturn(senior);
when(callback.getSenior().getPhoneNumber()).thenReturn("01012341234");
Expand All @@ -429,28 +430,57 @@ void getCallbackForSinitto() {

//then
assertTrue(result.isAssignedToSelf());
assertEquals("01012341234", result.seniorPhoneNumber());
}

@Test
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - api ν˜ΈμΆœν•œ μ‹œλ‹ˆλ˜ 본인이 ν• λ‹Ήλœ 콜백이 μ•„λ‹Œ 경우")
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - 1.λŒ€κΈ°μƒνƒœ μ•„λ‹˜ 2.AssignedMemberId 이 null 인 상황 ")
void getCallbackForSinitto2() {
//given
Long memberId = 1L;
Long callbackId = 1L;
Callback callback = mock(Callback.class);

when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback));
when(callback.getAssignedMemberId()).thenReturn(999L); // μ—¬κΈ°μ„œ μ‹œλ‹ˆλ˜ λ³ΈμΈμ—κ²Œ ν• λ‹Ήλœ 콜백이 μ•„λ‹Œκ±Έ 확인
when(callback.getId()).thenReturn(1L);
when(callback.getSeniorName()).thenReturn("SeniorName");
when(callback.getPostTime()).thenReturn(LocalDateTime.now());
when(callback.getAssignedMemberId()).thenReturn(null);
when(callback.getStatus()).thenReturn(Callback.Status.IN_PROGRESS.toString());

//when then
assertThrows(ForbiddenException.class, () -> callbackService.getCallbackForSinitto(memberId, callbackId));
}

@Test
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - 1.λŒ€κΈ°μƒνƒœ μ•„λ‹˜ 2.AssignedMemberId 이 null 은 μ•„λ‹Œλ° ν•΄λ‹Ή μ½œλ°±μ— ν• λ‹Ήλœ μ‹œλ‹ˆλ˜λŠ” μ•„λ‹Œ 상황")
void getCallbackForSinitto3() {
//given
Long memberId = 1L;
Long callbackId = 1L;
Callback callback = mock(Callback.class);

when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback));
when(callback.getAssignedMemberId()).thenReturn(999L);
when(callback.getStatus()).thenReturn(Callback.Status.IN_PROGRESS.toString());

//when then
assertThrows(ForbiddenException.class, () -> callbackService.getCallbackForSinitto(memberId, callbackId));
}

@Test
@DisplayName("μ‹œλ‹ˆλ˜μš© 콜백 단건 쑰회 - 1.콜백이 'λŒ€κΈ°μƒνƒœ' 인 경우(λͺ¨λ“  μ‹œλ‹ˆλ˜κ°€ 쑰회 κ°€λŠ₯ν•˜λ‹€)")
void getCallbackForSinitto4() {
//given
Long memberId = 1L;
Long callbackId = 1L;
Callback callback = mock(Callback.class);

when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback));
when(callback.getStatus()).thenReturn(Callback.Status.WAITING.toString());
when(callback.getSeniorId()).thenReturn(1L);

//when
CallbackForSinittoResponse result = callbackService.getCallbackForSinitto(memberId, callbackId);

//then
assertFalse(result.isAssignedToSelf());
assertEquals("", result.seniorPhoneNumber());
}
}

0 comments on commit b6e5599

Please sign in to comment.