|
| 1 | +package com.depromeet.whatnow.domains.picture.service |
| 2 | + |
| 3 | +import com.depromeet.whatnow.common.vo.CoordinateVo |
| 4 | +import com.depromeet.whatnow.domains.picture.adapter.PictureAdapter |
| 5 | +import com.depromeet.whatnow.domains.picture.domain.PictureCommentType |
| 6 | +import com.depromeet.whatnow.domains.picture.exception.CancelledUserUploadException |
| 7 | +import com.depromeet.whatnow.domains.picture.exception.InvalidCommentTypeException |
| 8 | +import com.depromeet.whatnow.domains.picture.exception.UploadBeforeTrackingException |
| 9 | +import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor |
| 10 | +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser |
| 11 | +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType |
| 12 | +import org.assertj.core.api.Assertions |
| 13 | +import org.junit.jupiter.api.Test |
| 14 | +import org.junit.jupiter.api.extension.ExtendWith |
| 15 | +import org.mockito.ArgumentMatchers.anyLong |
| 16 | +import org.mockito.InjectMocks |
| 17 | +import org.mockito.Mock |
| 18 | +import org.mockito.junit.jupiter.MockitoExtension |
| 19 | +import org.mockito.kotlin.given |
| 20 | + |
| 21 | +@ExtendWith(MockitoExtension::class) |
| 22 | +class PictureDomainServiceTest { |
| 23 | + @Mock |
| 24 | + lateinit var pictureAdapter: PictureAdapter |
| 25 | + |
| 26 | + @Mock |
| 27 | + lateinit var promiseUserAdapter: PromiseUserAdaptor |
| 28 | + |
| 29 | + @InjectMocks |
| 30 | + lateinit var pictureDomainService: PictureDomainService |
| 31 | + |
| 32 | + @Test |
| 33 | + fun `사진 업로드 성공 요청시 정상적이라면 에러를 반환하지 않는다`() { |
| 34 | + // given |
| 35 | + val promiseUser = PromiseUser( |
| 36 | + promiseId = 1, |
| 37 | + userId = 1, |
| 38 | + userLocation = CoordinateVo(1.0, 1.0), |
| 39 | + promiseUserType = PromiseUserType.LATE, |
| 40 | + ) |
| 41 | + given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) |
| 42 | + .willReturn(promiseUser) |
| 43 | + |
| 44 | + // when, then |
| 45 | + Assertions.assertThatCode { |
| 46 | + pictureDomainService.successUploadImage(1, 1, "imageKey", PictureCommentType.RUNNING) |
| 47 | + }.doesNotThrowAnyException() |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + fun `유저가 READY 상태라면 예외가 발생한다`() { |
| 52 | + // given |
| 53 | + val promiseUser = PromiseUser( |
| 54 | + promiseId = 1, |
| 55 | + userId = 1, |
| 56 | + userLocation = CoordinateVo(1.0, 1.0), |
| 57 | + promiseUserType = PromiseUserType.READY, |
| 58 | + ) |
| 59 | + given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) |
| 60 | + .willReturn(promiseUser) |
| 61 | + |
| 62 | + // when, then |
| 63 | + Assertions.assertThatThrownBy { |
| 64 | + pictureDomainService.successUploadImage(1, 1, "imageKey", PictureCommentType.RUNNING) |
| 65 | + }.isInstanceOf(UploadBeforeTrackingException::class.java) |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + fun `유저가 CANCEL 상태라면 예외가 발생한다`() { |
| 70 | + // given |
| 71 | + val promiseUser = PromiseUser( |
| 72 | + promiseId = 1, |
| 73 | + userId = 1, |
| 74 | + userLocation = CoordinateVo(1.0, 1.0), |
| 75 | + promiseUserType = PromiseUserType.CANCEL, |
| 76 | + ) |
| 77 | + given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) |
| 78 | + .willReturn(promiseUser) |
| 79 | + |
| 80 | + // when, then |
| 81 | + Assertions.assertThatThrownBy { |
| 82 | + pictureDomainService.successUploadImage(1, 1, "imageKey", PictureCommentType.RUNNING) |
| 83 | + }.isInstanceOf(CancelledUserUploadException::class.java) |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + fun `LATE 유저가 WAIT 타입의 코멘트를 입력 할 경우 예외가 발생한다`() { |
| 88 | + // given |
| 89 | + val promiseUser = PromiseUser( |
| 90 | + promiseId = 1, |
| 91 | + userId = 1, |
| 92 | + userLocation = CoordinateVo(1.0, 1.0), |
| 93 | + promiseUserType = PromiseUserType.LATE, |
| 94 | + ) |
| 95 | + given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) |
| 96 | + .willReturn(promiseUser) |
| 97 | + |
| 98 | + // when, then |
| 99 | + Assertions.assertThatThrownBy { |
| 100 | + pictureDomainService.successUploadImage(1, 1, "imageKey", PictureCommentType.DID_YOU_COME) |
| 101 | + }.isInstanceOf(InvalidCommentTypeException::class.java) |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + fun `WAIT 유저가 LATE 타입의 코멘트를 입력 할 경우 예외가 발생한다`() { |
| 106 | + // given |
| 107 | + val promiseUser = PromiseUser( |
| 108 | + promiseId = 1, |
| 109 | + userId = 1, |
| 110 | + userLocation = CoordinateVo(1.0, 1.0), |
| 111 | + promiseUserType = PromiseUserType.WAIT, |
| 112 | + ) |
| 113 | + given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) |
| 114 | + .willReturn(promiseUser) |
| 115 | + |
| 116 | + // when, then |
| 117 | + Assertions.assertThatThrownBy { |
| 118 | + pictureDomainService.successUploadImage(1, 1, "imageKey", PictureCommentType.WAIT_A_BIT) |
| 119 | + }.isInstanceOf(InvalidCommentTypeException::class.java) |
| 120 | + } |
| 121 | +} |
0 commit comments