Close #25982: Fix check between current and new when adding a bookmark

pull/543/head
Jonathan Almeida 2 years ago committed by mergify[bot]
parent 26d22e7528
commit 7309b671b1

@ -30,8 +30,8 @@ class BookmarksUseCase(
*/
@WorkerThread
suspend operator fun invoke(url: String, title: String, position: UInt? = null): Boolean {
try {
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == it.url } == null
return try {
val canAdd = storage.getBookmarksWithUrl(url).firstOrNull { it.url == url } == null
if (canAdd) {
storage.addItem(
@ -41,9 +41,9 @@ class BookmarksUseCase(
position = position
)
}
return canAdd
canAdd
} catch (e: PlacesException.UrlParseFailed) {
return false
false
}
}
}

@ -44,9 +44,11 @@ class BookmarksUseCaseTest {
fun `WHEN adding bookmark THEN new item is stored`() = runTest {
val bookmarksStorage = mockk<BookmarksStorage>(relaxed = true)
val historyStorage = mockk<HistoryStorage>(relaxed = true)
val bookmarkNode = mockk<BookmarkNode>()
val useCase = BookmarksUseCase(bookmarksStorage, historyStorage)
coEvery { bookmarksStorage.getBookmarksWithUrl(any()) }.coAnswers { emptyList() }
every { bookmarkNode.url }.answers { "https://firefox.com" }
coEvery { bookmarksStorage.getBookmarksWithUrl(any()) }.coAnswers { listOf(bookmarkNode) }
val result = useCase.addBookmark("https://mozilla.org", "Mozilla")

Loading…
Cancel
Save