Skip to content

Commit c827ca1

Browse files
committed
update tests
1 parent a69e458 commit c827ca1

File tree

3 files changed

+89
-140
lines changed

3 files changed

+89
-140
lines changed

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

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,146 +1175,11 @@ apiDescribe('Validation:', persistence => {
11751175
}
11761176
);
11771177

1178-
// Multiple Inequality validation tests
1179-
validationIt(persistence, 'can have multiple inequality fields', db => {
1180-
const coll = collection(db, 'test');
1181-
expect(() =>
1182-
query(coll, where('x', '>=', 32), where('y', '<', 42))
1183-
).not.to.throw();
1184-
});
1185-
1186-
validationIt(
1187-
persistence,
1188-
'can have != and inequality queries on different fields',
1189-
db => {
1190-
const coll = collection(db, 'test');
1191-
expect(() =>
1192-
query(coll, where('x', '>', 32), where('y', '!=', 42))
1193-
).not.to.throw();
1194-
}
1195-
);
1196-
11971178
validationIt(
11981179
persistence,
1199-
'can have not-in and inequality queries on different fields',
1180+
'conflicting operators inside a nested composite filter',
12001181
db => {
12011182
const coll = collection(db, 'test');
1202-
expect(() =>
1203-
query(coll, where('y', '>=', 32), where('x', 'not-in', [42]))
1204-
).not.to.throw();
1205-
}
1206-
);
1207-
1208-
validationIt(
1209-
persistence,
1210-
'can have inequality different than orderBy',
1211-
db => {
1212-
const coll = collection(db, 'test');
1213-
// single inequality
1214-
expect(() =>
1215-
query(coll, where('x', '>', 32), orderBy('y'))
1216-
).not.to.throw();
1217-
expect(() =>
1218-
query(coll, orderBy('y'), where('x', '>', 32))
1219-
).not.to.throw();
1220-
expect(() =>
1221-
query(coll, where('x', '>', 32), orderBy('y'), orderBy('x'))
1222-
).not.to.throw();
1223-
expect(() =>
1224-
query(coll, orderBy('y'), orderBy('x'), where('x', '>', 32))
1225-
).not.to.throw();
1226-
expect(() =>
1227-
query(coll, where('x', '!=', 32), orderBy('y'))
1228-
).not.to.throw();
1229-
1230-
// multiple inequality
1231-
expect(() =>
1232-
query(coll, where('x', '>', 32), where('y', '!=', 42), orderBy('z'))
1233-
).not.to.throw();
1234-
expect(() =>
1235-
query(coll, orderBy('y'), where('x', '>', 32), where('y', '<=', 42))
1236-
).not.to.throw();
1237-
expect(() =>
1238-
query(
1239-
coll,
1240-
where('x', '>', 32),
1241-
where('y', '!=', 42),
1242-
orderBy('y'),
1243-
orderBy('x')
1244-
)
1245-
).not.to.throw();
1246-
expect(() =>
1247-
query(
1248-
coll,
1249-
orderBy('y'),
1250-
orderBy('z'),
1251-
where('x', '>', 32),
1252-
where('y', '!=', 42)
1253-
)
1254-
).not.to.throw();
1255-
}
1256-
);
1257-
1258-
validationIt(
1259-
persistence,
1260-
'multiple inequalities inside a nested composite filter',
1261-
db => {
1262-
// Multiple inequality on different fields inside a nested composite filter.
1263-
const coll = collection(db, 'test');
1264-
expect(() =>
1265-
query(
1266-
coll,
1267-
or(
1268-
and(where('a', '==', 'b'), where('c', '>', 'd')),
1269-
and(where('e', '<=', 'f'), where('g', '==', 'h'))
1270-
)
1271-
)
1272-
).not.to.throw();
1273-
1274-
// Multiple inequality on different fields between a field filter and a composite filter.
1275-
expect(() =>
1276-
query(
1277-
coll,
1278-
and(
1279-
or(
1280-
and(where('a', '==', 'b'), where('c', '>=', 'd')),
1281-
and(where('e', '==', 'f'), where('g', '!=', 'h'))
1282-
),
1283-
where('r', '<', 's')
1284-
)
1285-
)
1286-
).not.to.throw();
1287-
1288-
// OrderBy and multiple inequality on different fields.
1289-
expect(() =>
1290-
query(
1291-
coll,
1292-
or(
1293-
and(where('a', '==', 'b'), where('c', '>', 'd')),
1294-
and(where('e', '==', 'f'), where('g', '!=', 'h'))
1295-
),
1296-
orderBy('r'),
1297-
orderBy('a')
1298-
)
1299-
).not.to.throw();
1300-
1301-
// Multiple inequality inside two composite filters.
1302-
expect(() =>
1303-
query(
1304-
coll,
1305-
and(
1306-
or(
1307-
and(where('a', '==', 'b'), where('c', '>=', 'd')),
1308-
and(where('e', '==', 'f'), where('g', '!=', 'h'))
1309-
),
1310-
or(
1311-
and(where('i', '==', 'j'), where('k', '>', 'l')),
1312-
and(where('m', '==', 'n'), where('o', '<', 'p'))
1313-
)
1314-
)
1315-
)
1316-
).not.to.throw();
1317-
13181183
// Composite queries can validate conflicting operators.
13191184
expect(() =>
13201185
query(

packages/firestore/test/unit/core/query.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
doc,
5151
expectCorrectComparisons,
5252
expectEqualitySets,
53+
fieldPath,
5354
filter,
5455
orderBy,
5556
orFilter,
@@ -777,6 +778,82 @@ describe('Query', () => {
777778
);
778779
});
779780

781+
it("generates the correct implicit order by's for multiple inequality", () => {
782+
assertImplicitOrderBy(
783+
query(
784+
'foo',
785+
filter('a', '<', 5),
786+
filter('aa', '>', 5),
787+
filter('b', '>', 5),
788+
filter('A', '>', 5)
789+
),
790+
orderBy('A'),
791+
orderBy('a'),
792+
orderBy('aa'),
793+
orderBy('b'),
794+
orderBy(DOCUMENT_KEY_NAME)
795+
);
796+
797+
// numbers
798+
assertImplicitOrderBy(
799+
query(
800+
'foo',
801+
filter('a', '<', 5),
802+
filter('1', '>', 5),
803+
filter('19', '>', 5),
804+
filter('2', '>', 5)
805+
),
806+
orderBy('1'),
807+
orderBy('19'),
808+
orderBy('2'),
809+
orderBy('a'),
810+
811+
orderBy(DOCUMENT_KEY_NAME)
812+
);
813+
814+
// nested fields
815+
assertImplicitOrderBy(
816+
query(
817+
'foo',
818+
filter('a', '<', 5),
819+
filter('aa', '>', 5),
820+
filter('a.a', '>', 5)
821+
),
822+
orderBy('a'),
823+
orderBy('a.a'),
824+
orderBy('aa'),
825+
orderBy(DOCUMENT_KEY_NAME)
826+
);
827+
828+
// special characters
829+
assertImplicitOrderBy(
830+
query(
831+
'foo',
832+
filter('a', '<', 5),
833+
filter('_a', '>', 5),
834+
filter('a.a', '>', 5)
835+
),
836+
orderBy('_a'),
837+
orderBy('a'),
838+
orderBy('a.a'),
839+
orderBy(DOCUMENT_KEY_NAME)
840+
);
841+
842+
// field name with dot
843+
assertImplicitOrderBy(
844+
query(
845+
'foo',
846+
filter('a', '<', 5),
847+
filter('a.a', '>', 5),
848+
filter(fieldPath('a.a'), '>', 5)
849+
),
850+
orderBy('a'),
851+
orderBy('a.a'), // nested field
852+
orderBy(fieldPath('a.a')), // field name with dot
853+
orderBy(DOCUMENT_KEY_NAME)
854+
);
855+
});
856+
780857
it('matchesAllDocuments() considers filters, orders and bounds', () => {
781858
const baseQuery = newQueryForPath(ResourcePath.fromString('collection'));
782859
expect(queryMatchesAllDocuments(baseQuery)).to.be.true;

packages/firestore/test/util/helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ export function path(path: string, offset?: number): ResourcePath {
226226
return new ResourcePath(splitPath(path, '/'), offset);
227227
}
228228

229-
export function field(path: string): FieldPath {
230-
return new FieldPath(path.split('.'));
229+
export function field(path: string | FieldPath): FieldPath {
230+
return path instanceof FieldPath ? path : new FieldPath(path.split('.'));
231231
}
232232

233+
export function fieldPath(path: string): FieldPath {
234+
return new FieldPath([path]);
235+
}
233236
export function fieldIndex(
234237
collectionGroup: string,
235238
options: {
@@ -261,7 +264,11 @@ export function blob(...bytes: number[]): Bytes {
261264
return Bytes.fromUint8Array(new Uint8Array(bytes || []));
262265
}
263266

264-
export function filter(path: string, op: string, value: unknown): FieldFilter {
267+
export function filter(
268+
path: string | FieldPath,
269+
op: string,
270+
value: unknown
271+
): FieldFilter {
265272
const dataValue = wrap(value);
266273
const operator = op as Operator;
267274
return FieldFilter.create(field(path), operator, dataValue);
@@ -736,7 +743,7 @@ export function resumeTokenForSnapshot(
736743
}
737744
}
738745

739-
export function orderBy(path: string, op?: string): OrderBy {
746+
export function orderBy(path: string | FieldPath, op?: string): OrderBy {
740747
op = op || 'asc';
741748
debugAssert(op === 'asc' || op === 'desc', 'Unknown direction: ' + op);
742749
const dir: Direction =

0 commit comments

Comments
 (0)