Skip to content

Commit 5206828

Browse files
committed
clean up integration tests so they pass in classic and enterprise DBs
1 parent d3eed35 commit 5206828

File tree

9 files changed

+361
-312
lines changed

9 files changed

+361
-312
lines changed

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

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { expect } from 'chai';
1919

20+
import { it } from '../../util/mocha_extensions';
2021
import {
2122
collection,
2223
collectionGroup,
@@ -42,7 +43,6 @@ import {
4243
withTestCollection,
4344
withTestDb
4445
} from '../util/helpers';
45-
import { USE_EMULATOR } from '../util/settings';
4646

4747
apiDescribe('Count queries', persistence => {
4848
it('can run count query getCountFromServer', () => {
@@ -150,7 +150,7 @@ apiDescribe('Count queries', persistence => {
150150
// production, since the Firestore Emulator does not require index creation
151151
// and will, therefore, never fail in this situation.
152152
// eslint-disable-next-line no-restricted-properties
153-
(USE_EMULATOR ? it.skip : it)(
153+
it.skipEnterprise.skipEmulator(
154154
'getCountFromServer error message contains console link if missing index',
155155
() => {
156156
return withEmptyTestCollection(persistence, async coll => {
@@ -362,7 +362,7 @@ apiDescribe('Aggregation queries', persistence => {
362362
// production, since the Firestore Emulator does not require index creation
363363
// and will, therefore, never fail in this situation.
364364
// eslint-disable-next-line no-restricted-properties
365-
(USE_EMULATOR ? it.skip : it)(
365+
it.skipEmulator.skipEnterprise(
366366
'getAggregateFromServer error message contains console link good if missing index',
367367
() => {
368368
return withEmptyTestCollection(persistence, async coll => {
@@ -480,26 +480,29 @@ apiDescribe('Aggregation queries - sum / average', persistence => {
480480
});
481481
});
482482

483-
it('fails when exceeding the max (5) aggregations using getAggregationFromServer', () => {
484-
const testDocs = {
485-
a: { author: 'authorA', title: 'titleA', pages: 100 },
486-
b: { author: 'authorB', title: 'titleB', pages: 50 }
487-
};
488-
return withTestCollection(persistence, testDocs, async coll => {
489-
const promise = getAggregateFromServer(coll, {
490-
totalPages: sum('pages'),
491-
averagePages: average('pages'),
492-
count: count(),
493-
totalPagesX: sum('pages'),
494-
averagePagesY: average('pages'),
495-
countZ: count()
483+
it.skipEnterprise(
484+
'fails when exceeding the max (5) aggregations using getAggregationFromServer',
485+
() => {
486+
const testDocs = {
487+
a: { author: 'authorA', title: 'titleA', pages: 100 },
488+
b: { author: 'authorB', title: 'titleB', pages: 50 }
489+
};
490+
return withTestCollection(persistence, testDocs, async coll => {
491+
const promise = getAggregateFromServer(coll, {
492+
totalPages: sum('pages'),
493+
averagePages: average('pages'),
494+
count: count(),
495+
totalPagesX: sum('pages'),
496+
averagePagesY: average('pages'),
497+
countZ: count()
498+
});
499+
500+
await expect(promise).to.eventually.be.rejectedWith(
501+
/maximum number of aggregations/
502+
);
496503
});
497-
498-
await expect(promise).to.eventually.be.rejectedWith(
499-
/maximum number of aggregations/
500-
);
501-
});
502-
});
504+
}
505+
);
503506

504507
it('returns undefined when getting the result of an unrequested aggregation', () => {
505508
const testDocs = {
@@ -940,47 +943,50 @@ apiDescribe('Aggregation queries - sum / average', persistence => {
940943
});
941944
});
942945

943-
it('performs sum over a result set of zero documents using getAggregationFromServer', () => {
944-
const testDocs = {
945-
a: {
946-
author: 'authorA',
947-
title: 'titleA',
948-
pages: 100,
949-
year: 1980,
950-
rating: 5
951-
},
952-
b: {
953-
author: 'authorB',
954-
title: 'titleB',
955-
pages: 50,
956-
year: 2020,
957-
rating: 4
958-
},
959-
c: {
960-
author: 'authorC',
961-
title: 'titleC',
962-
pages: 100,
963-
year: 1980,
964-
rating: 3
965-
},
966-
d: {
967-
author: 'authorD',
968-
title: 'titleD',
969-
pages: 50,
970-
year: 2020,
971-
rating: 0
972-
}
973-
};
974-
return withTestCollection(persistence, testDocs, async coll => {
975-
const snapshot = await getAggregateFromServer(
976-
query(coll, where('pages', '>', 200)),
977-
{
978-
totalPages: sum('pages')
946+
it.skipEnterprise(
947+
'performs sum over a result set of zero documents using getAggregationFromServer',
948+
() => {
949+
const testDocs = {
950+
a: {
951+
author: 'authorA',
952+
title: 'titleA',
953+
pages: 100,
954+
year: 1980,
955+
rating: 5
956+
},
957+
b: {
958+
author: 'authorB',
959+
title: 'titleB',
960+
pages: 50,
961+
year: 2020,
962+
rating: 4
963+
},
964+
c: {
965+
author: 'authorC',
966+
title: 'titleC',
967+
pages: 100,
968+
year: 1980,
969+
rating: 3
970+
},
971+
d: {
972+
author: 'authorD',
973+
title: 'titleD',
974+
pages: 50,
975+
year: 2020,
976+
rating: 0
979977
}
980-
);
981-
expect(snapshot.data().totalPages).to.equal(0);
982-
});
983-
});
978+
};
979+
return withTestCollection(persistence, testDocs, async coll => {
980+
const snapshot = await getAggregateFromServer(
981+
query(coll, where('pages', '>', 200)),
982+
{
983+
totalPages: sum('pages')
984+
}
985+
);
986+
expect(snapshot.data().totalPages).to.equal(0);
987+
});
988+
}
989+
);
984990

985991
it('performs sum only on numeric fields using getAggregationFromServer', () => {
986992
const testDocs = {

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

Lines changed: 101 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { expect } from 'chai';
1919

20+
import { it } from '../../util/mocha_extensions';
2021
import { CompositeIndexTestHelper } from '../util/composite_index_test_helper';
2122
import {
2223
where,
@@ -196,27 +197,33 @@ apiDescribe('Composite Index Queries', persistence => {
196197
});
197198
});
198199

199-
it('performs aggregations on documents with all aggregated fields using getAggregationFromServer', () => {
200-
const testDocs = {
201-
a: { author: 'authorA', title: 'titleA', pages: 100, year: 1980 },
202-
b: { author: 'authorB', title: 'titleB', pages: 50, year: 2020 },
203-
c: { author: 'authorC', title: 'titleC', pages: 150, year: 2021 },
204-
d: { author: 'authorD', title: 'titleD', pages: 50 }
205-
};
206-
const testHelper = new CompositeIndexTestHelper();
207-
return testHelper.withTestDocs(persistence, testDocs, async coll => {
208-
const snapshot = await getAggregateFromServer(testHelper.query(coll), {
209-
totalPages: sum('pages'),
210-
averagePages: average('pages'),
211-
averageYear: average('year'),
212-
count: count()
200+
it.skipEmulator.skipEnterprise(
201+
'performs aggregations on documents with all aggregated fields using getAggregationFromServer',
202+
() => {
203+
const testDocs = {
204+
a: { author: 'authorA', title: 'titleA', pages: 100, year: 1980 },
205+
b: { author: 'authorB', title: 'titleB', pages: 50, year: 2020 },
206+
c: { author: 'authorC', title: 'titleC', pages: 150, year: 2021 },
207+
d: { author: 'authorD', title: 'titleD', pages: 50 }
208+
};
209+
const testHelper = new CompositeIndexTestHelper();
210+
return testHelper.withTestDocs(persistence, testDocs, async coll => {
211+
const snapshot = await getAggregateFromServer(
212+
testHelper.query(coll),
213+
{
214+
totalPages: sum('pages'),
215+
averagePages: average('pages'),
216+
averageYear: average('year'),
217+
count: count()
218+
}
219+
);
220+
expect(snapshot.data().totalPages).to.equal(300);
221+
expect(snapshot.data().averagePages).to.equal(100);
222+
expect(snapshot.data().averageYear).to.equal(2007);
223+
expect(snapshot.data().count).to.equal(3);
213224
});
214-
expect(snapshot.data().totalPages).to.equal(300);
215-
expect(snapshot.data().averagePages).to.equal(100);
216-
expect(snapshot.data().averageYear).to.equal(2007);
217-
expect(snapshot.data().count).to.equal(3);
218-
});
219-
});
225+
}
226+
);
220227

221228
it('performs aggregates on multiple fields where one aggregate could cause short-circuit due to NaN using getAggregationFromServer', () => {
222229
const testDocs = {
@@ -262,56 +269,62 @@ apiDescribe('Composite Index Queries', persistence => {
262269
});
263270
});
264271

265-
it('performs aggregates when using `array-contains-any` operator getAggregationFromServer', () => {
266-
const testDocs = {
267-
a: {
268-
author: 'authorA',
269-
title: 'titleA',
270-
pages: 100,
271-
year: 1980,
272-
rating: [5, 1000]
273-
},
274-
b: {
275-
author: 'authorB',
276-
title: 'titleB',
277-
pages: 50,
278-
year: 2020,
279-
rating: [4]
280-
},
281-
c: {
282-
author: 'authorC',
283-
title: 'titleC',
284-
pages: 100,
285-
year: 1980,
286-
rating: [2222, 3]
287-
},
288-
d: {
289-
author: 'authorD',
290-
title: 'titleD',
291-
pages: 50,
292-
year: 2020,
293-
rating: [0]
294-
}
295-
};
296-
const testHelper = new CompositeIndexTestHelper();
297-
return testHelper.withTestDocs(persistence, testDocs, async coll => {
298-
const snapshot = await getAggregateFromServer(
299-
testHelper.query(coll, where('rating', 'array-contains-any', [5, 3])),
300-
{
301-
totalRating: sum('rating'),
302-
averageRating: average('rating'),
303-
totalPages: sum('pages'),
304-
averagePages: average('pages'),
305-
countOfDocs: count()
272+
it.skipEnterprise(
273+
'performs aggregates when using `array-contains-any` operator getAggregationFromServer',
274+
() => {
275+
const testDocs = {
276+
a: {
277+
author: 'authorA',
278+
title: 'titleA',
279+
pages: 100,
280+
year: 1980,
281+
rating: [5, 1000]
282+
},
283+
b: {
284+
author: 'authorB',
285+
title: 'titleB',
286+
pages: 50,
287+
year: 2020,
288+
rating: [4]
289+
},
290+
c: {
291+
author: 'authorC',
292+
title: 'titleC',
293+
pages: 100,
294+
year: 1980,
295+
rating: [2222, 3]
296+
},
297+
d: {
298+
author: 'authorD',
299+
title: 'titleD',
300+
pages: 50,
301+
year: 2020,
302+
rating: [0]
306303
}
307-
);
308-
expect(snapshot.data().totalRating).to.equal(0);
309-
expect(snapshot.data().averageRating).to.be.null;
310-
expect(snapshot.data().totalPages).to.equal(200);
311-
expect(snapshot.data().averagePages).to.equal(100);
312-
expect(snapshot.data().countOfDocs).to.equal(2);
313-
});
314-
});
304+
};
305+
const testHelper = new CompositeIndexTestHelper();
306+
return testHelper.withTestDocs(persistence, testDocs, async coll => {
307+
const snapshot = await getAggregateFromServer(
308+
testHelper.query(
309+
coll,
310+
where('rating', 'array-contains-any', [5, 3])
311+
),
312+
{
313+
totalRating: sum('rating'),
314+
averageRating: average('rating'),
315+
totalPages: sum('pages'),
316+
averagePages: average('pages'),
317+
countOfDocs: count()
318+
}
319+
);
320+
expect(snapshot.data().totalRating).to.equal(0);
321+
expect(snapshot.data().averageRating).to.be.null;
322+
expect(snapshot.data().totalPages).to.equal(200);
323+
expect(snapshot.data().averagePages).to.equal(100);
324+
expect(snapshot.data().countOfDocs).to.equal(2);
325+
});
326+
}
327+
);
315328
});
316329

317330
describe('Multiple Inequality', () => {
@@ -950,18 +963,24 @@ apiDescribe('Composite Index Queries', persistence => {
950963
});
951964
});
952965

953-
it('inequality query will reject if document key appears only in equality filter', () => {
954-
const testHelper = new CompositeIndexTestHelper();
955-
return testHelper.withTestCollection(persistence, async coll => {
956-
const query_ = testHelper.query(
957-
coll,
958-
where('key', '!=', 42),
959-
where(documentId(), '==', 'doc1')
960-
);
961-
await expect(testHelper.getDocs(query_)).to.be.eventually.rejectedWith(
962-
'Equality on key is not allowed if there are other inequality fields and key does not appear in inequalities.'
963-
);
964-
});
965-
});
966+
//
967+
it.skipEnterprise(
968+
'inequality query will reject if document key appears only in equality filter',
969+
() => {
970+
const testHelper = new CompositeIndexTestHelper();
971+
return testHelper.withTestCollection(persistence, async coll => {
972+
const query_ = testHelper.query(
973+
coll,
974+
where('key', '!=', 42),
975+
where(documentId(), '==', 'doc1')
976+
);
977+
await expect(
978+
testHelper.getDocs(query_)
979+
).to.be.eventually.rejectedWith(
980+
'Equality on key is not allowed if there are other inequality fields and key does not appear in inequalities.'
981+
);
982+
});
983+
}
984+
);
966985
});
967986
});

0 commit comments

Comments
 (0)