Skip to content

Commit cc839f4

Browse files
committed
PR feedback.
1 parent aa7346a commit cc839f4

File tree

3 files changed

+39
-67
lines changed

3 files changed

+39
-67
lines changed

packages/firestore/src/remote/datastore.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import { CredentialsProvider } from '../api/credentials';
1919
import { User } from '../auth/user';
2020
import { Aggregate } from '../core/aggregate';
21+
import { DatabaseId } from '../core/database_info';
2122
import { queryToAggregateTarget, Query, queryToTarget } from '../core/query';
2223
import { Document } from '../model/document';
2324
import { DocumentKey } from '../model/document_key';
2425
import { Mutation } from '../model/mutation';
26+
import { ResourcePath } from '../model/path';
2527
import {
2628
ApiClientObjectMap,
2729
BatchGetDocumentsRequest as ProtoBatchGetDocumentsRequest,
@@ -47,16 +49,13 @@ import {
4749
import {
4850
fromDocument,
4951
fromBatchGetDocumentsResponse,
50-
getEncodedDatabaseId,
5152
JsonProtoSerializer,
5253
toMutation,
5354
toName,
5455
toQueryTarget,
5556
toResourcePath,
5657
toRunAggregationQueryRequest
5758
} from './serializer';
58-
import { DatabaseId } from '../core/database_info';
59-
import { ResourcePath } from '../model/path';
6059

6160
/**
6261
* Datastore and its related methods are a wrapper around the external Google
@@ -248,15 +247,15 @@ export async function invokeRunQueryRpc(
248247
query: Query
249248
): Promise<Document[]> {
250249
const datastoreImpl = debugCast(datastore, DatastoreImpl);
251-
const { queryTarget: request, parent } = toQueryTarget(
250+
const { queryTarget, parent } = toQueryTarget(
252251
datastoreImpl.serializer,
253252
queryToTarget(query)
254253
);
255254
const response = await datastoreImpl.invokeStreamingRPC<
256255
ProtoRunQueryRequest,
257256
ProtoRunQueryResponse
258257
>('RunQuery', datastoreImpl.serializer.databaseId, parent, {
259-
structuredQuery: request.structuredQuery
258+
structuredQuery: queryTarget.structuredQuery
260259
});
261260
return (
262261
response

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

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ import {
3434
count,
3535
sum,
3636
average,
37-
addDoc,
38-
setLogLevel
37+
addDoc
3938
} from '../util/firebase_export';
4039
import {
4140
apiDescribe,
@@ -57,36 +56,23 @@ apiDescribe('Count queries', persistence => {
5756
});
5857
});
5958

60-
it('can run count query getCountFromServer with + in document name', () => {
61-
setLogLevel('debug');
62-
const testDocs = {
63-
'a+1': { author: 'authorA' },
64-
'b1': { author: 'authorB' },
65-
'c1': { author: 'authorC' }
66-
};
67-
return withTestCollection(persistence, testDocs, async coll => {
68-
const subColl1 = collection(coll, 'a+1/sub');
69-
await addDoc(subColl1, { foo: 'bar' });
70-
await addDoc(subColl1, { foo: 'baz' });
71-
72-
const subColl2 = collection(coll, 'b1/su+b');
73-
await addDoc(subColl2, { foo: 'bar' });
74-
await addDoc(subColl2, { foo: 'baz' });
75-
76-
const subColl3 = collection(coll, 'c1/sub');
77-
await addDoc(subColl3, { foo: 'bar' });
78-
await addDoc(subColl3, { foo: 'baz' });
79-
80-
const snapshot1 = await getCountFromServer(subColl1);
81-
expect(snapshot1.data().count).to.equal(2);
82-
83-
const snapshot2 = await getCountFromServer(subColl2);
84-
expect(snapshot2.data().count).to.equal(2);
85-
86-
const snapshot3 = await getCountFromServer(subColl3);
87-
expect(snapshot3.data().count).to.equal(2);
88-
});
89-
});
59+
['so!@#$%^&*()_+special/sub', 'b1/so!@#$%^&*()_+special'].forEach(
60+
documentPath => {
61+
it(
62+
'can run count query getCountFromServer with special chars in the document path: ' +
63+
documentPath,
64+
() => {
65+
return withTestCollection(persistence, {}, async coll => {
66+
const subColl1 = collection(coll, documentPath);
67+
await addDoc(subColl1, { foo: 'bar' });
68+
await addDoc(subColl1, { foo: 'baz' });
69+
const snapshot1 = await getCountFromServer(subColl1);
70+
expect(snapshot1.data().count).to.equal(2);
71+
});
72+
}
73+
);
74+
}
75+
);
9076

9177
it("count query doesn't use converter", () => {
9278
const testDocs = {

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,6 @@ describe('Query', () => {
11291129
it('supports query over collection path with special characters', () => {
11301130
return withTestCollection(async collRef => {
11311131
const docWithSpecials = doc(collRef, 'so!@#$%^&*()_+special');
1132-
await setDoc(docWithSpecials, {});
11331132

11341133
const collectionWithSpecials = collection(
11351134
docWithSpecials,
@@ -1142,7 +1141,6 @@ describe('Query', () => {
11421141
query(collectionWithSpecials, orderBy('foo', 'asc'))
11431142
);
11441143

1145-
expect(result.size).to.equal(2);
11461144
verifyResults(result, { foo: 1 }, { foo: 2 });
11471145
});
11481146
});
@@ -2159,34 +2157,23 @@ describe('Count queries', () => {
21592157
});
21602158
});
21612159

2162-
it('can run count query getCountFromServer with + in document name', () => {
2163-
return withTestCollection(async coll => {
2164-
await setDoc(doc(coll, 'a+1'), {});
2165-
await setDoc(doc(coll, 'b1'), {});
2166-
await setDoc(doc(coll, 'c1'), {});
2167-
2168-
const subColl1 = collection(coll, 'a+1/sub');
2169-
await addDoc(subColl1, { foo: 'bar' });
2170-
await addDoc(subColl1, { foo: 'baz' });
2171-
2172-
const subColl2 = collection(coll, 'b1/su+b');
2173-
await addDoc(subColl2, { foo: 'bar' });
2174-
await addDoc(subColl2, { foo: 'baz' });
2175-
2176-
const subColl3 = collection(coll, 'c1/sub');
2177-
await addDoc(subColl3, { foo: 'bar' });
2178-
await addDoc(subColl3, { foo: 'baz' });
2179-
2180-
const snapshot1 = await getCount(subColl1);
2181-
expect(snapshot1.data().count).to.equal(2);
2182-
2183-
const snapshot2 = await getCount(subColl2);
2184-
expect(snapshot2.data().count).to.equal(2);
2185-
2186-
const snapshot3 = await getCount(subColl3);
2187-
expect(snapshot3.data().count).to.equal(2);
2188-
});
2189-
});
2160+
['so!@#$%^&*()_+special/sub', 'b1/so!@#$%^&*()_+special'].forEach(
2161+
documentPath => {
2162+
it(
2163+
'can run count query getCount with special chars in the document path: ' +
2164+
documentPath,
2165+
() => {
2166+
return withTestCollection(async coll => {
2167+
const subColl1 = collection(coll, documentPath);
2168+
await addDoc(subColl1, { foo: 'bar' });
2169+
await addDoc(subColl1, { foo: 'baz' });
2170+
const snapshot1 = await getCount(subColl1);
2171+
expect(snapshot1.data().count).to.equal(2);
2172+
});
2173+
}
2174+
);
2175+
}
2176+
);
21902177

21912178
it('run count query on empty collection', () => {
21922179
return withTestCollection(async coll => {

0 commit comments

Comments
 (0)