Skip to content

Commit

Permalink
Adding queryWithMicrosecondPrecision test
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed May 29, 2018
1 parent b7cee60 commit 1d1a2c2
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void serverTimestamp() throws Exception {
}

@Test
public void updateMicrosecondTimestamp() throws Exception {
public void timestampDoesntGetTruncatedDuringUpdate() throws Exception {
DocumentReference documentReference = addDocument("time", Timestamp.ofTimeSecondsAndNanos(0, 123000));
DocumentSnapshot documentSnapshot = documentReference.get().get();

Expand Down Expand Up @@ -265,6 +265,23 @@ public void noResults() throws Exception {
assertNotNull(querySnapshot.getReadTime());
}

@Test
public void queryWithMicrosecondPrecision() throws Exception {
Timestamp microsecondTimestamp = Timestamp.ofTimeSecondsAndNanos(0, 123000);

DocumentReference documentReference = addDocument("time", microsecondTimestamp);
DocumentSnapshot documentSnapshot = documentReference.get().get();

Query query = randomColl.whereEqualTo("time", microsecondTimestamp);
QuerySnapshot querySnapshot = query.get().get();
assertEquals(1, querySnapshot.size());

// Using `.toDate()` truncates to millseconds, and hence the query doesn't match.
query = randomColl.whereEqualTo("time", microsecondTimestamp.toDate());
querySnapshot = query.get().get();
assertEquals(0, querySnapshot.size());
}

@Test
public void nestedQuery() throws Exception {
randomColl = randomColl.document("foo").collection("bar");
Expand Down

0 comments on commit 1d1a2c2

Please sign in to comment.