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

Commit

Permalink
Fix issue 2933 (#2959)
Browse files Browse the repository at this point in the history
* updated fake transaction dao

* implement fake transaction dao test
  • Loading branch information
Rick-AB authored Feb 14, 2024
1 parent 3430fb4 commit 26bb0dc
Show file tree
Hide file tree
Showing 2 changed files with 3,088 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class FakeTransactionDao : TransactionDao, WriteTransactionDao {
return items.filter {
val dateTime = it.dateTime ?: return@filter false
it.type == TransactionType.TRANSFER &&
it.toAccountId == toAccountId &&
isBetween(dateTime, startDate, endDate) &&
!it.isDeleted
}.sortedByDescending { it.dateTime }
Expand Down Expand Up @@ -292,15 +293,20 @@ class FakeTransactionDao : TransactionDao, WriteTransactionDao {
}

override suspend fun save(value: TransactionEntity) {
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<TransactionEntity>) {
values.forEach { save(it) }
}

override suspend fun flagDeleted(id: UUID) {
items.map {
items.replaceAll {
if (it.id == id) {
it.copy(isDeleted = true)
} else {
Expand All @@ -310,7 +316,7 @@ class FakeTransactionDao : TransactionDao, WriteTransactionDao {
}

override suspend fun flagDeletedByRecurringRuleIdAndNoDateTime(recurringRuleId: UUID) {
items.map {
items.replaceAll {
if (it.recurringRuleId == recurringRuleId && it.dateTime == null) {
it.copy(isDeleted = true)
} else {
Expand All @@ -320,7 +326,7 @@ class FakeTransactionDao : TransactionDao, WriteTransactionDao {
}

override suspend fun flagDeletedByAccountId(accountId: UUID) {
items.map {
items.replaceAll {
if (it.accountId == accountId) {
it.copy(isDeleted = true)
} else {
Expand Down
Loading

0 comments on commit 26bb0dc

Please sign in to comment.