Skip to content

Commit

Permalink
fix(firestore): Allow queries with combined in and array-contains-any (
Browse files Browse the repository at this point in the history
  • Loading branch information
ibobo authored and exaby73 committed Jul 25, 2023
1 parent 4d36e2c commit a24d657
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 222 deletions.
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

0 comments on commit a24d657

Please sign in to comment.