Skip to content

Commit

Permalink
refactor: VoteId 추가 및 테스트 보강
Browse files Browse the repository at this point in the history
  • Loading branch information
kpeel5839 committed Aug 8, 2024
1 parent 94d05ea commit 2aafd3d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ class InquiryNotificationServiceTest @Autowired constructor(
)

// when
val responses = inquiryNotificationService.getNotifications(null, 1).notifications
val responses1 = inquiryNotificationService.getNotifications(null, 1)
val responses2= inquiryNotificationService.getNotifications(responses1.notifications[0].id, 1)

// then
responses.size shouldBe 1
responses[0].id shouldBe savedNotification.id
responses1.notifications.size shouldBe 1
responses1.notifications[0].id shouldBe savedNotification.id
responses1.hasNext shouldBe true
responses2.notifications.size shouldBe 1
responses2.notifications[0].id shouldBe notifications[0].id
responses2.hasNext shouldBe false
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,28 @@ class ReceivedVoteServiceTest @Autowired constructor(
)

// when
val receivedVotes = receivedVoteService.getReceivedVotes(null, 100)
val receivedVotes1 = receivedVoteService.getReceivedVotes(null, 100)
val receivedVotes2 = receivedVoteService.getReceivedVotes(null, 1)
val receivedVotes3 = receivedVoteService.getReceivedVotes(receivedVotes2.voteData[0].voteId, 1)

// then
receivedVotes.voteData.size shouldBe 2
receivedVotes.voteData[0].date shouldBe plusOneMinute.toLocalDate().toString()
receivedVotes.voteData[0].receivedVoteResults.size shouldBe 2
receivedVotes.voteData[0].receivedVoteResults[0].voteOption.id shouldBe voteOptions[5].id
receivedVotes.voteData[0].receivedVoteResults[0].voteCount shouldBe 1
receivedVotes.voteData[0].receivedVoteResults[0].isNew shouldBe true
receivedVotes.voteData[0].receivedVoteResults[1].voteOption.id shouldBe voteOptions[6].id
receivedVotes.voteData[0].receivedVoteResults[1].voteCount shouldBe 1
receivedVotes.voteData[0].receivedVoteResults[1].isNew shouldBe true
receivedVotes.voteData[1].date shouldBe now.minusDays(1).toLocalDate().toString()
receivedVotes.voteData[1].receivedVoteResults.size shouldBe 0
receivedVotes1.voteData.size shouldBe 2
receivedVotes1.voteData[0].date shouldBe plusOneMinute.toLocalDate().toString()
receivedVotes1.voteData[0].receivedVoteResults.size shouldBe 2
receivedVotes1.voteData[0].receivedVoteResults[0].voteOption.id shouldBe voteOptions[5].id
receivedVotes1.voteData[0].receivedVoteResults[0].voteCount shouldBe 1
receivedVotes1.voteData[0].receivedVoteResults[0].isNew shouldBe true
receivedVotes1.voteData[0].receivedVoteResults[1].voteOption.id shouldBe voteOptions[6].id
receivedVotes1.voteData[0].receivedVoteResults[1].voteCount shouldBe 1
receivedVotes1.voteData[0].receivedVoteResults[1].isNew shouldBe true
receivedVotes1.voteData[1].date shouldBe now.minusDays(1).toLocalDate().toString()
receivedVotes1.voteData[1].receivedVoteResults.size shouldBe 0
receivedVotes2.voteData.size shouldBe 1
receivedVotes2.voteData[0].voteId shouldBe vote1!!.id
receivedVotes2.hasNext shouldBe true
receivedVotes3.voteData.size shouldBe 1
receivedVotes3.voteData[0].voteId shouldBe vote2!!.id
receivedVotes3.hasNext shouldBe false
}

@Test
Expand Down
29 changes: 19 additions & 10 deletions app/src/test/kotlin/com/wespot/vote/service/SentVoteServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,27 @@ class SentVoteServiceTest @Autowired constructor(
)

// when
val sentVotes = sentVoteService.getSentVotes(null, 100)
val sentVotes1 = sentVoteService.getSentVotes(null, 100)
val sentVotes2 = sentVoteService.getSentVotes(null, 1)
val sentVotes3 = sentVoteService.getSentVotes(sentVotes1.voteData[0].voteId, 1)

// then
sentVotes.voteData.size shouldBe 2
sentVotes.voteData[0].date shouldBe now.toLocalDate().toString()
sentVotes.voteData[0].sentVoteResults.size shouldBe 2
sentVotes.voteData[0].sentVoteResults[0].vote.voteOption.id shouldBe voteOptions[5].id
sentVotes.voteData[0].sentVoteResults[1].vote.voteOption.id shouldBe voteOptions[7].id
sentVotes.voteData[0].sentVoteResults[0].vote.user.id shouldBe users[1].id
sentVotes.voteData[0].sentVoteResults[1].vote.user.id shouldBe users[2].id
sentVotes.voteData[1].date shouldBe now.minusDays(1).toLocalDate().toString()
sentVotes.voteData[1].sentVoteResults.size shouldBe 0
sentVotes1.voteData.size shouldBe 2
sentVotes1.voteData[0].date shouldBe now.toLocalDate().toString()
sentVotes1.voteData[0].sentVoteResults.size shouldBe 2
sentVotes1.voteData[0].sentVoteResults[0].vote.voteOption.id shouldBe voteOptions[5].id
sentVotes1.voteData[0].sentVoteResults[1].vote.voteOption.id shouldBe voteOptions[7].id
sentVotes1.voteData[0].sentVoteResults[0].vote.user.id shouldBe users[1].id
sentVotes1.voteData[0].sentVoteResults[1].vote.user.id shouldBe users[2].id
sentVotes1.voteData[1].date shouldBe now.minusDays(1).toLocalDate().toString()
sentVotes1.voteData[1].sentVoteResults.size shouldBe 0
sentVotes1.hasNext shouldBe false
sentVotes2.voteData.size shouldBe 1
sentVotes2.voteData[0].voteId shouldBe vote1!!.id
sentVotes2.hasNext shouldBe true
sentVotes3.voteData.size shouldBe 1
sentVotes3.voteData[0].voteId shouldBe vote2!!.id
sentVotes3.hasNext shouldBe false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wespot.vote.VoteRecord
import com.wespot.voteoption.VoteOption

data class ReceivedVotesResponse(
val voteId: Long,
val date: String,
val receivedVoteResults: List<ReceivedVotesResultResponses>
) {
Expand All @@ -13,6 +14,7 @@ data class ReceivedVotesResponse(

fun of(vote: Vote, voteResults: Map<VoteOption, VoteRecord>): ReceivedVotesResponse {
return ReceivedVotesResponse(
vote.id,
vote.voteIdentifier.date.toString(),
voteResults.map { ReceivedVotesResultResponses.of(it.key, it.value) }
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.wespot.vote.CompleteBallot
import com.wespot.vote.Vote

data class SentVotesResponse(
val voteId: Long,
val date: String,
val sentVoteResults: List<SentVotesResultsResponse>
) {
Expand All @@ -12,6 +13,7 @@ data class SentVotesResponse(

fun of(vote: Vote, ballots: List<CompleteBallot>): SentVotesResponse {
return SentVotesResponse(
vote.id,
vote.voteIdentifier.date.toString(),
ballots.map { SentVotesResultsResponse.of(it) }
)
Expand Down

0 comments on commit 2aafd3d

Please sign in to comment.