-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: Vote쪽 Sent Votes 로직 수정 * refactor: SentVotes 스펙 변경 완료 * test: 스펙 변경 이후 테스트 수정 * test: CompleteBallotTest 추가 * feat: Notification 목록 조회에 Cursor Based Pagination 적용 * feat: CursorBased Pagination 적용 * test: 테스트 수정 * refactor: 사용하지 않는 메서드 제거 * test: Fixture 추가 * test: CursorBased Repository Test 추가 * refactor: VoteId 추가 및 테스트 보강 * chore: UserSettings CustomUrlFilter에 추가 * refactor: CursorUtils 사용
- Loading branch information
Showing
40 changed files
with
522 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...test/kotlin/com/wespot/notification/infrastructure/mysql/NotificationJpaRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.wespot.notification.infrastructure.mysql | ||
|
||
import com.wespot.notification.NotificationJpaEntity | ||
import com.wespot.notification.NotificationJpaRepository | ||
import com.wespot.notification.NotificationMapper | ||
import com.wespot.notification.NotificationType | ||
import com.wespot.notification.fixtrue.NotificationFixture | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest | ||
|
||
@DataJpaTest | ||
class NotificationJpaRepositoryTest @Autowired constructor( | ||
private val notificationJpaRepository: NotificationJpaRepository | ||
) { | ||
|
||
@Test | ||
fun `알림 목록 조회에 Cursor Based Pagination을 도입한다`() { | ||
// given | ||
val notification1 = createSavedNotification() | ||
val notification2 = createSavedNotification() | ||
val notification3 = createSavedNotification() | ||
val notification4 = createSavedNotification() | ||
val notification5 = createSavedNotification() | ||
val userId = notification1.userId | ||
|
||
// when | ||
val firstSearch = | ||
notificationJpaRepository.findAllByUserIdOrderByBaseEntityCreatedAtDesc(userId, Long.MAX_VALUE, 3) | ||
val secondSearch = | ||
notificationJpaRepository.findAllByUserIdOrderByBaseEntityCreatedAtDesc(userId, firstSearch[2].id, 4) | ||
|
||
// then | ||
firstSearch.size shouldBe 3 | ||
firstSearch[0] shouldBe notification5 | ||
firstSearch[1] shouldBe notification4 | ||
firstSearch[2] shouldBe notification3 | ||
secondSearch.size shouldBe 2 | ||
secondSearch[0] shouldBe notification2 | ||
secondSearch[1] shouldBe notification1 | ||
} | ||
|
||
private fun createSavedNotification(): NotificationJpaEntity { | ||
val notification = NotificationFixture.createWithType(NotificationType.MESSAGE) | ||
val notificationJpaEntity = NotificationMapper.mapToJpaEntity(notification) | ||
|
||
return notificationJpaRepository.save(notificationJpaEntity) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/test/kotlin/com/wespot/vote/domain/CompleteBallotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.wespot.vote.domain | ||
|
||
import com.wespot.user.fixture.UserFixture | ||
import com.wespot.vote.CompleteBallot | ||
import com.wespot.vote.fixture.BallotFixture | ||
import com.wespot.vote.fixture.VoteFixture | ||
import com.wespot.voteoption.fixture.VoteOptionFixture | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
|
||
class CompleteBallotTest : BehaviorSpec({ | ||
|
||
given("완전한 투표지를 만들 때") { | ||
val ballot = | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1, 1, 1, 2) | ||
val validSender = UserFixture.createWithId(1) | ||
val invalidSender = UserFixture.createWithId(2) | ||
val validReceiver = UserFixture.createWithId(2) | ||
val invalidReceiver = UserFixture.createWithId(1) | ||
val validVote = VoteFixture.createWithIdAndVoteNumberAndBallots(1, 0, emptyList()) | ||
val invalidVote = VoteFixture.createWithIdAndVoteNumberAndBallots(2, 0, emptyList()) | ||
val validVoteOption = VoteOptionFixture.createWithId(1) | ||
val invalidVoteOption = VoteOptionFixture.createWithId(2) | ||
`when`("입력된 값이 투표지와 동일하지 않다면") { | ||
val shouldThrow1 = shouldThrow<IllegalArgumentException> { | ||
CompleteBallot.of( | ||
invalidVote, | ||
validVoteOption, | ||
validSender, | ||
validReceiver, | ||
ballot | ||
) | ||
} | ||
val shouldThrow2 = shouldThrow<IllegalArgumentException> { | ||
CompleteBallot.of( | ||
validVote, | ||
invalidVoteOption, | ||
validSender, | ||
validReceiver, | ||
ballot | ||
) | ||
} | ||
val shouldThrow3 = shouldThrow<IllegalArgumentException> { | ||
CompleteBallot.of( | ||
validVote, | ||
validVoteOption, | ||
invalidSender, | ||
validReceiver, | ||
ballot | ||
) | ||
} | ||
val shouldThrow4 = shouldThrow<IllegalArgumentException> { | ||
CompleteBallot.of( | ||
validVote, | ||
validVoteOption, | ||
validSender, | ||
invalidReceiver, | ||
ballot | ||
) | ||
} | ||
then("예외가 발생한다.") { | ||
shouldThrow1 shouldHaveMessage "입력된 투표가 잘못되었습니다." | ||
shouldThrow2 shouldHaveMessage "입력된 선택지가 잘못되었습니다." | ||
shouldThrow3 shouldHaveMessage "입력된 송신자가 잘못되었습니다." | ||
shouldThrow4 shouldHaveMessage "입력된 수신자가 잘못되었습니다." | ||
} | ||
} | ||
`when`("정상적인 값이 입력된다면") { | ||
val completeBallot = CompleteBallot.of(validVote, validVoteOption, validSender, validReceiver, ballot) | ||
then("정상적으로 생성된다.") { | ||
completeBallot.vote shouldBe validVote | ||
completeBallot.voteOption shouldBe validVoteOption | ||
completeBallot.sender shouldBe validSender | ||
completeBallot.receiver shouldBe validReceiver | ||
completeBallot.createdAt shouldBe ballot.createdAt | ||
completeBallot.updatedAt shouldBe ballot.updatedAt | ||
completeBallot.isReceiverRead shouldBe ballot.isReceiverRead | ||
} | ||
} | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.