Skip to content

Commit

Permalink
fix(firestore): support unlimited number of where conditions (#1314) -
Browse files Browse the repository at this point in the history
  • Loading branch information
dominics authored Jul 29, 2024
1 parent f699bb0 commit a44152b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/firebase-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ export function slashPathToFirestoreRef(
typeof ref.where === 'function'
) {
if (Array.isArray(options.where[0])) {
const [where1, where2] = options.where as WhereOptions[];
ref = applyWhere(
applyWhere(ref, where1, options.statics || firestoreStatics),
where2,
options.statics || firestoreStatics,
);
(options.where as WhereOptions[]).forEach((whereCondition) => {
ref = applyWhere(
ref,
whereCondition,
options.statics || firestoreStatics,
);
});
} else {
ref = applyWhere(
ref,
Expand Down
13 changes: 12 additions & 1 deletion test/unit/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,17 @@ describe('tasks', () => {
it('supports multi-where', async () => {
await projectFirestoreRef.set(testProject);
const secondProjectId = 'some';
const secondProject = { name: 'another', status: 'asdf' };
const secondProject = {
name: 'another',
status: 'asdf',
anotherProperty: 'ghjk',
};
await projectsFirestoreRef.doc(secondProjectId).set(secondProject);
await projectsFirestoreRef.doc('confounding').set({
name: 'another',
status: 'asdf',
anotherProperty: 'we-must-not-match-this',
});
const result = await tasks.callFirestore(
adminApp,
'get',
Expand All @@ -178,9 +187,11 @@ describe('tasks', () => {
where: [
['name', '==', secondProject.name],
['status', '==', secondProject.status],
['anotherProperty', '==', secondProject.anotherProperty],
],
},
);
expect(result).to.have.length(1);
expect(result[0]).to.have.property('id', secondProjectId);
expect(result[0]).to.have.property('name', secondProject.name);
expect(result[0]).to.have.property('status', secondProject.status);
Expand Down

0 comments on commit a44152b

Please sign in to comment.