Skip to content
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

test: VoteAdapter 투표 수 계산 로직 테스트 #143

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,14 @@ class CourseServiceTest {
given(scheduleQueryPort.findAllByRoomUid(room.roomUid)).willReturn(schedules)
given(placeQueryPort.findAllByRoomUid(room.roomUid)).willReturn(places)
given(voteQueryPort.findAllByPlaceIds(anyList())).willReturn(votes)

val agreeCountPlaceId =
votes
.filter { it.result == VoteResult.AGREE }
.groupingBy { it.placeId.getValue() }
.eachCount()
given(voteQueryPort.findAgreeCountByPlaceId(votes)).willReturn(agreeCountPlaceId)
given(voteQueryPort.findAgreeCountByPlaceId(votes))
.willReturn(
mapOf(
8L to 1,
9L to 1,
10L to 2,
),
)

val coordinate1 = Coordinate(places[1].longitude, places[1].latitude)
val coordinate2 = Coordinate(places[4].longitude, places[4].latitude)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ class VoteServiceTest {
.willReturn(votes)
given(voteQueryPort.findAgreeCountByPlaceId(votes))
.willReturn(
votes
.filter { it.result == VoteResult.AGREE }
.groupingBy { it.placeId.getValue() }
.eachCount(),
mapOf(
1L to 1,
3L to 2,
),
)

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.piikii.output.persistence.postgresql.adapter

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.domain.vote.Vote
import com.piikii.application.domain.vote.VoteResult
import com.piikii.output.persistence.postgresql.persistence.repository.VoteRepository
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import java.util.UUID

@ExtendWith(MockitoExtension::class)
class VoteAdapterTest {
@InjectMocks
lateinit var voteAdapter: VoteAdapter

@Mock
lateinit var voteRepository: VoteRepository

@Test
fun `PlaceId 별로 AGREE 투표 수를 계산 및 매핑한다`() {
// given
val placeId1 = LongTypeId(1L)
val placeId2 = LongTypeId(2L)
val userUid = UuidTypeId(UUID.randomUUID())
val votes =
listOf(
Vote(id = LongTypeId(1), userUid = userUid, placeId = placeId1, result = VoteResult.AGREE),
Vote(id = LongTypeId(2), userUid = userUid, placeId = placeId1, result = VoteResult.AGREE),
Vote(id = LongTypeId(3), userUid = userUid, placeId = placeId2, result = VoteResult.AGREE),
Vote(id = LongTypeId(4), userUid = userUid, placeId = placeId1, result = VoteResult.DISAGREE),
Vote(id = LongTypeId(5), userUid = userUid, placeId = placeId2, result = VoteResult.DISAGREE),
)

// when
val result = voteAdapter.findAgreeCountByPlaceId(votes)

// then
assertThat(result[placeId1.getValue()]).isEqualTo(2)
assertThat(result[placeId2.getValue()]).isEqualTo(1)
}
}
Loading