Skip to content

Commit 946c0ba

Browse files
committed
format
1 parent 1af8c3c commit 946c0ba

File tree

2 files changed

+95
-97
lines changed

2 files changed

+95
-97
lines changed

packages/firestore/test/integration/api/composite_index_query.test.ts

Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -34,111 +34,108 @@ import { apiDescribe } from '../util/helpers';
3434
* isolation and query construction.
3535
*
3636
* 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.
4040
*/
4141

4242
apiDescribe('Composite Index Queries', persistence => {
4343
// OR Query tests only run when the SDK's local cache is configured to use
4444
// LRU garbage collection (rather than eager garbage collection) because
4545
// they validate that the result from server and cache match.
4646
// 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+
);
7269
});
70+
});
7371

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+
);
9492

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+
);
105103

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+
);
118116

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+
);
129127

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+
);
141138
});
142-
}
143-
);
139+
});
140+
});
144141
});

packages/firestore/test/integration/util/composite_index_test_helper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { COMPOSITE_INDEX_TEST_COLLECTION, DEFAULT_SETTINGS } from './settings';
4949
* Key Features:
5050
* - Runs tests against the dedicated test collection with predefined composite indexes.
5151
* - Automatically associates a test ID with documents for data isolation.
52+
* - Utilizes TTL policy for automatic test data cleanup.
5253
* - Constructs Firestore queries with test ID filters.
5354
*/
5455
export class CompositeIndexTestHelper {
@@ -155,20 +156,20 @@ export class CompositeIndexTestHelper {
155156
reference: CollectionReference<T, DbModelType>,
156157
data: object
157158
): Promise<DocumentReference<T, DbModelType>> {
158-
const docWithTestId = this.addTestSpecificFieldsToDoc(
159+
const processedData = this.addTestSpecificFieldsToDoc(
159160
data
160161
) as WithFieldValue<T>;
161-
return addDocument(reference, docWithTestId);
162+
return addDocument(reference, processedData);
162163
}
163164

164165
// Sets a document in Firestore with test-specific fields.
165166
setDoc<T, DbModelType extends DocumentData>(
166167
reference: DocumentReference<T, DbModelType>,
167168
data: object
168169
): Promise<void> {
169-
const docWithTestId = this.addTestSpecificFieldsToDoc(
170+
const processedData = this.addTestSpecificFieldsToDoc(
170171
data
171172
) as WithFieldValue<T>;
172-
return setDocument(reference, docWithTestId);
173+
return setDocument(reference, processedData);
173174
}
174175
}

0 commit comments

Comments
 (0)