Skip to content

Commit

Permalink
check if there is any orderby clause (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Aug 22, 2023
1 parent 01f669c commit 9df7c25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,9 @@ public Query endAt(Object... fieldValues) {
}

private void warningOnSingleDocumentReference(Object... fieldValues) {
if (fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference) {
if (options.getFieldOrders().isEmpty()
&& fieldValues.length == 1
&& fieldValues[0] instanceof DocumentReference) {
LOGGER.warning(
"Warning: Passing DocumentReference into a cursor without orderBy clause is not an intended "
+ "behavior. Please use DocumentSnapshot or add an explicit orderBy on document key field.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,23 @@ public void withDocumentReferenceCursor() {
assertEquals(queryRequest, runQuery.getValue());
}

@Test
public void withDocumentIdAndDocumentReferenceCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
.streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());

DocumentReference documentCursor = firestoreMock.document(DOCUMENT_PATH);
Value documentValue = reference(DOCUMENT_NAME);

query.orderBy(FieldPath.documentId()).startAt(documentCursor).get();

RunQueryRequest queryRequest =
query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentValue, true));

assertEquals(queryRequest, runQuery.getValue());
}

@Test
public void withExtractedDirectionForDocumentSnapshotCursor() {
doAnswer(queryResponse())
Expand Down

0 comments on commit 9df7c25

Please sign in to comment.