Change-Id: Id9774ad300b04c17cb1d7668c1ab1bac014bf70c
pull/1275/head
Jaehwa Noh 9 months ago
parent f301fc5859
commit ed91723e2f

@ -43,7 +43,7 @@ internal class FakeUserDataRepository @Inject constructor(
override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) = override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) =
niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed) niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed)
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { override suspend fun setNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked) niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
} }

@ -42,7 +42,7 @@ internal class OfflineFirstUserDataRepository @Inject constructor(
analyticsHelper.logTopicFollowToggled(followedTopicId, followed) analyticsHelper.logTopicFollowToggled(followedTopicId, followed)
} }
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { override suspend fun setNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked) niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
analyticsHelper.logNewsResourceBookmarkToggled( analyticsHelper.logNewsResourceBookmarkToggled(
newsResourceId = newsResourceId, newsResourceId = newsResourceId,

@ -41,7 +41,7 @@ interface UserDataRepository {
/** /**
* Updates the bookmarked status for a news resource * Updates the bookmarked status for a news resource
*/ */
suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) suspend fun setNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean)
/** /**
* Updates the viewed status for a news resource * Updates the viewed status for a news resource

@ -133,7 +133,7 @@ class OfflineFirstUserDataRepositoryTest {
@Test @Test
fun offlineFirstUserDataRepository_bookmark_news_resource_logic_delegates_to_nia_preferences() = fun offlineFirstUserDataRepository_bookmark_news_resource_logic_delegates_to_nia_preferences() =
testScope.runTest { testScope.runTest {
subject.updateNewsResourceBookmark(newsResourceId = "0", bookmarked = true) subject.setNewsResourceBookmark(newsResourceId = "0", bookmarked = true)
assertEquals( assertEquals(
setOf("0"), setOf("0"),
@ -142,7 +142,7 @@ class OfflineFirstUserDataRepositoryTest {
.first(), .first(),
) )
subject.updateNewsResourceBookmark(newsResourceId = "1", bookmarked = true) subject.setNewsResourceBookmark(newsResourceId = "1", bookmarked = true)
assertEquals( assertEquals(
setOf("0", "1"), setOf("0", "1"),

@ -61,7 +61,7 @@ class TestUserDataRepository : UserDataRepository {
} }
} }
override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { override suspend fun setNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
currentUserData.let { current -> currentUserData.let { current ->
val bookmarkedNews = if (bookmarked) { val bookmarkedNews = if (bookmarked) {
current.bookmarkedNewsResources + newsResourceId current.bookmarkedNewsResources + newsResourceId

@ -58,7 +58,7 @@ class BookmarksViewModel @Inject constructor(
viewModelScope.launch { viewModelScope.launch {
shouldDisplayUndoBookmark = true shouldDisplayUndoBookmark = true
lastRemovedBookmarkId = newsResourceId lastRemovedBookmarkId = newsResourceId
userDataRepository.updateNewsResourceBookmark(newsResourceId, false) userDataRepository.setNewsResourceBookmark(newsResourceId, false)
} }
} }
@ -71,7 +71,7 @@ class BookmarksViewModel @Inject constructor(
fun undoBookmarkRemoval() { fun undoBookmarkRemoval() {
viewModelScope.launch { viewModelScope.launch {
lastRemovedBookmarkId?.let { lastRemovedBookmarkId?.let {
userDataRepository.updateNewsResourceBookmark(it, true) userDataRepository.setNewsResourceBookmark(it, true)
} }
} }
clearUndoState() clearUndoState()

@ -67,7 +67,7 @@ class BookmarksViewModelTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() } val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() }
newsRepository.sendNewsResources(newsResourcesTestData) newsRepository.sendNewsResources(newsResourcesTestData)
userDataRepository.updateNewsResourceBookmark(newsResourcesTestData[0].id, true) userDataRepository.setNewsResourceBookmark(newsResourcesTestData[0].id, true)
val item = viewModel.feedUiState.value val item = viewModel.feedUiState.value
assertIs<Success>(item) assertIs<Success>(item)
assertEquals(item.feed.size, 1) assertEquals(item.feed.size, 1)
@ -81,7 +81,7 @@ class BookmarksViewModelTest {
// Set the news resources to be used by this test // Set the news resources to be used by this test
newsRepository.sendNewsResources(newsResourcesTestData) newsRepository.sendNewsResources(newsResourcesTestData)
// Start with the resource saved // Start with the resource saved
userDataRepository.updateNewsResourceBookmark(newsResourcesTestData[0].id, true) userDataRepository.setNewsResourceBookmark(newsResourcesTestData[0].id, true)
// Use viewModel to remove saved resource // Use viewModel to remove saved resource
viewModel.removeFromSavedResources(newsResourcesTestData[0].id) viewModel.removeFromSavedResources(newsResourcesTestData[0].id)
// Verify list of saved resources is now empty // Verify list of saved resources is now empty

@ -117,7 +117,7 @@ class ForYouViewModel @Inject constructor(
fun updateNewsResourceSaved(newsResourceId: String, isChecked: Boolean) { fun updateNewsResourceSaved(newsResourceId: String, isChecked: Boolean) {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.updateNewsResourceBookmark(newsResourceId, isChecked) userDataRepository.setNewsResourceBookmark(newsResourceId, isChecked)
} }
} }

@ -81,7 +81,7 @@ class TopicViewModel @Inject constructor(
fun bookmarkNews(newsResourceId: String, bookmarked: Boolean) { fun bookmarkNews(newsResourceId: String, bookmarked: Boolean) {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.updateNewsResourceBookmark(newsResourceId, bookmarked) userDataRepository.setNewsResourceBookmark(newsResourceId, bookmarked)
} }
} }

Loading…
Cancel
Save