Skip to content

Commit

Permalink
Firestore: Add test that verifies aggregate query error message when …
Browse files Browse the repository at this point in the history
…missing index (#1960)
  • Loading branch information
dconeybe authored Dec 15, 2023
1 parent 85f1008 commit 2e4e83d
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions dev/system-test/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,28 @@ describe('count queries', () => {
await runQueryAndExpectCount(count5, 1);
});
}

// Only verify the error message for missing indexes when running against
// production, since the Firestore Emulator does not require index creation
// and will, therefore, never fail in this situation.
// eslint-disable-next-line no-restricted-properties
(process.env.FIRESTORE_EMULATOR_HOST === undefined ? it : it.skip)(
'count query error message contains console link if missing index',
() => {
const query = randomCol.where('key1', '==', 42).where('key2', '<', 42);
const countQuery = query.count();
const databaseId = query.firestore._settings.databaseId ?? '(default)';
// TODO(b/316359394) Remove this check for the default databases once
// cl/582465034 is rolled out to production.
if (databaseId === '(default)') {
return expect(countQuery.get()).to.be.eventually.rejectedWith(
/index.*https:\/\/console\.firebase\.google\.com/
);
} else {
return expect(countQuery.get()).to.be.eventually.rejectedWith(/index/);
}
}
);
});

describe('count queries using aggregate api', () => {
Expand Down Expand Up @@ -3540,15 +3562,27 @@ describe('Aggregation queries', () => {
// production, since the Firestore Emulator does not require index creation
// and will, therefore, never fail in this situation.
// eslint-disable-next-line no-restricted-properties
(process.env.FIRESTORE_EMULATOR_HOST === undefined ? it.skip : it)(
'aggregate() error message is good if missing index',
async () => {
(process.env.FIRESTORE_EMULATOR_HOST === undefined ? it : it.skip)(
'aggregate query error message contains console link if missing index',
() => {
const query = col.where('key1', '==', 42).where('key2', '<', 42);
await expect(
query.aggregate({count: AggregateField.count()}).get()
).to.be.eventually.rejectedWith(
/index.*https:\/\/console\.firebase\.google\.com/
);
const aggregateQuery = query.aggregate({
count: AggregateField.count(),
sum: AggregateField.sum('pages'),
average: AggregateField.average('pages'),
});
const databaseId = query.firestore._settings.databaseId ?? '(default)';
// TODO(b/316359394) Remove this check for the default databases once
// cl/582465034 is rolled out to production.
if (databaseId === '(default)') {
return expect(aggregateQuery.get()).to.be.eventually.rejectedWith(
/index.*https:\/\/console\.firebase\.google\.com/
);
} else {
return expect(aggregateQuery.get()).to.be.eventually.rejectedWith(
/index/
);
}
}
);

Expand Down

0 comments on commit 2e4e83d

Please sign in to comment.