Skip to content

Commit 5a13aa7

Browse files
paetzpaetz
and
paetz
authored
Delete partners on database reset (#477)
Co-authored-by: paetz <[email protected]>
1 parent a39213e commit 5a13aa7

File tree

4 files changed

+2
-31
lines changed

4 files changed

+2
-31
lines changed

app/src/androidTest/java/com/yacgroup/yacguide/database/RegionDaoTests.kt

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022, 2023 Axel Paetzold
2+
* Copyright (C) 2022, 2023, 2025 Axel Paetzold
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@ import com.yacgroup.yacguide.database.TestDB.Companion.INVALID_NAME
2727
import com.yacgroup.yacguide.database.TestDB.Companion.REGIONS
2828
import com.yacgroup.yacguide.database.TestDB.Companion.ROUTES
2929
import com.yacgroup.yacguide.database.TestDB.Companion.SECTORS
30-
import kotlinx.coroutines.ExperimentalCoroutinesApi
3130
import kotlinx.coroutines.test.runTest
3231
import org.junit.jupiter.api.*
3332
import org.junit.jupiter.api.Assertions.*
@@ -58,19 +57,16 @@ class RegionDaoTests {
5857
_db.close()
5958
}
6059

61-
@OptIn(ExperimentalCoroutinesApi::class)
6260
@Test
6361
fun getAllInCountry_invalidCountryName_returnsEmptyList() = runTest {
6462
assertTrue(_regionDao.getAllInCountry(INVALID_NAME).isEmpty())
6563
}
6664

67-
@OptIn(ExperimentalCoroutinesApi::class)
6865
@Test
6966
fun getAllInCountry_noRegionsAvailable_returnsEmptyList() = runTest {
7067
assertTrue(_regionDao.getAllInCountry(COUNTRIES.last().name).isEmpty())
7168
}
7269

73-
@OptIn(ExperimentalCoroutinesApi::class)
7470
@Test
7571
fun getAllInCountry_regionsAvailable_returnsCorrespondingRegions() = runTest {
7672
val country1Name = COUNTRIES.first().name
@@ -80,7 +76,6 @@ class RegionDaoTests {
8076
assertTrue(equal(regionsInCountry1, _regionDao.getAllInCountry(country1Name)))
8177
}
8278

83-
@OptIn(ExperimentalCoroutinesApi::class)
8479
@Test
8580
fun getAllNonEmpty_sectorsWithParentRegionsAvailable_returnsCorrespondingRegions() = runTest {
8681
val nonEmptyRegions = REGIONS.filter { region ->
@@ -89,26 +84,22 @@ class RegionDaoTests {
8984
assertTrue(equal(nonEmptyRegions, _regionDao.getAllNonEmpty()))
9085
}
9186

92-
@OptIn(ExperimentalCoroutinesApi::class)
9387
@Test
9488
fun getRegion_invalidRegionId_returnsNull() = runTest {
9589
assertNull(_regionDao.getRegion(INVALID_ID))
9690
}
9791

98-
@OptIn(ExperimentalCoroutinesApi::class)
9992
@Test
10093
fun getRegion_regionAvailable_returnsRegion() = runTest {
10194
val region = REGIONS.first()
10295
assertEquals(_regionDao.getRegion(region.id), region)
10396
}
10497

105-
@OptIn(ExperimentalCoroutinesApi::class)
10698
@Test
10799
fun getRegionForRoute_invalidRouteId_returnsNull() = runTest {
108100
assertNull(_regionDao.getRegionForRoute(INVALID_ID))
109101
}
110102

111-
@OptIn(ExperimentalCoroutinesApi::class)
112103
@Test
113104
fun getRegionForRoute_regionForRouteAvailable_returnsAccordingRegion() = runTest {
114105
val region = REGIONS.first()
@@ -147,24 +138,10 @@ class RegionDaoDeletionTests {
147138
_db.close()
148139
}
149140

150-
151-
@OptIn(ExperimentalCoroutinesApi::class)
152141
@Test
153142
fun deleteAll_regionTableBecomesEmpty() = runTest {
154143
_regionDao.deleteAll()
155144
assertTrue(_regionDao.all.isEmpty())
156145
}
157146

158-
@OptIn(ExperimentalCoroutinesApi::class)
159-
@Test
160-
fun deleteAll_countryNameGiven_regionTableDoesNotContainCorrespondingRegionsAnymore() = runTest {
161-
val country1Name = COUNTRIES.first().name
162-
val regionsInCountry1 = REGIONS.filter {
163-
it.country == country1Name
164-
}
165-
_regionDao.deleteAll(country1Name)
166-
regionsInCountry1.forEach {
167-
assertFalse(_regionDao.all.contains(it))
168-
}
169-
}
170147
}

app/src/main/java/com/yacgroup/yacguide/PreferencesActivity.kt

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PreferencesActivity : BaseNavigationActivity() {
5050
setPositiveButton(R.string.ok) {_, _ ->
5151
_db.deleteCountriesRecursively()
5252
_db.deleteAscends()
53+
_db.deletePartners()
5354
_resetCustomSettings()
5455
Toast.makeText(this.context, R.string.reset_database_done, Toast.LENGTH_SHORT).show()
5556
}

app/src/main/java/com/yacgroup/yacguide/database/DatabaseWrapper.kt

-4
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ class DatabaseWrapper(context: Context) {
272272
_db.regionDao().deleteAll()
273273
}
274274

275-
fun deleteRegions(countryName: String) = _dbTransaction {
276-
_db.regionDao().deleteAll(countryName)
277-
}
278-
279275
fun deleteCountriesRecursively() = _dbTransaction {
280276
_db.routeCommentDao().deleteAll()
281277
_db.routeDao().deleteAll()

app/src/main/java/com/yacgroup/yacguide/database/RegionDao.kt

-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,4 @@ interface RegionDao {
4848

4949
@Query(DELETE_REGIONS)
5050
fun deleteAll()
51-
52-
@Query("$DELETE_REGIONS WHERE Region.country = :countryName")
53-
fun deleteAll(countryName: String)
5451
}

0 commit comments

Comments
 (0)