Skip to content

Commit b4a2f60

Browse files
russellwheatleyguide-loclt
authored andcommitted
ci: update tests for arrayContainsAny & isNotEqualTo which now result in a "failed-precondition" exception. (firebase#12529)
1 parent 18ef898 commit b4a2f60

File tree

1 file changed

+89
-22
lines changed

1 file changed

+89
-22
lines changed

packages/cloud_firestore/cloud_firestore/example/integration_test/second_database.dart

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ void runSecondDatabaseTests() {
120120
});
121121
});
122122
/**
123-
* get
124-
*/
123+
* get
124+
*/
125125
group('Query.get()', () {
126126
testWidgets('returns a [QuerySnapshot]', (_) async {
127127
CollectionReference<Map<String, dynamic>> collection =
@@ -194,8 +194,8 @@ void runSecondDatabaseTests() {
194194
});
195195

196196
/**
197-
* snapshots
198-
*/
197+
* snapshots
198+
*/
199199
group('Query.snapshots()', () {
200200
testWidgets('returns a [Stream]', (_) async {
201201
CollectionReference<Map<String, dynamic>> collection =
@@ -340,8 +340,8 @@ void runSecondDatabaseTests() {
340340
});
341341

342342
/**
343-
* End At
344-
*/
343+
* End At
344+
*/
345345

346346
group('Query.endAt{Document}()', () {
347347
testWidgets('ends at string field paths', (_) async {
@@ -506,8 +506,8 @@ void runSecondDatabaseTests() {
506506
});
507507

508508
/**
509-
* Start At
510-
*/
509+
* Start At
510+
*/
511511

512512
group('Query.startAt{Document}()', () {
513513
testWidgets('starts at string field paths', (_) async {
@@ -671,8 +671,8 @@ void runSecondDatabaseTests() {
671671
});
672672

673673
/**
674-
* End Before
675-
*/
674+
* End Before
675+
*/
676676

677677
group('Query.endBefore{Document}()', () {
678678
testWidgets('ends before string field paths', (_) async {
@@ -837,8 +837,8 @@ void runSecondDatabaseTests() {
837837
});
838838

839839
/**
840-
* Start after
841-
*/
840+
* Start after
841+
*/
842842
group('Query.startAfter{Document}()', () {
843843
testWidgets('starts after string field paths', (_) async {
844844
CollectionReference<Map<String, dynamic>> collection =
@@ -968,8 +968,8 @@ void runSecondDatabaseTests() {
968968
});
969969

970970
/**
971-
* Start & End
972-
*/
971+
* Start & End
972+
*/
973973

974974
group('Query.startAt/endAt', () {
975975
testWidgets('starts at & ends at a document', (_) async {
@@ -1084,8 +1084,8 @@ void runSecondDatabaseTests() {
10841084
});
10851085

10861086
/**
1087-
* Limit
1088-
*/
1087+
* Limit
1088+
*/
10891089

10901090
group('Query.limit{toLast}()', () {
10911091
testWidgets('limits documents', (_) async {
@@ -1152,8 +1152,8 @@ void runSecondDatabaseTests() {
11521152
});
11531153

11541154
/**
1155-
* Order
1156-
*/
1155+
* Order
1156+
*/
11571157
group('Query.orderBy()', () {
11581158
testWidgets('allows ordering by documentId', (_) async {
11591159
CollectionReference<Map<String, dynamic>> collection =
@@ -1236,8 +1236,8 @@ void runSecondDatabaseTests() {
12361236
});
12371237

12381238
/**
1239-
* Where filters
1240-
*/
1239+
* Where filters
1240+
*/
12411241

12421242
group('Query.where()', () {
12431243
testWidgets(
@@ -1820,15 +1820,82 @@ void runSecondDatabaseTests() {
18201820
Filter('totalDomesticRevenue', isEqualTo: 60000000),
18211821
Filter('totalWorldwideRevenue', isEqualTo: 200000000),
18221822
Filter('estimatedProfit', isEqualTo: 140000000),
1823-
// Fails because this is not allowed when arrayContainsAny is included in the Query
1823+
// Inequality causes "failed-precondition" exception and asks user to create an index
18241824
Filter('mainCharacter', isNotEqualTo: 'MainCharacter2'),
18251825
),
18261826
)
18271827
.orderBy('rating', descending: true)
18281828
.get(),
18291829
throwsA(
18301830
isA<FirebaseException>()
1831-
.having((e) => e.code, 'code', 'invalid-argument'),
1831+
.having((e) => e.code, 'code', 'failed-precondition')
1832+
.having(
1833+
(e) => e.message,
1834+
'message',
1835+
contains(
1836+
'The query contains range and inequality filters on multiple fields',
1837+
),
1838+
),
1839+
),
1840+
);
1841+
},
1842+
);
1843+
1844+
testWidgets(
1845+
'Exception thrown when combining `arrayContainsAny` & `isNotEqualTo` in multiple conjunctive queries',
1846+
(_) async {
1847+
CollectionReference<Map<String, dynamic>> collection =
1848+
await initializeTest('multiple-conjunctive-queries');
1849+
1850+
await expectLater(
1851+
collection
1852+
.where(
1853+
Filter.and(
1854+
Filter('rating1', isEqualTo: 3.8),
1855+
Filter('year1', isEqualTo: 1970),
1856+
Filter('runtime1', isEqualTo: 90),
1857+
Filter('director1', isEqualTo: 'Director2'),
1858+
Filter('producer1', isEqualTo: 'Producer2'),
1859+
Filter('budget1', isEqualTo: 20000000),
1860+
Filter('boxOffice1', isEqualTo: 50000000),
1861+
Filter('actor1', isEqualTo: 'Actor2'),
1862+
Filter('language1', isEqualTo: 'English'),
1863+
Filter('award1', isEqualTo: 'Award2'),
1864+
Filter('genre1', arrayContainsAny: ['sci-fi']),
1865+
Filter('country1', isEqualTo: 'USA'),
1866+
Filter('released1', isEqualTo: true),
1867+
Filter('screenplay1', isEqualTo: 'Screenplay2'),
1868+
Filter('cinematography1', isEqualTo: 'Cinematography2'),
1869+
Filter('music1', isEqualTo: 'Music2'),
1870+
Filter('rating2', isEqualTo: 4.2),
1871+
Filter('year2', isEqualTo: 1982),
1872+
Filter('runtime2', isEqualTo: 60),
1873+
Filter('director2', isEqualTo: 'Director3'),
1874+
Filter('producer2', isEqualTo: 'Producer3'),
1875+
Filter('budget2', isEqualTo: 30000000),
1876+
Filter('boxOffice2', isEqualTo: 60000000),
1877+
Filter('actor2', isEqualTo: 'Actor3'),
1878+
Filter('language2', isEqualTo: 'Korean'),
1879+
Filter('award2', isEqualTo: 'Award3'),
1880+
Filter('genre2', isEqualTo: ['sci-fi', 'action']),
1881+
Filter('country2', isEqualTo: 'South Korea'),
1882+
Filter('released2', isEqualTo: false),
1883+
// Inequality causes "failed-precondition" exception and asks user to create an index
1884+
Filter('screenplay2', isNotEqualTo: 'blah'),
1885+
),
1886+
)
1887+
.orderBy('rating1', descending: true)
1888+
.get(),
1889+
throwsA(
1890+
isA<FirebaseException>()
1891+
.having((e) => e.code, 'code', 'failed-precondition')
1892+
.having(
1893+
(e) => e.message,
1894+
'message',
1895+
contains(
1896+
'The query contains range and inequality filters on multiple fields',
1897+
),
1898+
),
18321899
),
18331900
);
18341901
},

0 commit comments

Comments
 (0)