Skip to content

Commit 34ad43c

Browse files
authored
Enable COUNT integration tests, now that backend support has rolled out (#6649)
1 parent 5aa48d0 commit 34ad43c

File tree

2 files changed

+74
-81
lines changed

2 files changed

+74
-81
lines changed

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

+71-75
Original file line numberDiff line numberDiff line change
@@ -37,90 +37,86 @@ import {
3737
withTestCollection,
3838
withTestDb
3939
} from '../util/helpers';
40-
import { USE_EMULATOR } from '../util/settings';
4140

42-
(USE_EMULATOR ? apiDescribe : apiDescribe.skip)(
43-
'Count quries',
44-
(persistence: boolean) => {
45-
it('can run count query getCountFromServer', () => {
46-
const testDocs = {
47-
a: { author: 'authorA', title: 'titleA' },
48-
b: { author: 'authorB', title: 'titleB' }
49-
};
50-
return withTestCollection(persistence, testDocs, async coll => {
51-
const snapshot = await getCountFromServer(coll);
52-
expect(snapshot.data().count).to.equal(2);
53-
});
41+
apiDescribe('Count quries', (persistence: boolean) => {
42+
it('can run count query getCountFromServer', () => {
43+
const testDocs = {
44+
a: { author: 'authorA', title: 'titleA' },
45+
b: { author: 'authorB', title: 'titleB' }
46+
};
47+
return withTestCollection(persistence, testDocs, async coll => {
48+
const snapshot = await getCountFromServer(coll);
49+
expect(snapshot.data().count).to.equal(2);
5450
});
51+
});
5552

56-
it("count query doesn't use converter", () => {
57-
const testDocs = {
58-
a: { author: 'authorA', title: 'titleA' },
59-
b: { author: 'authorB', title: 'titleB' }
60-
};
61-
const throwingConverter = {
62-
toFirestore(obj: never): DocumentData {
63-
throw new Error('should never be called');
64-
},
65-
fromFirestore(snapshot: QueryDocumentSnapshot): never {
66-
throw new Error('should never be called');
67-
}
68-
};
69-
return withTestCollection(persistence, testDocs, async coll => {
70-
const query_ = query(
71-
coll,
72-
where('author', '==', 'authorA')
73-
).withConverter(throwingConverter);
74-
const snapshot = await getCountFromServer(query_);
75-
expect(snapshot.data().count).to.equal(1);
76-
});
53+
it("count query doesn't use converter", () => {
54+
const testDocs = {
55+
a: { author: 'authorA', title: 'titleA' },
56+
b: { author: 'authorB', title: 'titleB' }
57+
};
58+
const throwingConverter = {
59+
toFirestore(obj: never): DocumentData {
60+
throw new Error('should never be called');
61+
},
62+
fromFirestore(snapshot: QueryDocumentSnapshot): never {
63+
throw new Error('should never be called');
64+
}
65+
};
66+
return withTestCollection(persistence, testDocs, async coll => {
67+
const query_ = query(
68+
coll,
69+
where('author', '==', 'authorA')
70+
).withConverter(throwingConverter);
71+
const snapshot = await getCountFromServer(query_);
72+
expect(snapshot.data().count).to.equal(1);
7773
});
74+
});
7875

79-
it('count query supports collection groups', () => {
80-
return withTestDb(persistence, async db => {
81-
const collectionGroupId = doc(collection(db, 'aggregateQueryTest')).id;
82-
const docPaths = [
83-
`${collectionGroupId}/cg-doc1`,
84-
`abc/123/${collectionGroupId}/cg-doc2`,
85-
`zzz${collectionGroupId}/cg-doc3`,
86-
`abc/123/zzz${collectionGroupId}/cg-doc4`,
87-
`abc/123/zzz/${collectionGroupId}`
88-
];
89-
const batch = writeBatch(db);
90-
for (const docPath of docPaths) {
91-
batch.set(doc(db, docPath), { x: 1 });
92-
}
93-
await batch.commit();
94-
const snapshot = await getCountFromServer(
95-
collectionGroup(db, collectionGroupId)
96-
);
97-
expect(snapshot.data().count).to.equal(2);
98-
});
76+
it('count query supports collection groups', () => {
77+
return withTestDb(persistence, async db => {
78+
const collectionGroupId = doc(collection(db, 'aggregateQueryTest')).id;
79+
const docPaths = [
80+
`${collectionGroupId}/cg-doc1`,
81+
`abc/123/${collectionGroupId}/cg-doc2`,
82+
`zzz${collectionGroupId}/cg-doc3`,
83+
`abc/123/zzz${collectionGroupId}/cg-doc4`,
84+
`abc/123/zzz/${collectionGroupId}`
85+
];
86+
const batch = writeBatch(db);
87+
for (const docPath of docPaths) {
88+
batch.set(doc(db, docPath), { x: 1 });
89+
}
90+
await batch.commit();
91+
const snapshot = await getCountFromServer(
92+
collectionGroup(db, collectionGroupId)
93+
);
94+
expect(snapshot.data().count).to.equal(2);
9995
});
96+
});
10097

101-
it('getCountFromServer fails if firestore is terminated', () => {
102-
return withEmptyTestCollection(persistence, async (coll, firestore) => {
103-
await terminate(firestore);
104-
expect(() => getCountFromServer(coll)).to.throw(
105-
'The client has already been terminated.'
106-
);
107-
});
98+
it('getCountFromServer fails if firestore is terminated', () => {
99+
return withEmptyTestCollection(persistence, async (coll, firestore) => {
100+
await terminate(firestore);
101+
expect(() => getCountFromServer(coll)).to.throw(
102+
'The client has already been terminated.'
103+
);
108104
});
105+
});
109106

110-
it("terminate doesn't crash when there is count query in flight", () => {
111-
return withEmptyTestCollection(persistence, async (coll, firestore) => {
112-
void getCountFromServer(coll);
113-
await terminate(firestore);
114-
});
107+
it("terminate doesn't crash when there is count query in flight", () => {
108+
return withEmptyTestCollection(persistence, async (coll, firestore) => {
109+
void getCountFromServer(coll);
110+
await terminate(firestore);
115111
});
112+
});
116113

117-
it('getCountFromServer fails if user is offline', () => {
118-
return withEmptyTestCollection(persistence, async (coll, firestore) => {
119-
await disableNetwork(firestore);
120-
await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith(
121-
'Failed to get count result because the client is offline'
122-
);
123-
});
114+
it('getCountFromServer fails if user is offline', () => {
115+
return withEmptyTestCollection(persistence, async (coll, firestore) => {
116+
await disableNetwork(firestore);
117+
await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith(
118+
'Failed to get count result because the client is offline'
119+
);
124120
});
125-
}
126-
);
121+
});
122+
});

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ import { runTransaction } from '../../src/lite-api/transaction';
8383
import { writeBatch } from '../../src/lite-api/write_batch';
8484
import {
8585
DEFAULT_PROJECT_ID,
86-
DEFAULT_SETTINGS,
87-
USE_EMULATOR
86+
DEFAULT_SETTINGS
8887
} from '../integration/util/settings';
8988

9089
import {
@@ -2120,7 +2119,7 @@ describe('withConverter() support', () => {
21202119
});
21212120

21222121
// eslint-disable-next-line no-restricted-properties
2123-
(USE_EMULATOR ? describe : describe.skip)('Count quries', () => {
2122+
describe('Count quries', () => {
21242123
it('AggregateQuerySnapshot inherits the original query', () => {
21252124
return withTestCollection(async coll => {
21262125
const query_ = query(coll);
@@ -2151,9 +2150,7 @@ describe('withConverter() support', () => {
21512150
it('run count query fails on invalid collection reference', () => {
21522151
return withTestDb(async db => {
21532152
const queryForRejection = collection(db, '__badpath__');
2154-
await expect(getCount(queryForRejection)).to.eventually.be.rejectedWith(
2155-
'Request failed with error: Bad Request'
2156-
);
2153+
await expect(getCount(queryForRejection)).to.eventually.be.rejected;
21572154
});
21582155
});
21592156

0 commit comments

Comments
 (0)