-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TileSourceEntity id generation. (#2045)
* Fix TileSourceEntity id generation. Room treats non-null values assigned to boxed types (e.g. Int?, Integer) as explicit values and will not auto-generate IDs when these values are provided. This was causing UNIQUNESS constraint failures when inserting/updating tilesource entites, as we were using `0` as a default. Converting to a non-boxed primitive type `Int` results in the correct behavior (Room treats `0` as an indicator that a value should be generated).
- Loading branch information
Showing
3 changed files
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import com.google.android.ground.model.geometry.LinearRing | |
import com.google.android.ground.model.geometry.Point | ||
import com.google.android.ground.model.geometry.Polygon | ||
import com.google.android.ground.model.imagery.OfflineArea | ||
import com.google.android.ground.model.imagery.TileSource | ||
import com.google.android.ground.model.job.Job | ||
import com.google.android.ground.model.job.Style | ||
import com.google.android.ground.model.mutation.LocationOfInterestMutation | ||
|
@@ -375,6 +376,12 @@ class LocalDataStoreTests : BaseHiltTest() { | |
assertThat(localValueStore.isTermsOfServiceAccepted).isFalse() | ||
} | ||
|
||
@Test | ||
fun testInsertOrUpdateSurvey_usesUniqueKeyForTileSources() = runWithTestDispatcher { | ||
// Should not throw. | ||
localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY_WITH_TILE_SOURCES) | ||
} | ||
|
||
companion object { | ||
private val TEST_USER = User("user id", "[email protected]", "user 1") | ||
private val TEST_TASK = Task("task id", 1, Task.Type.TEXT, "task label", false) | ||
|
@@ -383,6 +390,14 @@ class LocalDataStoreTests : BaseHiltTest() { | |
Job("job id", TEST_STYLE, "heading title", mapOf(Pair(TEST_TASK.id, TEST_TASK))) | ||
private val TEST_SURVEY = | ||
Survey("survey id", "survey 1", "foo description", mapOf(Pair(TEST_JOB.id, TEST_JOB))) | ||
private val TEST_SURVEY_WITH_TILE_SOURCES = | ||
TEST_SURVEY.copy( | ||
tileSources = | ||
listOf( | ||
TileSource(url = "dummy URL", type = TileSource.Type.TILED_WEB_MAP), | ||
TileSource(url = "other dummy URL", type = TileSource.Type.TILED_WEB_MAP) | ||
) | ||
) | ||
private val TEST_POINT = Point(Coordinates(110.0, -23.1)) | ||
private val TEST_POINT_2 = Point(Coordinates(51.0, 44.0)) | ||
private val TEST_POLYGON_1 = | ||
|