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

fix(firestore): Allow queries with combined in and array-contains-any #7142

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
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: 0 additions & 50 deletions packages/firestore/e2e/Query/where.and.filter.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,56 +213,6 @@ describe(' firestore().collection().where(AND Filters)', function () {
}
});

it('throws if query has array-contains-any & in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(
Filter.and(Filter('foo.bar', 'array-contains-any', [1]), Filter('foo.bar', 'in', [2])),
);

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'in' filters with 'array-contains-any' filters",
);
return Promise.resolve();
}
});

it('throws if query has multiple in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'in', [2])));

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("You cannot use more than one 'in' filter");
return Promise.resolve();
}
});

it('throws if query has in & array-contains-any filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(
Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'array-contains-any', [2])),
);

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'array-contains-any' filters with 'in' filters",
);
return Promise.resolve();
}
});

it("should throw error when using 'not-in' operator twice", async function () {
const ref = firebase.firestore().collection(COLLECTION);

Expand Down
46 changes: 0 additions & 46 deletions packages/firestore/e2e/Query/where.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,52 +159,6 @@ describe('firestore().collection().where()', function () {
}
});

it('throws if query has array-contains-any & in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where('foo.bar', 'array-contains-any', [1])
.where('foo.bar', 'in', [2]);
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'in' filters with 'array-contains-any' filters",
);
return Promise.resolve();
}
});

it('throws if query has multiple in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where('foo.bar', 'in', [1])
.where('foo.bar', 'in', [2]);
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("You cannot use more than one 'in' filter");
return Promise.resolve();
}
});

it('throws if query has in & array-contains-any filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where('foo.bar', 'in', [1])
.where('foo.bar', 'array-contains-any', [2]);
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'array-contains-any' filters with 'in' filters",
);
return Promise.resolve();
}
});

/* Queries */

it('returns with where equal filter', async function () {
Expand Down
49 changes: 0 additions & 49 deletions packages/firestore/e2e/Query/where.filter.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,55 +171,6 @@ describe('firestore().collection().where(Filters)', function () {
}
});

it('throws if query has array-contains-any & in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(Filter('foo.bar', 'array-contains-any', [1]))
.where(Filter('foo.bar', 'in', [2]));

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'in' filters with 'array-contains-any' filters",
);
return Promise.resolve();
}
});

it('throws if query has multiple in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(Filter('foo.bar', 'in', [1]))
.where(Filter('foo.bar', 'in', [2]));

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("You cannot use more than one 'in' filter");
return Promise.resolve();
}
});

it('throws if query has in & array-contains-any filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(Filter('foo.bar', 'in', [1]))
.where(Filter('foo.bar', 'array-contains-any', [2]));

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'array-contains-any' filters with 'in' filters",
);
return Promise.resolve();
}
});

it("should throw error when using 'not-in' operator twice", async function () {
const ref = firebase.firestore().collection(COLLECTION);

Expand Down
61 changes: 0 additions & 61 deletions packages/firestore/e2e/Query/where.or.filter.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,67 +318,6 @@ describe('firestore().collection().where(OR Filters)', function () {
}
});

it('throws if query has array-contains-any & in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(
Filter.or(
Filter.and(Filter('foo.bar', 'array-contains-any', [1]), Filter('foo.bar', 'in', [2])),
Filter.and(Filter('foo.bar', 'array-contains-any', [1]), Filter('foo.bar', 'in', [2])),
),
);

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'in' filters with 'array-contains-any' filters",
);
return Promise.resolve();
}
});

it('throws if query has multiple in filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(
Filter.or(
Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'in', [2])),
Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'in', [2])),
),
);

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("You cannot use more than one 'in' filter");
return Promise.resolve();
}
});

it('throws if query has in & array-contains-any filter', function () {
try {
firebase
.firestore()
.collection(COLLECTION)
.where(
Filter.or(
Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'array-contains-any', [2])),
Filter.and(Filter('foo.bar', 'in', [1]), Filter('foo.bar', 'array-contains-any', [2])),
),
);

return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
"You cannot use 'array-contains-any' filters with 'in' filters",
);
return Promise.resolve();
}
});

it("should throw error when using 'not-in' operator twice", async function () {
const ref = firebase.firestore().collection(COLLECTION);

Expand Down
16 changes: 0 additions & 16 deletions packages/firestore/lib/FirestoreQueryModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,6 @@ export default class FirestoreQueryModifiers {
);
}

if (this.hasIn) {
throw new Error(
"Invalid query. You cannot use 'array-contains-any' filters with 'in' filters.",
);
}

if (this.hasNotIn) {
throw new Error(
"Invalid query. You cannot use 'array-contains-any' filters with 'not-in' filters.",
Expand All @@ -313,16 +307,6 @@ export default class FirestoreQueryModifiers {
}

if (filter.operator === OPERATORS.in) {
if (this.hasIn) {
throw new Error("Invalid query. You cannot use more than one 'in' filter.");
}

if (this.hasArrayContainsAny) {
throw new Error(
"Invalid query. You cannot use 'in' filters with 'array-contains-any' filters.",
);
}

if (this.hasNotIn) {
throw new Error("Invalid query. You cannot use 'in' filters with 'not-in' filters.");
}
Expand Down