Skip to content

Commit 433b283

Browse files
committed
Adding and fixing tests.
1 parent 838f825 commit 433b283

File tree

2 files changed

+119
-109
lines changed

2 files changed

+119
-109
lines changed

packages/firestore/test/integration/api/query.test.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ apiDescribe('Queries', (persistence: boolean) => {
15491549

15501550
// TODO(orquery): Enable this test when prod supports OR queries.
15511551
// eslint-disable-next-line no-restricted-properties
1552-
it.skip('supports multiple in ops', () => {
1552+
it('supports multiple in ops', () => {
15531553
const testDocs = {
15541554
doc1: { a: 1, b: 0 },
15551555
doc2: { b: 1 },
@@ -1663,9 +1663,7 @@ apiDescribe('Queries', (persistence: boolean) => {
16631663
'doc4',
16641664
'doc6'
16651665
);
1666-
});
16671666

1668-
return withTestCollection(persistence, testDocs, async coll => {
16691667
await checkOnlineAndOfflineResultsMatch(
16701668
query(
16711669
coll,
@@ -1676,31 +1674,26 @@ apiDescribe('Queries', (persistence: boolean) => {
16761674
),
16771675
'doc3'
16781676
);
1679-
});
16801677

1681-
return withTestCollection(persistence, testDocs, async coll => {
16821678
await checkOnlineAndOfflineResultsMatch(
16831679
query(
16841680
coll,
16851681
or(
1686-
where('a', 'in', [2, 3]),
1687-
where('c', '==', 10),
1682+
and(where('a', 'in', [2, 3]), where('c', '==', 10)),
16881683
where('b', 'array-contains-any', [0, 7])
16891684
)
16901685
),
16911686
'doc1',
16921687
'doc3',
16931688
'doc4'
16941689
);
1695-
});
16961690

1697-
return withTestCollection(persistence, testDocs, async coll => {
16981691
await checkOnlineAndOfflineResultsMatch(
16991692
query(
17001693
coll,
17011694
and(
17021695
where('a', 'in', [2, 3]),
1703-
or(where('b', 'array-contains-any', [0, 7]), where('c', '==', 10))
1696+
or(where('b', 'array-contains-any', [0, 7]), where('c', '==', 20))
17041697
)
17051698
),
17061699
'doc3',
@@ -1731,34 +1724,28 @@ apiDescribe('Queries', (persistence: boolean) => {
17311724
'doc4',
17321725
'doc6'
17331726
);
1734-
});
17351727

1736-
return withTestCollection(persistence, testDocs, async coll => {
17371728
await checkOnlineAndOfflineResultsMatch(
17381729
query(
17391730
coll,
17401731
and(where('a', 'in', [2, 3]), where('b', 'array-contains', 7))
17411732
),
17421733
'doc3'
17431734
);
1744-
});
17451735

1746-
return withTestCollection(persistence, testDocs, async coll => {
17471736
await checkOnlineAndOfflineResultsMatch(
17481737
query(
17491738
coll,
17501739
or(
17511740
where('a', 'in', [2, 3]),
1752-
and(where('b', 'array-contains', 3), where('b', '==', 1))
1741+
and(where('b', 'array-contains', 3), where('a', '==', 1))
17531742
)
17541743
),
17551744
'doc3',
17561745
'doc4',
17571746
'doc6'
17581747
);
1759-
});
17601748

1761-
return withTestCollection(persistence, testDocs, async coll => {
17621749
await checkOnlineAndOfflineResultsMatch(
17631750
query(
17641751
coll,
@@ -1791,6 +1778,12 @@ apiDescribe('Queries', (persistence: boolean) => {
17911778
'doc4',
17921779
'doc5'
17931780
);
1781+
1782+
await checkOnlineAndOfflineResultsMatch(
1783+
query(coll, where('a', 'in', [2, 3]), orderBy('a')),
1784+
'doc6',
1785+
'doc3'
1786+
);
17941787
});
17951788
});
17961789
});

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 109 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -961,106 +961,123 @@ apiDescribe('Validation:', (persistence: boolean) => {
961961
);
962962
});
963963

964-
validationIt(persistence, 'with multiple disjunctive filters fail', db => {
965-
expect(() =>
966-
query(
967-
collection(db, 'test'),
968-
where('foo', 'not-in', [1, 2]),
969-
where('foo', 'not-in', [2, 3])
970-
)
971-
).to.throw(
972-
"Invalid query. You cannot use more than one 'not-in' filter."
973-
);
964+
validationIt.only(
965+
persistence,
966+
'with multiple disjunctive filters fail',
967+
db => {
968+
expect(() =>
969+
query(
970+
collection(db, 'test'),
971+
where('foo', 'not-in', [1, 2]),
972+
where('foo', 'not-in', [2, 3])
973+
)
974+
).to.throw(
975+
"Invalid query. You cannot use more than one 'not-in' filter."
976+
);
974977

975-
expect(() =>
976-
query(
977-
collection(db, 'test'),
978-
where('foo', 'array-contains-any', [1, 2]),
979-
where('foo', 'array-contains-any', [2, 3])
980-
)
981-
).to.throw(
982-
"Invalid query. You cannot use more than one 'array-contains-any'" +
983-
' filter.'
984-
);
978+
expect(() =>
979+
query(
980+
collection(db, 'test'),
981+
where('foo', 'array-contains-any', [1, 2]),
982+
where('foo', 'array-contains-any', [2, 3])
983+
)
984+
).to.throw(
985+
"Invalid query. You cannot use more than one 'array-contains-any'" +
986+
' filter.'
987+
);
985988

986-
expect(() =>
987-
query(
988-
collection(db, 'test'),
989-
where('foo', 'not-in', [2, 3]),
990-
where('foo', 'array-contains-any', [2, 3])
991-
)
992-
).to.throw(
993-
"Invalid query. You cannot use 'array-contains-any' filters with " +
994-
"'not-in' filters."
995-
);
989+
expect(() =>
990+
query(
991+
collection(db, 'test'),
992+
where('foo', 'not-in', [2, 3]),
993+
where('foo', 'array-contains-any', [2, 3])
994+
)
995+
).to.throw(
996+
"Invalid query. You cannot use 'array-contains-any' filters with " +
997+
"'not-in' filters."
998+
);
996999

997-
expect(() =>
998-
query(
999-
collection(db, 'test'),
1000-
where('foo', 'array-contains-any', [2, 3]),
1001-
where('foo', 'not-in', [2, 3])
1002-
)
1003-
).to.throw(
1004-
"Invalid query. You cannot use 'not-in' filters with " +
1005-
"'array-contains-any' filters."
1006-
);
1000+
expect(() =>
1001+
query(
1002+
collection(db, 'test'),
1003+
where('foo', 'array-contains-any', [2, 3]),
1004+
where('foo', 'not-in', [2, 3])
1005+
)
1006+
).to.throw(
1007+
"Invalid query. You cannot use 'not-in' filters with " +
1008+
"'array-contains-any' filters."
1009+
);
10071010

1008-
expect(() =>
1009-
query(
1010-
collection(db, 'test'),
1011-
where('foo', 'not-in', [2, 3]),
1012-
where('foo', 'in', [2, 3])
1013-
)
1014-
).to.throw(
1015-
"Invalid query. You cannot use 'in' filters with 'not-in' filters."
1016-
);
1011+
expect(() =>
1012+
query(
1013+
collection(db, 'test'),
1014+
where('foo', 'not-in', [2, 3]),
1015+
where('foo', 'in', [2, 3])
1016+
)
1017+
).to.throw(
1018+
"Invalid query. You cannot use 'in' filters with 'not-in' filters."
1019+
);
10171020

1018-
expect(() =>
1019-
query(
1020-
collection(db, 'test'),
1021-
where('foo', 'in', [2, 3]),
1022-
where('foo', 'not-in', [2, 3])
1023-
)
1024-
).to.throw(
1025-
"Invalid query. You cannot use 'not-in' filters with 'in' filters."
1026-
);
1021+
expect(() =>
1022+
query(
1023+
collection(db, 'test'),
1024+
where('foo', 'in', [2, 3]),
1025+
where('foo', 'not-in', [2, 3])
1026+
)
1027+
).to.throw(
1028+
"Invalid query. You cannot use 'not-in' filters with 'in' filters."
1029+
);
10271030

1028-
expect(() =>
1029-
query(
1030-
collection(db, 'test'),
1031-
where('foo', 'array-contains', 1),
1032-
where('foo', 'in', [2, 3]),
1033-
where('foo', 'array-contains-any', [2])
1034-
)
1035-
).to.throw(
1036-
"Invalid query. You cannot use 'array-contains-any' filters with " +
1037-
"'array-contains' filters."
1038-
);
1031+
// This is redundant with the above tests, but makes sure our validation
1032+
// doesn't get confused.
1033+
expect(() =>
1034+
query(
1035+
collection(db, 'test'),
1036+
where('foo', 'in', [2, 3]),
1037+
where('foo', 'array-contains', 1),
1038+
where('foo', 'array-contains-any', [2])
1039+
)
1040+
).to.throw(
1041+
"Invalid query. You cannot use 'array-contains-any' filters with 'array-contains' filters."
1042+
);
10391043

1040-
expect(() =>
1041-
query(
1042-
collection(db, 'test'),
1043-
where('foo', 'not-in', [2, 3]),
1044-
where('foo', 'array-contains', 2),
1045-
where('foo', 'array-contains-any', [2])
1046-
)
1047-
).to.throw(
1048-
"Invalid query. You cannot use 'array-contains' filters with " +
1049-
"'not-in' filters."
1050-
);
1044+
expect(() =>
1045+
query(
1046+
collection(db, 'test'),
1047+
where('foo', 'array-contains', 1),
1048+
where('foo', 'in', [2, 3]),
1049+
where('foo', 'array-contains-any', [2])
1050+
)
1051+
).to.throw(
1052+
"Invalid query. You cannot use 'array-contains-any' filters with " +
1053+
"'array-contains' filters."
1054+
);
10511055

1052-
expect(() =>
1053-
query(
1054-
collection(db, 'test'),
1055-
where('foo', 'array-contains', 2),
1056-
where('foo', 'in', [2]),
1057-
where('foo', 'not-in', [2, 3])
1058-
)
1059-
).to.throw(
1060-
"Invalid query. You cannot use 'not-in' filters with " +
1061-
"'array-contains' filters."
1062-
);
1063-
});
1056+
expect(() =>
1057+
query(
1058+
collection(db, 'test'),
1059+
where('foo', 'not-in', [2, 3]),
1060+
where('foo', 'array-contains', 2),
1061+
where('foo', 'array-contains-any', [2])
1062+
)
1063+
).to.throw(
1064+
"Invalid query. You cannot use 'array-contains' filters with " +
1065+
"'not-in' filters."
1066+
);
1067+
1068+
expect(() =>
1069+
query(
1070+
collection(db, 'test'),
1071+
where('foo', 'array-contains', 2),
1072+
where('foo', 'in', [2]),
1073+
where('foo', 'not-in', [2, 3])
1074+
)
1075+
).to.throw(
1076+
"Invalid query. You cannot use 'not-in' filters with " +
1077+
"'array-contains' filters."
1078+
);
1079+
}
1080+
);
10641081

10651082
validationIt(
10661083
persistence,

0 commit comments

Comments
 (0)