-
Notifications
You must be signed in to change notification settings - Fork 0
#28,29 - 유저는 투표 결과를 조회할 수 있다. #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5b0a774
refactor: VoteUseCase 네이밍 변경
kpeel5839 3bd48f5
feat: VoteRank Service 정의
kpeel5839 9b10811
feat: API 정의
kpeel5839 bb765fa
feat: DTO 정의
kpeel5839 a501dcf
feat: 오늘의 질문지를 감싸는 객체 정의
kpeel5839 853840e
feat: VoteMetrics, VoteRecord 정의
kpeel5839 d7b1317
feat: Domain 로직 정의
kpeel5839 058a95c
refactor: 조회에는 Transactional 어노테이션 제거
kpeel5839 0d70fa1
feat: 순위 반환 서비스 로직 작성
kpeel5839 84175b5
refactor: SavedVoteService에서 Helper를 사용할 수 있도록 수정
kpeel5839 3735400
refactor: Response 명 변경
kpeel5839 033fb6d
refactor: Security Context에서 UserId를 뽑아낼 수 있도록 수정
kpeel5839 0bd40f4
refactor: 순환해서 질문지를 가져오지 않도록 수정
kpeel5839 a924c93
chore: submodule 가져오는 과정 ci에 추가
kpeel5839 0a206fd
test: 오늘의 질문지 테스트 작성
kpeel5839 2393cd7
test: VoteMetrics 테스트 작성
kpeel5839 9faf8c0
test: VoteRecord 테스트 작성
kpeel5839 b20251c
test: BallotsAggregator 테스트 작성
kpeel5839 1a175af
test: Vote 테스트 작성
kpeel5839 dec455b
test: VoteRankServiceTest 작성
kpeel5839 43e1841
chore: CustomUrlFilter에 valid url 추가
kpeel5839 36ad537
refactor: groupNumber->classNumber로 변경
kpeel5839 0f571bb
refactor: groupNumber->classNumber로 변경
kpeel5839 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
113 changes: 113 additions & 0 deletions
113
app/src/test/kotlin/com/wespot/vote/domain/BallotsAggregatorTest.kt
This file contains hidden or 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,113 @@ | ||
package com.wespot.vote.domain | ||
|
||
import com.wespot.vote.BallotsAggregator | ||
import com.wespot.vote.fixture.BallotFixture | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
import java.time.LocalDateTime | ||
|
||
class BallotsAggregatorTest : BehaviorSpec({ | ||
|
||
given("투표지 집계기를 생성할 때") { | ||
`when`("서로 다른 선택지에 대한 결과가 섞여 있으면") { | ||
then("예외가 발생한다.") { | ||
val shouldThrow = shouldThrow<IllegalArgumentException> { | ||
BallotsAggregator.of( | ||
1L, | ||
listOf(BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 2L, 1L, 2L)) | ||
) | ||
} | ||
shouldThrow shouldHaveMessage "서로 다른 질문지에 대한 결과가 섞였습니다." | ||
} | ||
} | ||
} | ||
|
||
given("투표지 집계기를 통해") { | ||
val calculateRankByBallotSize = listOf( | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 1L, 2L), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 2L, 3L), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 3L, 2L), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 4L, 3L), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 5L, 2L), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiver(1L, 1L, 6L, 4L), | ||
) | ||
`when`("득표수를 토대로") { | ||
val ballotsAggregator = BallotsAggregator.of(1L, calculateRankByBallotSize) | ||
val rankedResults = ballotsAggregator.getRankResults() | ||
then("정렬된 순서를 반환받는다.") { | ||
rankedResults[0].userId shouldBe 2 | ||
rankedResults[0].voteCount shouldBe 3 | ||
rankedResults[1].userId shouldBe 3 | ||
rankedResults[1].voteCount shouldBe 2 | ||
rankedResults[2].userId shouldBe 4 | ||
rankedResults[2].voteCount shouldBe 1 | ||
} | ||
} | ||
val calculateRankByBallotSizeAndReceivedAt = listOf( | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
1L, | ||
2L, | ||
LocalDateTime.now().minusHours(10) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
3L, | ||
2L, | ||
LocalDateTime.now().minusHours(10) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
5L, | ||
2L, | ||
LocalDateTime.now().minusHours(10) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
2L, | ||
3L, | ||
LocalDateTime.now().minusHours(10) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
4L, | ||
3L, | ||
LocalDateTime.now().minusHours(1) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
6L, | ||
4L, | ||
LocalDateTime.now().minusHours(2) | ||
), | ||
BallotFixture.createByVoteAndVoteOptionAndSenderAndReceiverAndCreatedAt( | ||
1L, | ||
1L, | ||
7L, | ||
4L, | ||
LocalDateTime.now().minusHours(2) | ||
), | ||
) | ||
`when`("득표수가 같다면, 가장 최근에 받은 투푠을 기준으로") { | ||
val ballotsAggregator = BallotsAggregator.of(1L, calculateRankByBallotSizeAndReceivedAt) | ||
val rankedResults = ballotsAggregator.getRankResults() | ||
then("정렬된 순서를 반환받는다.") { | ||
rankedResults[0].userId shouldBe 2 | ||
rankedResults[0].voteCount shouldBe 3 | ||
rankedResults[1].userId shouldBe 3 | ||
rankedResults[1].voteCount shouldBe 2 | ||
rankedResults[2].userId shouldBe 4 | ||
rankedResults[2].voteCount shouldBe 2 | ||
} | ||
} | ||
} | ||
|
||
}) |
This file contains hidden or 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,36 @@ | ||
package com.wespot.vote.domain | ||
|
||
import com.wespot.vote.Rate | ||
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 RateTest : BehaviorSpec({ | ||
|
||
given("Rate를 만들 때") { | ||
val validRate = 1 | ||
`when`("0 이하의 등수가 입력되면") { | ||
then("예외가 발생한다.") { | ||
val shouldThrow = shouldThrow<IllegalArgumentException> { Rate.from(0) } | ||
shouldThrow shouldHaveMessage "등수는 0 이하일 수 없습니다." | ||
} | ||
} | ||
`when`("정상적인 값이 입력되면") { | ||
val rate = Rate.from(validRate) | ||
then("정상적으로 생성된다.") { | ||
rate.value shouldBe validRate | ||
} | ||
} | ||
} | ||
|
||
given("의미없는") { | ||
`when`("Rate를 만들면") { | ||
val Rate = Rate.createMeaningLessRate() | ||
then("등수가 Int MAX VALUE로 설정되게 된다.") { | ||
Rate.value shouldBe Int.MAX_VALUE | ||
} | ||
} | ||
} | ||
|
||
}) |
50 changes: 50 additions & 0 deletions
50
app/src/test/kotlin/com/wespot/vote/domain/VoteMetricsTest.kt
This file contains hidden or 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,50 @@ | ||
package com.wespot.vote.domain | ||
|
||
import com.wespot.vote.VoteMetrics | ||
import com.wespot.vote.fixture.BallotFixture | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import java.time.LocalDateTime | ||
|
||
class VoteMetricsTest : BehaviorSpec({ | ||
|
||
given("초기의 VoteMetrics를") { | ||
val userId = 1L | ||
`when`("생성하면") { | ||
val voteMetrics = VoteMetrics.createInitialState(userId) | ||
then("정상적으로 생성된다.") { | ||
voteMetrics.userId shouldBe userId | ||
voteMetrics.lastVotedDateTime shouldBe LocalDateTime.MIN | ||
voteMetrics.voteCount shouldBe 0 | ||
voteMetrics.isReceiverRead shouldBe true | ||
} | ||
} | ||
} | ||
|
||
given("기존의 VoteMetrics에") { | ||
val userId = 1L | ||
val voteMetrics = VoteMetrics.createInitialState(userId) | ||
val ballot = BallotFixture.create() | ||
`when`("최근의 Ballot을 추가하면") { | ||
ballot.receiverRead() | ||
val resultVoteMetrics = voteMetrics.recordBallot(ballot) | ||
then("최근으로 갱신된다.") { | ||
resultVoteMetrics.userId shouldBe userId | ||
resultVoteMetrics.lastVotedDateTime shouldBe ballot.createdAt | ||
resultVoteMetrics.voteCount shouldBe 1 | ||
resultVoteMetrics.isReceiverRead shouldBe true | ||
} | ||
} | ||
`when`("수신자가 읽지 않은 Ballot을 추가하면") { | ||
val noReceiverReadBallot = BallotFixture.create() | ||
val resultVoteMetrics = voteMetrics.recordBallot(noReceiverReadBallot) | ||
then("읽지 않음으로 갱신된다.") { | ||
resultVoteMetrics.userId shouldBe userId | ||
resultVoteMetrics.lastVotedDateTime shouldBe noReceiverReadBallot.createdAt | ||
resultVoteMetrics.voteCount shouldBe 1 | ||
resultVoteMetrics.isReceiverRead shouldBe false | ||
} | ||
} | ||
} | ||
|
||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변수명 엄청 기네요😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋㅋㅋㅋㅋ 어쩌다보니.. 테스트니까 이해해주세요오옹 ♡♡