Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore: Add test that verifies aggregate query error message when missing index #1960

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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