Skip to content

Commit

Permalink
test(firestore): additional coverage for startAfterDocument() (#16697)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Nov 22, 2024
1 parent 1ef2044 commit aba66b0
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'
push:
Expand All @@ -19,6 +20,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'
push:
Expand All @@ -19,6 +20,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'
push:
Expand All @@ -19,6 +20,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'
push:
Expand All @@ -19,6 +20,7 @@ on:
- 'docs/**'
- 'website/**'
- '**/example/**'
- '!**/example/integration_test/**'
- '**/flutterfire_ui/**'
- '**.md'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,134 @@ void runQueryTests() {
expect(snapshot.docs[0].id, equals('doc3'));
expect(snapshot.docs[1].id, equals('doc4'));
});

testWidgets(
'throws exception without orderBy() on field used for inequality query',
(_) async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('startAfterDocument-inequality-field-throw');
await Future.wait([
collection.doc('doc1').set({
'bar': {'value': 2},
}),
collection.doc('doc2').set({
'bar': {'value': 10},
}),
collection.doc('doc3').set({
'bar': {'value': 10},
}),
collection.doc('doc4').set({
'bar': {'value': 10},
}),
]);

DocumentSnapshot startAtSnapshot = await collection.doc('doc2').get();
Query inequalityQuery =
collection.where('bar.value', isGreaterThan: 5);

await expectLater(
inequalityQuery.startAfterDocument(startAtSnapshot).get(),
throwsA(
isA<FirebaseException>().having(
(e) => e.message,
'message',
contains(
'Client specified an invalid argument',
),
),
),
);
},
// firebase-js-sdk does not require an orderBy() field to be set for this to work
skip: kIsWeb,
);

testWidgets(
'throws exception without correct orderBy("wrong-field") field used for inequality query',
(_) async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest(
'startAfterDocument-wrong-inequality-field-throw',
);
await Future.wait([
collection.doc('doc1').set({
'bar': {'value': 2},
}),
collection.doc('doc2').set(
{
'bar': {'value': 10},
'wrong-field': 2,
},
),
collection.doc('doc3').set(
{
'bar': {'value': 10},
'wrong-field': 2,
},
),
collection.doc('doc4').set(
{
'bar': {'value': 10},
'wrong-field': 2,
},
),
]);

DocumentSnapshot startAtSnapshot = await collection.doc('doc2').get();
Query inequalityQuery =
collection.where('bar.value', isGreaterThan: 5);
await expectLater(
inequalityQuery
.orderBy('wrong-field')
.startAfterDocument(startAtSnapshot)
.get(),
throwsA(
isA<FirebaseException>().having(
(e) => e.message,
'message',
contains(
'Client specified an invalid argument',
),
),
),
);
},
// firebase-js-sdk does not require an orderBy() field to be set for this to work
skip: kIsWeb,
);

testWidgets(
'Successful request when using orderBy() with same field used on inequality query',
(_) async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('startAfterDocument-correct-inequality-field');
await Future.wait([
collection.doc('doc1').set({
'bar': 2,
}),
collection.doc('doc2').set({
'bar': 10,
}),
collection.doc('doc3').set({
'bar': 11,
}),
collection.doc('doc4').set({
'bar': 12,
}),
]);

DocumentSnapshot startAtSnapshot = await collection.doc('doc2').get();
Query inequalityQuery = collection.where('bar', isGreaterThan: 5);

final result = await inequalityQuery
.orderBy('bar')
.startAfterDocument(startAtSnapshot)
.get();

expect(result.size, equals(2));
expect(result.docs[0].id, equals('doc3'));
expect(result.docs[1].id, equals('doc4'));
});
});

/**
Expand Down

0 comments on commit aba66b0

Please sign in to comment.