From 08759b6e24f0388849e094cb79b1f95dcb41a22b Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 30 Mar 2022 12:38:35 +0200 Subject: [PATCH 1/2] Remove --- .../core/storage/FamilyTestDatabaseTest.kt | 21 ------------------- .../core/storage/FamilyTestDatabase.kt | 3 --- 2 files changed, 24 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabaseTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabaseTest.kt index 8cd490af006..358592061e3 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabaseTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabaseTest.kt @@ -121,25 +121,4 @@ class FamilyTestDatabaseTest : BaseTestInstrumentation() { dao.getAllActive().first().size shouldBe 0 dao.getAllInRecycleBin().first().size shouldBe 0 } - - @Test - fun testDeleteAfterRetention() = runBlocking { - dao.insert(test.toEntity()) - dao.insert(test2.toEntity()) - - dao.getAllActive().first().size shouldBe 2 - dao.getAllInRecycleBin().first().size shouldBe 0 - - dao.update(identifier) { - it.moveToRecycleBin(now) - } - - dao.getAllActive().first().size shouldBe 1 - dao.getAllInRecycleBin().first().size shouldBe 1 - - dao.deleteFromRecycleBin(now.millis + 1) - - dao.getAllActive().first().size shouldBe 1 - dao.getAllInRecycleBin().first().size shouldBe 0 - } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabase.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabase.kt index 559e6b08910..50728001569 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabase.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/familytest/core/storage/FamilyTestDatabase.kt @@ -89,9 +89,6 @@ interface FamilyCoronaTestDao { @Query("SELECT * FROM family_corona_test WHERE moved_to_recycle_bin_at_millis IS NOT NULL") fun getAllInRecycleBin(): Flow> - @Query("DELETE FROM family_corona_test WHERE moved_to_recycle_bin_at_millis < :olderThanMillis") - suspend fun deleteFromRecycleBin(olderThanMillis: Long) - @Query("DELETE FROM family_corona_test") suspend fun deleteAll() From 3a6df9119d4ab0b7c22829d45c82a658eec2ddf6 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 30 Mar 2022 13:04:37 +0200 Subject: [PATCH 2/2] Update tests --- .../cleanup/RecycleBinCleanUpServiceTest.kt | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/recyclebin/cleanup/RecycleBinCleanUpServiceTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/recyclebin/cleanup/RecycleBinCleanUpServiceTest.kt index 9aae972d7c5..56a7787bbe2 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/recyclebin/cleanup/RecycleBinCleanUpServiceTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/recyclebin/cleanup/RecycleBinCleanUpServiceTest.kt @@ -3,15 +3,19 @@ package de.rki.coronawarnapp.recyclebin.cleanup import de.rki.coronawarnapp.coronatest.type.PersonalCoronaTest import de.rki.coronawarnapp.covidcertificate.common.certificate.CwaCovidCertificate import de.rki.coronawarnapp.covidcertificate.common.repository.CertificateContainerId +import de.rki.coronawarnapp.familytest.core.model.FamilyCoronaTest import de.rki.coronawarnapp.reyclebin.cleanup.RecycleBinCleanUpService import de.rki.coronawarnapp.reyclebin.coronatest.RecycledCoronaTestsProvider import de.rki.coronawarnapp.reyclebin.covidcertificate.RecycledCertificatesProvider import de.rki.coronawarnapp.util.TimeStamper import io.mockk.MockKAnnotations +import io.mockk.Runs +import io.mockk.coEvery import io.mockk.coVerify import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.impl.annotations.RelaxedMockK +import io.mockk.just import io.mockk.mockk import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runBlockingTest @@ -34,6 +38,8 @@ class RecycleBinCleanUpServiceTest : BaseTest() { MockKAnnotations.init(this) every { timeStamper.nowUTC } returns Instant.parse("2021-10-13T12:00:00.000Z") + + coEvery { recycledCoronaTestsProvider.deleteCoronaTest(any()) } just Runs } private fun createInstance() = RecycleBinCleanUpService( @@ -53,12 +59,18 @@ class RecycleBinCleanUpServiceTest : BaseTest() { } private fun createTest(days: Int) = createTest(recycleTime = now.minus(Days.days(days).toStandardDuration())) + private fun familyTest(days: Int) = createFamilyTest(recycleTime = now.minus(Days.days(days).toStandardDuration())) private fun createTest(recycleTime: Instant): PersonalCoronaTest = mockk { every { recycledAt } returns recycleTime every { identifier } returns recycleTime.toString() } + private fun createFamilyTest(recycleTime: Instant): FamilyCoronaTest = mockk { + every { recycledAt } returns recycleTime + every { identifier } returns recycleTime.toString() + } + @Test fun `No recycled items, nothing to delete`() = runBlockingTest { every { recycledCertificatesProvider.recycledCertificates } returns flowOf(emptySet()) @@ -78,13 +90,20 @@ class RecycleBinCleanUpServiceTest : BaseTest() { val certWith30DaysOfRetention = createCert(30) val testWith0DaysOfRetention = createTest(0) val testWith30DaysOfRetention = createTest(30) + val familyTestWith0DaysOfRetention = familyTest(0) + val familyTestWith30DaysOfRetention = familyTest(30) every { recycledCertificatesProvider.recycledCertificates } returns flowOf( setOf(certWith0DaysOfRetention, certWith30DaysOfRetention) ) every { recycledCoronaTestsProvider.tests } returns flowOf( - setOf(testWith0DaysOfRetention, testWith30DaysOfRetention) + setOf( + testWith0DaysOfRetention, + testWith30DaysOfRetention, + familyTestWith0DaysOfRetention, + familyTestWith30DaysOfRetention + ) ) createInstance().clearRecycledItems() @@ -105,18 +124,21 @@ class RecycleBinCleanUpServiceTest : BaseTest() { val testExact30Days = createTest(nowMinus30Days) val test30DaysAnd1Ms = createTest(nowMinus30DaysAnd1Ms) + val familyTestExact30Days = createFamilyTest(nowMinus30Days) + val familyTest30DaysAnd1Ms = createFamilyTest(nowMinus30DaysAnd1Ms) + every { recycledCertificatesProvider.recycledCertificates } returns flowOf( setOf(certExact30Days, cert30DaysAnd1Ms) ) every { recycledCoronaTestsProvider.tests } returns flowOf( - setOf(testExact30Days, test30DaysAnd1Ms) + setOf(testExact30Days, test30DaysAnd1Ms, familyTest30DaysAnd1Ms, familyTestExact30Days) ) createInstance().clearRecycledItems() val containerIds = listOf(cert30DaysAnd1Ms.containerId) - val identifiers = listOf(test30DaysAnd1Ms.identifier) + val identifiers = listOf(test30DaysAnd1Ms.identifier, familyTest30DaysAnd1Ms.identifier) coVerify(exactly = 1) { recycledCertificatesProvider.deleteAllCertificate(containerIds) recycledCoronaTestsProvider.deleteAllCoronaTest(identifiers)