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

Rename function to setNewsResourceBookmarked #1275

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -43,7 +43,7 @@ internal class FakeUserDataRepository @Inject constructor(
override suspend fun setTopicIdFollowed(followedTopicId: String, followed: Boolean) =
niaPreferencesDataSource.setTopicIdFollowed(followedTopicId, followed)

override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
override suspend fun setNewsResourceBookmarked(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class OfflineFirstUserDataRepository @Inject constructor(
analyticsHelper.logTopicFollowToggled(followedTopicId, followed)
}

override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
override suspend fun setNewsResourceBookmarked(newsResourceId: String, bookmarked: Boolean) {
niaPreferencesDataSource.setNewsResourceBookmarked(newsResourceId, bookmarked)
analyticsHelper.logNewsResourceBookmarkToggled(
newsResourceId = newsResourceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface UserDataRepository {
/**
* Updates the bookmarked status for a news resource
*/
suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean)
suspend fun setNewsResourceBookmarked(newsResourceId: String, bookmarked: Boolean)

/**
* Updates the viewed status for a news resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class OfflineFirstUserDataRepositoryTest {
@Test
fun offlineFirstUserDataRepository_bookmark_news_resource_logic_delegates_to_nia_preferences() =
testScope.runTest {
subject.updateNewsResourceBookmark(newsResourceId = "0", bookmarked = true)
subject.setNewsResourceBookmarked(newsResourceId = "0", bookmarked = true)

assertEquals(
setOf("0"),
Expand All @@ -142,7 +142,7 @@ class OfflineFirstUserDataRepositoryTest {
.first(),
)

subject.updateNewsResourceBookmark(newsResourceId = "1", bookmarked = true)
subject.setNewsResourceBookmarked(newsResourceId = "1", bookmarked = true)

assertEquals(
setOf("0", "1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TestUserDataRepository : UserDataRepository {
}
}

override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) {
override suspend fun setNewsResourceBookmarked(newsResourceId: String, bookmarked: Boolean) {
currentUserData.let { current ->
val bookmarkedNews = if (bookmarked) {
current.bookmarkedNewsResources + newsResourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BookmarksViewModel @Inject constructor(
viewModelScope.launch {
shouldDisplayUndoBookmark = true
lastRemovedBookmarkId = newsResourceId
userDataRepository.updateNewsResourceBookmark(newsResourceId, false)
userDataRepository.setNewsResourceBookmarked(newsResourceId, false)
}
}

Expand All @@ -71,7 +71,7 @@ class BookmarksViewModel @Inject constructor(
fun undoBookmarkRemoval() {
viewModelScope.launch {
lastRemovedBookmarkId?.let {
userDataRepository.updateNewsResourceBookmark(it, true)
userDataRepository.setNewsResourceBookmarked(it, true)
}
}
clearUndoState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BookmarksViewModelTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() }

newsRepository.sendNewsResources(newsResourcesTestData)
userDataRepository.updateNewsResourceBookmark(newsResourcesTestData[0].id, true)
userDataRepository.setNewsResourceBookmarked(newsResourcesTestData[0].id, true)
val item = viewModel.feedUiState.value
assertIs<Success>(item)
assertEquals(item.feed.size, 1)
Expand All @@ -81,7 +81,7 @@ class BookmarksViewModelTest {
// Set the news resources to be used by this test
newsRepository.sendNewsResources(newsResourcesTestData)
// Start with the resource saved
userDataRepository.updateNewsResourceBookmark(newsResourcesTestData[0].id, true)
userDataRepository.setNewsResourceBookmarked(newsResourcesTestData[0].id, true)
// Use viewModel to remove saved resource
viewModel.removeFromSavedResources(newsResourcesTestData[0].id)
// Verify list of saved resources is now empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ForYouViewModel @Inject constructor(

fun updateNewsResourceSaved(newsResourceId: String, isChecked: Boolean) {
viewModelScope.launch {
userDataRepository.updateNewsResourceBookmark(newsResourceId, isChecked)
userDataRepository.setNewsResourceBookmarked(newsResourceId, isChecked)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TopicViewModel @Inject constructor(

fun bookmarkNews(newsResourceId: String, bookmarked: Boolean) {
viewModelScope.launch {
userDataRepository.updateNewsResourceBookmark(newsResourceId, bookmarked)
userDataRepository.setNewsResourceBookmarked(newsResourceId, bookmarked)
}
}

Expand Down