Skip to content

Commit 9f47522

Browse files
committed
add invalid collection test
1 parent 38faa63 commit 9f47522

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

packages/firestore/src/remote/datastore.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ export async function invokeRunAggregationQueryRpc(
250250
if (!datastoreImpl.connection.shouldResourcePathBeIncludedInRequest) {
251251
delete request.parent;
252252
}
253-
const EXPECTED_RESPONSE_COUNT = 1;
254253
const response = await datastoreImpl.invokeStreamingRPC<
255254
ProtoRunAggregationQueryRequest,
256255
ProtoRunAggregationQueryResponse
257-
>('RunAggregationQuery', parent!, request, EXPECTED_RESPONSE_COUNT);
256+
>('RunAggregationQuery', parent!, request, /*expectedResponseCount=*/ 1);
258257
return (
259258
response
260259
// Omit RunAggregationQueryResponse that only contain readTimes.

packages/firestore/test/lite/integration.test.ts

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,8 +2050,8 @@ describe('countQuery()', () => {
20502050
});
20512051

20522052
it('run count query on empty test collection', () => {
2053-
return withTestCollection(async collection => {
2054-
const snapshot = await getCount(query(collection));
2053+
return withTestCollection(async coll => {
2054+
const snapshot = await getCount(coll);
20552055
expect(snapshot.data().count).to.equal(0);
20562056
});
20572057
});
@@ -2062,20 +2062,34 @@ describe('countQuery()', () => {
20622062
{ author: 'authorA', title: 'titleB' },
20632063
{ author: 'authorB', title: 'titleC' }
20642064
];
2065-
return withTestCollectionAndInitialData(testDocs, async collection => {
2066-
const snapshot = await getCount(query(collection));
2065+
return withTestCollectionAndInitialData(testDocs, async coll => {
2066+
const snapshot = await getCount(coll);
20672067
expect(snapshot.data().count).to.equal(3);
20682068
});
20692069
});
20702070

2071+
it('run count query fails on invalid collection reference', () => {
2072+
return withTestDb(async db => {
2073+
const queryForRejection = collection(db, '__badpath__');
2074+
2075+
try {
2076+
await getCount(queryForRejection);
2077+
} catch (e) {
2078+
expect((e as Error)?.message).to.equal(
2079+
'Request failed with error: Bad Request'
2080+
);
2081+
}
2082+
});
2083+
});
2084+
20712085
it('count query supports filter', () => {
20722086
const testDocs = [
20732087
{ author: 'authorA', title: 'titleA' },
20742088
{ author: 'authorA', title: 'titleB' },
20752089
{ author: 'authorB', title: 'titleC' }
20762090
];
2077-
return withTestCollectionAndInitialData(testDocs, async collection => {
2078-
const query_ = query(collection, where('author', '==', 'authorA'));
2091+
return withTestCollectionAndInitialData(testDocs, async coll => {
2092+
const query_ = query(coll, where('author', '==', 'authorA'));
20792093
const snapshot = await getCount(query_);
20802094
expect(snapshot.data().count).to.equal(2);
20812095
});
@@ -2087,12 +2101,8 @@ describe('countQuery()', () => {
20872101
{ author: 'authorA', title: 'titleB' },
20882102
{ author: 'authorB', title: 'titleC' }
20892103
];
2090-
return withTestCollectionAndInitialData(testDocs, async collection => {
2091-
const query_ = query(
2092-
collection,
2093-
where('author', '==', 'authorA'),
2094-
limit(1)
2095-
);
2104+
return withTestCollectionAndInitialData(testDocs, async coll => {
2105+
const query_ = query(coll, where('author', '==', 'authorA'), limit(1));
20962106
const snapshot = await getCount(query_);
20972107
expect(snapshot.data().count).to.equal(1);
20982108
});
@@ -2104,12 +2114,8 @@ describe('countQuery()', () => {
21042114
{ author: 'authorA', title: 'titleB' },
21052115
{ author: 'authorB', title: 'titleC' }
21062116
];
2107-
return withTestCollectionAndInitialData(testDocs, async collection => {
2108-
const query_ = query(
2109-
collection,
2110-
where('author', '==', 'authorA'),
2111-
limit(3)
2112-
);
2117+
return withTestCollectionAndInitialData(testDocs, async coll => {
2118+
const query_ = query(coll, where('author', '==', 'authorA'), limit(3));
21132119
const snapshot = await getCount(query_);
21142120
expect(snapshot.data().count).to.equal(2);
21152121
});
@@ -2122,8 +2128,8 @@ describe('countQuery()', () => {
21222128
{ author: 'authorB', title: null },
21232129
{ author: 'authorB' }
21242130
];
2125-
return withTestCollectionAndInitialData(testDocs, async collection => {
2126-
const query_ = query(collection, orderBy('title'));
2131+
return withTestCollectionAndInitialData(testDocs, async coll => {
2132+
const query_ = query(coll, orderBy('title'));
21272133
const snapshot = await getCount(query_);
21282134
expect(snapshot.data().count).to.equal(3);
21292135
});
@@ -2136,8 +2142,8 @@ describe('countQuery()', () => {
21362142
{ id: 2, author: 'authorB', title: 'titleC' },
21372143
{ id: null, author: 'authorB', title: 'titleD' }
21382144
];
2139-
return withTestCollectionAndInitialData(testDocs, async collection => {
2140-
const query_ = query(collection, orderBy('id'), startAt(2));
2145+
return withTestCollectionAndInitialData(testDocs, async coll => {
2146+
const query_ = query(coll, orderBy('id'), startAt(2));
21412147
const snapshot = await getCount(query_);
21422148
expect(snapshot.data().count).to.equal(2);
21432149
});
@@ -2150,8 +2156,8 @@ describe('countQuery()', () => {
21502156
{ id: 2, author: 'authorB', title: 'titleC' },
21512157
{ id: null, author: 'authorB', title: 'titleD' }
21522158
];
2153-
return withTestCollectionAndInitialData(testDocs, async collection => {
2154-
const query_ = query(collection, orderBy('id'), startAfter(2));
2159+
return withTestCollectionAndInitialData(testDocs, async coll => {
2160+
const query_ = query(coll, orderBy('id'), startAfter(2));
21552161
const snapshot = await getCount(query_);
21562162
expect(snapshot.data().count).to.equal(1);
21572163
});
@@ -2164,8 +2170,8 @@ describe('countQuery()', () => {
21642170
{ id: 2, author: 'authorB', title: 'titleC' },
21652171
{ id: null, author: 'authorB', title: 'titleD' }
21662172
];
2167-
return withTestCollectionAndInitialData(testDocs, async collection => {
2168-
const query_ = query(collection, orderBy('id'), startAt(1), endAt(2));
2173+
return withTestCollectionAndInitialData(testDocs, async coll => {
2174+
const query_ = query(coll, orderBy('id'), startAt(1), endAt(2));
21692175
const snapshot = await getCount(query_);
21702176
expect(snapshot.data().count).to.equal(2);
21712177
});
@@ -2178,8 +2184,8 @@ describe('countQuery()', () => {
21782184
{ id: 2, author: 'authorB', title: 'titleC' },
21792185
{ id: null, author: 'authorB', title: 'titleD' }
21802186
];
2181-
return withTestCollectionAndInitialData(testDocs, async collection => {
2182-
const query_ = query(collection, orderBy('id'), startAt(1), endBefore(2));
2187+
return withTestCollectionAndInitialData(testDocs, async coll => {
2188+
const query_ = query(coll, orderBy('id'), startAt(1), endBefore(2));
21832189
const snapshot = await getCount(query_);
21842190
expect(snapshot.data().count).to.equal(1);
21852191
});
@@ -2191,9 +2197,9 @@ describe('countQuery()', () => {
21912197
{ author: 'authorA', title: 'titleB' },
21922198
{ author: 'authorB', title: 'titleC' }
21932199
];
2194-
return withTestCollectionAndInitialData(testDocs, async collection => {
2200+
return withTestCollectionAndInitialData(testDocs, async coll => {
21952201
const query_ = query(
2196-
collection,
2202+
coll,
21972203
where('author', '==', 'authorA')
21982204
).withConverter(postConverter);
21992205
const snapshot = await getCount(query_);
@@ -2223,15 +2229,15 @@ describe('countQuery()', () => {
22232229
});
22242230
});
22252231

2226-
it('aggregateSnapshotEqual on same queries', () => {
2232+
it('aggregateSnapshotEqual on same queries be truthy', () => {
22272233
const testDocs = [
22282234
{ author: 'authorA', title: 'titleA' },
22292235
{ author: 'authorA', title: 'titleB' },
22302236
{ author: 'authorB', title: 'titleC' }
22312237
];
2232-
return withTestCollectionAndInitialData(testDocs, async collection => {
2233-
const query1 = query(collection, where('author', '==', 'authorA'));
2234-
const query2 = query(collection, where('author', '==', 'authorA'));
2238+
return withTestCollectionAndInitialData(testDocs, async coll => {
2239+
const query1 = query(coll, where('author', '==', 'authorA'));
2240+
const query2 = query(coll, where('author', '==', 'authorA'));
22352241
const snapshot1A = await getCount(query1);
22362242
const snapshot1B = await getCount(query1);
22372243
const snapshot2 = await getCount(query2);
@@ -2240,26 +2246,26 @@ describe('countQuery()', () => {
22402246
});
22412247
});
22422248

2243-
it('aggregateSnapshotEqual on different queries', () => {
2249+
it('aggregateSnapshotEqual on different queries be falsy', () => {
22442250
const testDocs = [
22452251
{ author: 'authorA', title: 'titleA' },
22462252
{ author: 'authorA', title: 'titleB' },
22472253
{ author: 'authorB', title: 'titleC' },
22482254
{ author: 'authorB', title: 'titleD' }
22492255
];
2250-
return withTestCollectionAndInitialData(testDocs, async collection => {
2251-
const query1 = query(collection, where('author', '==', 'authorA'));
2252-
const query2 = query(collection, where('author', '==', 'authorB'));
2256+
return withTestCollectionAndInitialData(testDocs, async coll => {
2257+
const query1 = query(coll, where('author', '==', 'authorA'));
2258+
const query2 = query(coll, where('author', '==', 'authorB'));
22532259
const snapshot1 = await getCount(query1);
22542260
const snapshot2 = await getCount(query2);
22552261
expect(aggregateSnapshotEqual(snapshot1, snapshot2)).to.be.false;
22562262
});
22572263
});
22582264

22592265
it('count query fails on a terminated Firestore', () => {
2260-
return withTestCollection(async collection => {
2261-
await terminate(collection.firestore);
2262-
expect(() => getCount(query(collection))).to.throw(
2266+
return withTestCollection(async coll => {
2267+
await terminate(coll.firestore);
2268+
expect(() => getCount(coll)).to.throw(
22632269
'The client has already been terminated.'
22642270
);
22652271
});
@@ -2271,9 +2277,9 @@ describe('countQuery()', () => {
22712277
{ author: 'authorA', title: 'titleB' },
22722278
{ author: 'authorB', title: 'titleC' }
22732279
];
2274-
return withTestCollectionAndInitialData(testDocs, async collection => {
2275-
const promise = getCount(query(collection));
2276-
await terminate(collection.firestore);
2280+
return withTestCollectionAndInitialData(testDocs, async coll => {
2281+
const promise = getCount(coll);
2282+
await terminate(coll.firestore);
22772283
const snapshot = await promise;
22782284
expect(snapshot.data().count).to.equal(3);
22792285
});

0 commit comments

Comments
 (0)