Skip to content

Commit 4d75507

Browse files
committed
add legacy to new format timestamp test
1 parent 41ee794 commit 4d75507

File tree

1 file changed

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

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ class FirebaseFirestoreTest {
459459
assertNotEquals(DoubleAsTimestampSerializer.serverTimestamp, pendingWritesSnapshot.data(DoubleTimestamp.serializer(), ServerTimestampBehavior.ESTIMATE).time)
460460
}
461461

462+
@Test
463+
fun testLegacyDoubleTimestampWriteNewFormatRead() = runTest {
464+
@Serializable
465+
data class LegacyDocument(
466+
@Serializable(with = DoubleAsTimestampSerializer::class)
467+
val time: Double
468+
)
469+
470+
@Serializable
471+
data class NewDocument(
472+
val time: Timestamp
473+
)
474+
475+
val doc = Firebase.firestore
476+
.collection("testLegacyDoubleTimestampEncodeDecode")
477+
.document("testLegacy")
478+
479+
val ms = 12345678.0
480+
481+
doc.set(LegacyDocument(time = ms))
482+
483+
val fetched: NewDocument = doc.get().data()
484+
assertEquals(ms, fetched.time.toMilliseconds())
485+
}
486+
462487
@Test
463488
fun testQueryByTimestamp() = runTest {
464489
@Serializable

0 commit comments

Comments
 (0)