@@ -34,111 +34,108 @@ import { apiDescribe } from '../util/helpers';
34
34
* isolation and query construction.
35
35
*
36
36
* Please remember to update the main index configuration file (firestore_index_config.tf)
37
- * with any new composite indexes required by the test cases to maintain synchronization
38
- * of other testing environments, including CI. The required composite index can be generated by
39
- * clicking on the link to Firebase console in error message while running the test locally.
37
+ * with any new composite indexes needed for the tests. This ensures synchronization with
38
+ * other testing environments, including CI. You can generate the required index link by
39
+ * clicking on the Firebase console link in the error message while running tests locally.
40
40
*/
41
41
42
42
apiDescribe ( 'Composite Index Queries' , persistence => {
43
43
// OR Query tests only run when the SDK's local cache is configured to use
44
44
// LRU garbage collection (rather than eager garbage collection) because
45
45
// they validate that the result from server and cache match.
46
46
// eslint-disable-next-line no-restricted-properties
47
- ( persistence . gc === 'lru' ? describe . only : describe . skip ) (
48
- 'OR Queries' ,
49
- ( ) => {
50
- it ( 'can use query overloads' , ( ) => {
51
- const testDocs = {
52
- doc1 : { a : 1 , b : 0 } ,
53
- doc2 : { a : 2 , b : 1 } ,
54
- doc3 : { a : 3 , b : 2 } ,
55
- doc4 : { a : 1 , b : 3 } ,
56
- doc5 : { a : 1 , b : 1 }
57
- } ;
58
- const testHelper = new CompositeIndexTestHelper ( ) ;
59
- return testHelper . withTestDocs ( persistence , testDocs , async coll => {
60
- // a == 1, limit 2, b - desc
61
- await testHelper . assertOnlineAndOfflineResultsMatch (
62
- testHelper . query (
63
- coll ,
64
- where ( 'a' , '==' , 1 ) ,
65
- limit ( 2 ) ,
66
- orderBy ( 'b' , 'desc' )
67
- ) ,
68
- 'doc4' ,
69
- 'doc5'
70
- ) ;
71
- } ) ;
47
+ ( persistence . gc === 'lru' ? describe : describe . skip ) ( 'OR Queries' , ( ) => {
48
+ it ( 'can use query overloads' , ( ) => {
49
+ const testDocs = {
50
+ doc1 : { a : 1 , b : 0 } ,
51
+ doc2 : { a : 2 , b : 1 } ,
52
+ doc3 : { a : 3 , b : 2 } ,
53
+ doc4 : { a : 1 , b : 3 } ,
54
+ doc5 : { a : 1 , b : 1 }
55
+ } ;
56
+ const testHelper = new CompositeIndexTestHelper ( ) ;
57
+ return testHelper . withTestDocs ( persistence , testDocs , async coll => {
58
+ // a == 1, limit 2, b - desc
59
+ await testHelper . assertOnlineAndOfflineResultsMatch (
60
+ testHelper . query (
61
+ coll ,
62
+ where ( 'a' , '==' , 1 ) ,
63
+ limit ( 2 ) ,
64
+ orderBy ( 'b' , 'desc' )
65
+ ) ,
66
+ 'doc4' ,
67
+ 'doc5'
68
+ ) ;
72
69
} ) ;
70
+ } ) ;
73
71
74
- it ( 'can use or queries' , ( ) => {
75
- const testDocs = {
76
- doc1 : { a : 1 , b : 0 } ,
77
- doc2 : { a : 2 , b : 1 } ,
78
- doc3 : { a : 3 , b : 2 } ,
79
- doc4 : { a : 1 , b : 3 } ,
80
- doc5 : { a : 1 , b : 1 }
81
- } ;
82
- const testHelper = new CompositeIndexTestHelper ( ) ;
83
- return testHelper . withTestDocs ( persistence , testDocs , async coll => {
84
- // with one inequality: a>2 || b==1.
85
- await testHelper . assertOnlineAndOfflineResultsMatch (
86
- testHelper . compositeQuery (
87
- coll ,
88
- or ( where ( 'a' , '>' , 2 ) , where ( 'b' , '==' , 1 ) )
89
- ) ,
90
- 'doc5' ,
91
- 'doc2' ,
92
- 'doc3'
93
- ) ;
72
+ it ( 'can use or queries' , ( ) => {
73
+ const testDocs = {
74
+ doc1 : { a : 1 , b : 0 } ,
75
+ doc2 : { a : 2 , b : 1 } ,
76
+ doc3 : { a : 3 , b : 2 } ,
77
+ doc4 : { a : 1 , b : 3 } ,
78
+ doc5 : { a : 1 , b : 1 }
79
+ } ;
80
+ const testHelper = new CompositeIndexTestHelper ( ) ;
81
+ return testHelper . withTestDocs ( persistence , testDocs , async coll => {
82
+ // with one inequality: a>2 || b==1.
83
+ await testHelper . assertOnlineAndOfflineResultsMatch (
84
+ testHelper . compositeQuery (
85
+ coll ,
86
+ or ( where ( 'a' , '>' , 2 ) , where ( 'b' , '==' , 1 ) )
87
+ ) ,
88
+ 'doc5' ,
89
+ 'doc2' ,
90
+ 'doc3'
91
+ ) ;
94
92
95
- // Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2
96
- await testHelper . assertOnlineAndOfflineResultsMatch (
97
- testHelper . compositeQuery (
98
- coll ,
99
- or ( where ( 'a' , '==' , 1 ) , where ( 'b' , '>' , 0 ) ) ,
100
- limit ( 2 )
101
- ) ,
102
- 'doc1' ,
103
- 'doc2'
104
- ) ;
93
+ // Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2
94
+ await testHelper . assertOnlineAndOfflineResultsMatch (
95
+ testHelper . compositeQuery (
96
+ coll ,
97
+ or ( where ( 'a' , '==' , 1 ) , where ( 'b' , '>' , 0 ) ) ,
98
+ limit ( 2 )
99
+ ) ,
100
+ 'doc1' ,
101
+ 'doc2'
102
+ ) ;
105
103
106
- // Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2
107
- // Note: The public query API does not allow implicit ordering when limitToLast is used.
108
- await testHelper . assertOnlineAndOfflineResultsMatch (
109
- testHelper . compositeQuery (
110
- coll ,
111
- or ( where ( 'a' , '==' , 1 ) , where ( 'b' , '>' , 0 ) ) ,
112
- limitToLast ( 2 ) ,
113
- orderBy ( 'b' )
114
- ) ,
115
- 'doc3' ,
116
- 'doc4'
117
- ) ;
104
+ // Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2
105
+ // Note: The public query API does not allow implicit ordering when limitToLast is used.
106
+ await testHelper . assertOnlineAndOfflineResultsMatch (
107
+ testHelper . compositeQuery (
108
+ coll ,
109
+ or ( where ( 'a' , '==' , 1 ) , where ( 'b' , '>' , 0 ) ) ,
110
+ limitToLast ( 2 ) ,
111
+ orderBy ( 'b' )
112
+ ) ,
113
+ 'doc3' ,
114
+ 'doc4'
115
+ ) ;
118
116
119
- // Test with limits (explicit order by ASC): (a==2) || (b == 1) ORDER BY a LIMIT 1
120
- await testHelper . assertOnlineAndOfflineResultsMatch (
121
- testHelper . compositeQuery (
122
- coll ,
123
- or ( where ( 'a' , '==' , 2 ) , where ( 'b' , '==' , 1 ) ) ,
124
- limit ( 1 ) ,
125
- orderBy ( 'a' )
126
- ) ,
127
- 'doc5'
128
- ) ;
117
+ // Test with limits (explicit order by ASC): (a==2) || (b == 1) ORDER BY a LIMIT 1
118
+ await testHelper . assertOnlineAndOfflineResultsMatch (
119
+ testHelper . compositeQuery (
120
+ coll ,
121
+ or ( where ( 'a' , '==' , 2 ) , where ( 'b' , '==' , 1 ) ) ,
122
+ limit ( 1 ) ,
123
+ orderBy ( 'a' )
124
+ ) ,
125
+ 'doc5'
126
+ ) ;
129
127
130
- // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a LIMIT_TO_LAST 1
131
- await testHelper . assertOnlineAndOfflineResultsMatch (
132
- testHelper . compositeQuery (
133
- coll ,
134
- or ( where ( 'a' , '==' , 2 ) , where ( 'b' , '==' , 1 ) ) ,
135
- limitToLast ( 1 ) ,
136
- orderBy ( 'a' )
137
- ) ,
138
- 'doc2'
139
- ) ;
140
- } ) ;
128
+ // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a LIMIT_TO_LAST 1
129
+ await testHelper . assertOnlineAndOfflineResultsMatch (
130
+ testHelper . compositeQuery (
131
+ coll ,
132
+ or ( where ( 'a' , '==' , 2 ) , where ( 'b' , '==' , 1 ) ) ,
133
+ limitToLast ( 1 ) ,
134
+ orderBy ( 'a' )
135
+ ) ,
136
+ 'doc2'
137
+ ) ;
141
138
} ) ;
142
- }
143
- ) ;
139
+ } ) ;
140
+ } ) ;
144
141
} ) ;
0 commit comments