Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Fix issue 2932 (#2957)
Browse files Browse the repository at this point in the history
* updated fake category dao

* fake category dao test implementation
  • Loading branch information
Rick-AB authored Feb 13, 2024
1 parent fd178c9 commit 3430fb4
Show file tree
Hide file tree
Showing 2 changed files with 437 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FakeCategoryDao : CategoryDao, WriteCategoryDao {
private val items = mutableListOf<CategoryEntity>()

override suspend fun findAll(deleted: Boolean): List<CategoryEntity> {
return items
return items.filter { it.isDeleted == deleted }
}

override suspend fun findById(id: UUID): CategoryEntity? {
Expand All @@ -23,15 +23,26 @@ class FakeCategoryDao : CategoryDao, WriteCategoryDao {
}

override suspend fun save(value: CategoryEntity) {
items.add(value)
val existingItemIndex = items.indexOfFirst { it.id == value.id }
if (existingItemIndex > -1) {
items[existingItemIndex] = value
} else {
items.add(value)
}
}

override suspend fun saveMany(values: List<CategoryEntity>) {
values.forEach { save(it) }
}

override suspend fun flagDeleted(id: UUID) {
TODO("Not yet implemented")
items.replaceAll { categoryEntity ->
if (categoryEntity.id == id) {
categoryEntity.copy(isDeleted = true)
} else {
categoryEntity
}
}
}

override suspend fun deleteById(id: UUID) {
Expand Down
Loading

0 comments on commit 3430fb4

Please sign in to comment.