-
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.
Merge pull request #46 from YAPP-Github/feature/tgyuu/PC-476
[PC-476] 가치관 Pick, 가치관 Talk을 Splash 화면에서 동적으로 불러옵니다.
- Loading branch information
Showing
33 changed files
with
1,011 additions
and
112 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
73 changes: 73 additions & 0 deletions
73
core/data/src/main/java/com/puzzle/data/repository/MatchingRepositoryImpl.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,73 @@ | ||
package com.puzzle.data.repository | ||
|
||
import com.puzzle.common.suspendRunCatching | ||
import com.puzzle.database.model.matching.ValuePickAnswer | ||
import com.puzzle.database.model.matching.ValuePickEntity | ||
import com.puzzle.database.model.matching.ValuePickQuestion | ||
import com.puzzle.database.model.matching.ValueTalkEntity | ||
import com.puzzle.database.source.LocalMatchingDataSource | ||
import com.puzzle.domain.model.matching.ValuePick | ||
import com.puzzle.domain.model.matching.ValueTalk | ||
import com.puzzle.domain.repository.MatchingRepository | ||
import com.puzzle.network.model.UNKNOWN_INT | ||
import com.puzzle.network.source.MatchingDataSource | ||
import javax.inject.Inject | ||
|
||
class MatchingRepositoryImpl @Inject constructor( | ||
private val matchingDataSource: MatchingDataSource, | ||
private val localMatchingDataSource: LocalMatchingDataSource, | ||
) : MatchingRepository { | ||
override suspend fun loadValuePicks(): Result<Unit> = suspendRunCatching { | ||
val valuePicks = matchingDataSource.loadValuePicks() | ||
.getOrThrow() | ||
.toDomain() | ||
.filter { it.id != UNKNOWN_INT } | ||
|
||
val valuePickEntities = valuePicks.map { valuePick -> | ||
ValuePickEntity( | ||
valuePickQuestion = ValuePickQuestion( | ||
id = valuePick.id, | ||
category = valuePick.category, | ||
question = valuePick.question, | ||
), | ||
answers = valuePick.answers.map { answer -> | ||
ValuePickAnswer( | ||
questionsId = valuePick.id, | ||
number = answer.number, | ||
content = answer.content, | ||
) | ||
} | ||
) | ||
} | ||
|
||
localMatchingDataSource.replaceValuePicks(valuePickEntities) | ||
} | ||
|
||
override suspend fun loadValueTalks(): Result<Unit> = suspendRunCatching { | ||
val valueTalks = matchingDataSource.loadValueTalks() | ||
.getOrThrow() | ||
.toDomain() | ||
.filter { it.id != UNKNOWN_INT } | ||
|
||
val valueTalkEntities = valueTalks.map { | ||
ValueTalkEntity( | ||
id = it.id, | ||
title = it.title, | ||
category = it.category, | ||
helpMessages = it.helpMessages, | ||
) | ||
} | ||
|
||
localMatchingDataSource.replaceValueTalks(valueTalkEntities) | ||
} | ||
|
||
override suspend fun retrieveValuePick(): Result<List<ValuePick>> = suspendRunCatching { | ||
localMatchingDataSource.retrieveValuePicks() | ||
.map(ValuePickEntity::toDomain) | ||
} | ||
|
||
override suspend fun retrieveValueTalk(): Result<List<ValueTalk>> = suspendRunCatching { | ||
localMatchingDataSource.retrieveValueTalks() | ||
.map(ValueTalkEntity::toDomain) | ||
} | ||
} |
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
190 changes: 190 additions & 0 deletions
190
core/data/src/test/java/com/puzzle/data/repository/MatchingRepositoryImplTest.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,190 @@ | ||
package com.puzzle.data.repository | ||
|
||
import com.puzzle.database.source.LocalMatchingDataSource | ||
import com.puzzle.network.model.matching.LoadValuePicksResponse | ||
import com.puzzle.network.model.matching.LoadValueTalksResponse | ||
import com.puzzle.network.model.matching.ValuePickAnswerResponse | ||
import com.puzzle.network.model.matching.ValuePickResponse | ||
import com.puzzle.network.model.matching.ValueTalkResponse | ||
import com.puzzle.network.source.MatchingDataSource | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class MatchingRepositoryImplTest { | ||
|
||
private lateinit var matchingDataSource: MatchingDataSource | ||
private lateinit var localMatchingDataSource: LocalMatchingDataSource | ||
private lateinit var matchingRepository: MatchingRepositoryImpl | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
matchingDataSource = mockk() | ||
localMatchingDataSource = mockk() | ||
matchingRepository = MatchingRepositoryImpl(matchingDataSource, localMatchingDataSource) | ||
} | ||
|
||
@Test | ||
fun `가치관Pick을 새로 갱신할 경우 id값이 올바르게 내려오지 않은 가치관Pick은 무시한다`() = runTest { | ||
// given | ||
val invalidValuePick = ValuePickResponse( | ||
id = null, | ||
category = null, | ||
question = null, | ||
answers = null | ||
) | ||
val validValuePick = ValuePickResponse( | ||
id = 1, | ||
category = "음주", | ||
question = "술을 마시는 것에 대해 어떻게 생각하나요?", | ||
answers = listOf( | ||
ValuePickAnswerResponse(1, "함께 즐기고 싶어요"), | ||
ValuePickAnswerResponse(2, "같이 즐길 수 없어도 괜찮아요") | ||
) | ||
) | ||
|
||
coEvery { matchingDataSource.loadValuePicks() } returns | ||
Result.success(LoadValuePicksResponse(listOf(invalidValuePick, validValuePick))) | ||
coEvery { localMatchingDataSource.replaceValuePicks(any()) } returns Result.success(Unit) | ||
|
||
// when | ||
val result = matchingRepository.loadValuePicks() | ||
|
||
// then | ||
assertTrue(result.isSuccess) | ||
coVerify(exactly = 1) { | ||
localMatchingDataSource.replaceValuePicks( | ||
match { | ||
it.size == 1 && it.first().valuePickQuestion.id == validValuePick.id | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `가치관Talk을 새로 갱신할 경우 id값이 올바르게 내려오지 않은 가치관Talk은 무시한다`() = runTest { | ||
// given | ||
val invalidValueTalk = ValueTalkResponse( | ||
id = null, | ||
category = null, | ||
title = null, | ||
guide = null | ||
) | ||
val validValueTalk = ValueTalkResponse( | ||
id = 1, | ||
category = "음주", | ||
title = "술자리에 대한 대화", | ||
guide = null | ||
) | ||
|
||
coEvery { matchingDataSource.loadValueTalks() } returns | ||
Result.success(LoadValueTalksResponse(listOf(invalidValueTalk, validValueTalk))) | ||
coEvery { localMatchingDataSource.replaceValueTalks(any()) } returns Result.success(Unit) | ||
|
||
// when | ||
val result = matchingRepository.loadValueTalks() | ||
|
||
// then | ||
assertTrue(result.isSuccess) | ||
coVerify(exactly = 1) { | ||
localMatchingDataSource.replaceValueTalks( | ||
match { | ||
it.size == 1 && it.first().id == validValueTalk.id | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `갱신한 가치관Pick 데이터는 로컬 데이터베이스에 저장한다`() = runTest { | ||
// given | ||
val validValuePicks = listOf( | ||
ValuePickResponse( | ||
id = 1, | ||
category = "음주", | ||
question = "술을 마시는 것에 대해 어떻게 생각하나요?", | ||
answers = listOf( | ||
ValuePickAnswerResponse(1, "함께 즐기고 싶어요"), | ||
ValuePickAnswerResponse(2, "같이 즐길 수 없어도 괜찮아요") | ||
) | ||
), | ||
ValuePickResponse( | ||
id = 2, | ||
category = "취미", | ||
question = "좋아하는 취미가 있나요?", | ||
answers = listOf( | ||
ValuePickAnswerResponse(1, "여행을 좋아해요"), | ||
ValuePickAnswerResponse(2, "영화 감상을 좋아해요") | ||
) | ||
) | ||
) | ||
|
||
coEvery { matchingDataSource.loadValuePicks() } returns Result.success( | ||
LoadValuePicksResponse(validValuePicks) | ||
) | ||
coEvery { localMatchingDataSource.replaceValuePicks(any()) } returns Result.success(Unit) | ||
|
||
// when | ||
val result = matchingRepository.loadValuePicks() | ||
|
||
// then | ||
assertTrue(result.isSuccess) | ||
coVerify(exactly = 1) { | ||
localMatchingDataSource.replaceValuePicks( | ||
match { | ||
it.size == validValuePicks.size && it.all { entity -> | ||
validValuePicks.any { pick -> | ||
pick.id == entity.valuePickQuestion.id && | ||
pick.category == entity.valuePickQuestion.category | ||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `갱신한 가치관Talk 데이터는 로컬 데이터베이스에 저장한다`() = runTest { | ||
// given | ||
val validValueTalks = listOf( | ||
ValueTalkResponse( | ||
id = 1, | ||
title = "술자리에 대한 대화", | ||
category = "음주", | ||
guide = null | ||
), | ||
ValueTalkResponse( | ||
id = 2, | ||
title = "취미 공유하기", | ||
category = "취미", | ||
guide = null | ||
) | ||
) | ||
|
||
coEvery { matchingDataSource.loadValueTalks() } returns Result.success( | ||
LoadValueTalksResponse(validValueTalks) | ||
) | ||
coEvery { localMatchingDataSource.replaceValueTalks(any()) } returns Result.success(Unit) | ||
|
||
// when | ||
val result = matchingRepository.loadValueTalks() | ||
|
||
// then | ||
assertTrue(result.isSuccess) | ||
coVerify(exactly = 1) { | ||
localMatchingDataSource.replaceValueTalks( | ||
match { | ||
it.size == validValueTalks.size && it.all { entity -> | ||
validValueTalks.any { talk -> | ||
talk.id == entity.id && talk.title == entity.title | ||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
core/data/src/test/java/com/puzzle/data/repository/TermsRepositoryImplTest.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
Oops, something went wrong.