Skip to content

Commit

Permalink
Add License and code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi committed Mar 8, 2024
1 parent e0cf0fa commit 198dbd6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LocalDataStoreTests : BaseHiltTest() {
@Test
fun testInsertAndGetUser() = runWithTestDispatcher {
localUserStore.insertOrUpdateUser(TEST_USER)
assertThat(localUserStore.getUser("user id")).isEqualTo(TEST_USER)
assertThat(localUserStore.getUser(FakeData.USER_ID)).isEqualTo(TEST_USER)
}

@Test
Expand Down Expand Up @@ -174,7 +174,7 @@ class LocalDataStoreTests : BaseHiltTest() {
localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY)
localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION)

val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)

localLoiStore.findLocationsOfInterest(TEST_SURVEY).test {
assertThat(expectMostRecentItem()).isEqualTo(setOf(loi))
Expand All @@ -186,10 +186,10 @@ class LocalDataStoreTests : BaseHiltTest() {
localUserStore.insertOrUpdateUser(TEST_USER)
localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY)
localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION)
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
val newLoi = loi.copy(geometry = TEST_POINT_2)
localLoiStore.merge(newLoi)
val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")
val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)
assertThat(newLoi2?.geometry).isEqualTo(TEST_POINT_2)
}

Expand All @@ -198,10 +198,10 @@ class LocalDataStoreTests : BaseHiltTest() {
localUserStore.insertOrUpdateUser(TEST_USER)
localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY)
localLoiStore.applyAndEnqueue(TEST_POLYGON_LOI_MUTATION)
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
val newLoi = loi.copy(geometry = Polygon(LinearRing(TEST_POLYGON_2)))
localLoiStore.merge(newLoi)
val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")
val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)
assertThat(newLoi2?.geometry?.getShellCoordinates()).isEqualTo(TEST_POLYGON_2)
}

Expand All @@ -220,7 +220,7 @@ class LocalDataStoreTests : BaseHiltTest() {
MutationEntitySyncStatus.PENDING
)
.test { assertThat(expectMostRecentItem()).isEqualTo(listOf(TEST_SUBMISSION_MUTATION)) }
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
var submission = localSubmissionStore.getSubmission(loi, "submission id")
assertEquivalent(TEST_SUBMISSION_MUTATION, submission)

Expand Down Expand Up @@ -253,7 +253,7 @@ class LocalDataStoreTests : BaseHiltTest() {
assertEquivalent(mutation, submission)

// also test that getSubmissions returns the same submission as well
val submissions = localSubmissionStore.getSubmissions(loi, "job id")
val submissions = localSubmissionStore.getSubmissions(loi, FakeData.JOB_ID)
assertThat(submissions).hasSize(1)
assertEquivalent(mutation, submissions[0])
}
Expand All @@ -264,7 +264,7 @@ class LocalDataStoreTests : BaseHiltTest() {
localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY)
localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION)
localSubmissionStore.applyAndEnqueue(TEST_SUBMISSION_MUTATION)
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
val data = SubmissionData(mapOf(Pair("task id", TextResponse.fromString("foo value"))))
val submission = localSubmissionStore.getSubmission(loi, "submission id").copy(data = data)
localSubmissionStore.merge(submission)
Expand All @@ -288,7 +288,7 @@ class LocalDataStoreTests : BaseHiltTest() {
assertThat(submissionDao.findById("submission id")?.state).isEqualTo(EntityState.DELETED)

// Verify that the local submission doesn't end up in getSubmissions().
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
assertThat(localSubmissionStore.getSubmissions(loi, "task id")).isEmpty()

// After successful remote sync, delete submission is called by LocalMutationSyncWorker.
Expand All @@ -308,7 +308,7 @@ class LocalDataStoreTests : BaseHiltTest() {
localSubmissionStore.applyAndEnqueue(TEST_SUBMISSION_MUTATION)

// Assert that one LOI is streamed.
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!!
val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!!
localLoiStore.findLocationsOfInterest(TEST_SURVEY).test {
assertThat(expectMostRecentItem()).isEqualTo(setOf(loi))
}
Expand All @@ -318,18 +318,19 @@ class LocalDataStoreTests : BaseHiltTest() {
localLoiStore.applyAndEnqueue(mutation)

// Verify that local entity exists but its state is updated to DELETED.
assertThat(locationOfInterestDao.findById("loi id")?.state).isEqualTo(EntityState.DELETED)
assertThat(locationOfInterestDao.findById(FakeData.LOI_ID)?.state)
.isEqualTo(EntityState.DELETED)

// Verify that the local LOI is now removed from the latest LOI stream.
localLoiStore.findLocationsOfInterest(TEST_SURVEY).test {
assertThat(expectMostRecentItem()).isEmpty()
}

// After successful remote sync, delete LOI is called by LocalMutationSyncWorker.
localLoiStore.deleteLocationOfInterest("loi id")
localLoiStore.deleteLocationOfInterest(FakeData.LOI_ID)

// Verify that the LOI doesn't exist anymore
assertThat(localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")).isNull()
assertThat(localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)).isNull()

// Verify that the linked submission is also deleted.
assertFailsWith<LocalDataStoreException> {
Expand Down Expand Up @@ -373,13 +374,13 @@ class LocalDataStoreTests : BaseHiltTest() {
}

companion object {
private val TEST_USER = User("user id", "user@gmail.com", "user 1")
private val TEST_USER = User(FakeData.USER_ID, "user@gmail.com", "user 1")
private val TEST_TASK = Task("task id", 1, Task.Type.TEXT, "task label", false)
private val TEST_STYLE = Style("#112233")
private val TEST_JOB =
Job("job id", TEST_STYLE, "heading title", mapOf(Pair(TEST_TASK.id, TEST_TASK)))
Job(FakeData.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)))
Survey(FakeData.SURVEY_ID, "survey 1", "foo description", mapOf(Pair(TEST_JOB.id, TEST_JOB)))
private val TEST_SURVEY_WITH_TILE_SOURCES =
TEST_SURVEY.copy(
tileSources =
Expand Down Expand Up @@ -419,9 +420,9 @@ class LocalDataStoreTests : BaseHiltTest() {
id = 1L,
type = Mutation.Type.CREATE,
syncStatus = SyncStatus.PENDING,
surveyId = "survey id",
locationOfInterestId = "loi id",
userId = "user id"
surveyId = FakeData.SURVEY_ID,
locationOfInterestId = FakeData.LOI_ID,
userId = FakeData.USER_ID
)
private val TEST_OFFLINE_AREA =
OfflineArea("id_1", OfflineArea.State.PENDING, Bounds(0.0, 0.0, 0.0, 0.0), "Test Area", 0..14)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.ground.persistence.remote.firebase.schema

import com.google.android.ground.model.geometry.Coordinates
Expand Down
24 changes: 14 additions & 10 deletions sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ object FakeData {
// TODO: Replace constants with calls to newFoo() methods.
val TERMS_OF_SERVICE: TermsOfService =
TermsOfService("TERMS_OF_SERVICE", "Fake Terms of Service text")
const val JOB_ID = "job id"
const val LOI_ID = "loi id"
const val USER_ID = "user id"
const val SURVEY_ID = "survey id"

val JOB =
Job(
Expand All @@ -67,7 +71,7 @@ object FakeData {

val LOCATION_OF_INTEREST =
LocationOfInterest(
"loi id",
LOI_ID,
SURVEY.id,
JOB,
customId = "",
Expand Down Expand Up @@ -99,7 +103,7 @@ object FakeData {

val AREA_OF_INTEREST: LocationOfInterest =
LocationOfInterest(
"loi id",
LOI_ID,
SURVEY.id,
JOB,
"",
Expand Down Expand Up @@ -142,14 +146,14 @@ object FakeData {
syncStatus: Mutation.SyncStatus = Mutation.SyncStatus.PENDING,
): LocationOfInterestMutation =
LocationOfInterestMutation(
jobId = "job id",
jobId = JOB_ID,
geometry = point,
id = 1L,
locationOfInterestId = "loi id",
locationOfInterestId = LOI_ID,
type = mutationType,
syncStatus = syncStatus,
userId = "user id",
surveyId = "survey id",
userId = USER_ID,
surveyId = SURVEY_ID,
clientTimestamp = Date()
)

Expand All @@ -159,14 +163,14 @@ object FakeData {
syncStatus: Mutation.SyncStatus = Mutation.SyncStatus.PENDING,
): LocationOfInterestMutation =
LocationOfInterestMutation(
jobId = "job id",
jobId = JOB_ID,
geometry = Polygon(LinearRing(polygonVertices)),
id = 1L,
locationOfInterestId = "loi id",
locationOfInterestId = LOI_ID,
type = mutationType,
syncStatus = syncStatus,
userId = "user id",
surveyId = "survey id",
userId = USER_ID,
surveyId = SURVEY_ID,
clientTimestamp = Date()
)
}

0 comments on commit 198dbd6

Please sign in to comment.