File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
main/kotlin/org/wordpress/android/fluxc/persistence/dao
test/java/org/wordpress/android/fluxc/persistence/dao Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package org.wordpress.android.fluxc.persistence.dao
2
2
3
3
import androidx.room.Dao
4
4
import androidx.room.Insert
5
+ import androidx.room.OnConflictStrategy
5
6
import androidx.room.Query
6
7
import androidx.room.Transaction
7
8
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
@@ -31,6 +32,6 @@ internal abstract class TaxClassDao {
31
32
)
32
33
protected abstract suspend fun deleteAll (siteId : LocalId ): Int
33
34
34
- @Insert
35
+ @Insert(onConflict = OnConflictStrategy . REPLACE )
35
36
protected abstract suspend fun insertAll (classes : List <WCTaxClassModel >)
36
37
}
Original file line number Diff line number Diff line change @@ -121,4 +121,17 @@ class TaxClassDaoTest {
121
121
val otherSiteResult = sut.getTaxClasses(LocalId (999 ))
122
122
assertThat(otherSiteResult).containsExactly(differentSiteTaxClass)
123
123
}
124
+
125
+ @Test
126
+ fun `when there are duplicate tax classes, replaceAll keeps the last one` () = runTest {
127
+ // given
128
+ val taxClasses = listOf (sampleTaxClass1, sampleTaxClass2, sampleTaxClass1)
129
+ sut.replaceAll(site.localId(), taxClasses)
130
+
131
+ // when
132
+ val result = sut.getTaxClasses(site.localId())
133
+
134
+ // then
135
+ assertThat(result).containsExactlyInAnyOrderElementsOf(listOf (sampleTaxClass1, sampleTaxClass2))
136
+ }
124
137
}
You can’t perform that action at this time.
0 commit comments