Skip to content

Commit 3f28db6

Browse files
add a test for querying by natively supported class
1 parent aa8189f commit 3f28db6

File tree

1 file changed

+33
-0
lines changed
  • firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore

1 file changed

+33
-0
lines changed

firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,39 @@ class FirebaseFirestoreTest {
464464
assertNotEquals(DoubleAsTimestampSerializer.serverTimestamp, pendingWritesSnapshot.data(DoubleTimestamp.serializer(), ServerTimestampBehavior.ESTIMATE).time)
465465
}
466466

467+
@Test
468+
fun testQueryByTimestamp() = runTest {
469+
@Serializable
470+
data class DocumentWithTimestamp(
471+
val time: Timestamp
472+
)
473+
474+
val collection = Firebase.firestore
475+
.collection("testQueryByTimestamp")
476+
477+
val timestamp = Timestamp.now()
478+
479+
val pastTimestamp = Timestamp(timestamp.seconds - 60, timestamp.nanoseconds)
480+
val futureTimestamp = Timestamp(timestamp.seconds + 60, timestamp.nanoseconds)
481+
482+
collection.add(DocumentWithTimestamp(pastTimestamp))
483+
collection.add(DocumentWithTimestamp(futureTimestamp))
484+
485+
val equalityQueryResult = collection.where(
486+
path = FieldPath(DocumentWithTimestamp::time.name),
487+
equalTo = pastTimestamp
488+
).get().documents.map { it.data<DocumentWithTimestamp>() }
489+
490+
assertEquals(listOf(DocumentWithTimestamp(pastTimestamp)), equalityQueryResult)
491+
492+
val gtQueryResult = collection.where(
493+
path = FieldPath(DocumentWithTimestamp::time.name),
494+
greaterThan = timestamp
495+
).get().documents.map { it.data<DocumentWithTimestamp>() }
496+
497+
assertEquals(listOf(DocumentWithTimestamp(futureTimestamp)), gtQueryResult)
498+
}
499+
467500
private suspend fun setupFirestoreData() {
468501
Firebase.firestore.collection("testFirestoreQuerying")
469502
.document("one")

0 commit comments

Comments
 (0)