Skip to content

Commit 6061fb9

Browse files
Update Lite tests with Query API v2
1 parent eb44f4a commit 6061fb9

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed

packages/firestore/lite/test/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export function withTestDocAndInitialData(
7070

7171
export function withTestCollectionAndInitialData(
7272
data: firestore.DocumentData[],
73-
fn: (collRef: firestore.CollectionReference) => void | Promise<void>
73+
fn: (
74+
collRef: firestore.CollectionReference<firestore.DocumentData>
75+
) => void | Promise<void>
7476
): Promise<void> {
7577
return withTestDb(async db => {
7678
const coll = collection(db, AutoId.newId());

packages/firestore/lite/test/integration.test.ts

+45-36
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ import {
6262
increment,
6363
serverTimestamp,
6464
arrayUnion,
65-
arrayRemove
65+
arrayRemove,
66+
orderBy,
67+
startAfter,
68+
query,
69+
limit,
70+
endAt,
71+
endBefore,
72+
startAt,
73+
limitToLast,
74+
where
6675
} from '..';
6776
import {
6877
DEFAULT_PROJECT_ID,
@@ -764,8 +773,8 @@ describe('Query', () => {
764773
return withTestCollectionAndInitialData(
765774
[{ foo: 1 }, { foo: 2 }],
766775
async collRef => {
767-
const query = collRef.where('foo', '==', 1);
768-
const result = await getQuery(query);
776+
const query1 = query(collRef, where('foo', '==', 1));
777+
const result = await getQuery(query1);
769778
verifyResults(result, { foo: 1 });
770779
}
771780
);
@@ -775,8 +784,8 @@ describe('Query', () => {
775784
return withTestCollectionAndInitialData(
776785
[{ foo: 1 }, { foo: 2 }],
777786
async collRef => {
778-
const query = collRef.where(new FieldPath('foo'), '==', 1);
779-
const result = await getQuery(query);
787+
const query1 = query(collRef, where(new FieldPath('foo'), '==', 1));
788+
const result = await getQuery(query1);
780789
verifyResults(result, { foo: 1 });
781790
}
782791
);
@@ -786,8 +795,8 @@ describe('Query', () => {
786795
return withTestCollectionAndInitialData(
787796
[{ foo: 1 }, { foo: 2 }],
788797
async collRef => {
789-
const query = collRef.orderBy('foo');
790-
const result = await getQuery(query);
798+
const query1 = query(collRef, orderBy('foo'));
799+
const result = await getQuery(query1);
791800
verifyResults(result, { foo: 1 }, { foo: 2 });
792801
}
793802
);
@@ -797,8 +806,8 @@ describe('Query', () => {
797806
return withTestCollectionAndInitialData(
798807
[{ foo: 1 }, { foo: 2 }],
799808
async collRef => {
800-
const query = collRef.orderBy('foo', 'asc');
801-
const result = await getQuery(query);
809+
const query1 = query(collRef, orderBy('foo', 'asc'));
810+
const result = await getQuery(query1);
802811
verifyResults(result, { foo: 1 }, { foo: 2 });
803812
}
804813
);
@@ -808,8 +817,8 @@ describe('Query', () => {
808817
return withTestCollectionAndInitialData(
809818
[{ foo: 1 }, { foo: 2 }],
810819
async collRef => {
811-
const query = collRef.orderBy('foo', 'desc');
812-
const result = await getQuery(query);
820+
const query1 = query(collRef, orderBy('foo', 'desc'));
821+
const result = await getQuery(query1);
813822
verifyResults(result, { foo: 2 }, { foo: 1 });
814823
}
815824
);
@@ -819,8 +828,8 @@ describe('Query', () => {
819828
return withTestCollectionAndInitialData(
820829
[{ foo: 1 }, { foo: 2 }],
821830
async collRef => {
822-
const query = collRef.orderBy('foo').limit(1);
823-
const result = await getQuery(query);
831+
const query1 = query(collRef, orderBy('foo'), limit(1));
832+
const result = await getQuery(query1);
824833
verifyResults(result, { foo: 1 });
825834
}
826835
);
@@ -830,8 +839,8 @@ describe('Query', () => {
830839
return withTestCollectionAndInitialData(
831840
[{ foo: 1 }, { foo: 2 }, { foo: 3 }],
832841
async collRef => {
833-
const query = collRef.orderBy('foo').limitToLast(2);
834-
const result = await getQuery(query);
842+
const query1 = query(collRef, orderBy('foo'), limitToLast(2));
843+
const result = await getQuery(query1);
835844
verifyResults(result, { foo: 2 }, { foo: 3 });
836845
}
837846
);
@@ -841,8 +850,8 @@ describe('Query', () => {
841850
return withTestCollectionAndInitialData(
842851
[{ foo: 1 }, { foo: 2 }],
843852
async collRef => {
844-
const query = collRef.orderBy('foo').startAt(2);
845-
const result = await getQuery(query);
853+
const query1 = query(collRef, orderBy('foo'), startAt(2));
854+
const result = await getQuery(query1);
846855
verifyResults(result, { foo: 2 });
847856
}
848857
);
@@ -852,8 +861,8 @@ describe('Query', () => {
852861
return withTestCollectionAndInitialData(
853862
[{ foo: 1 }, { foo: 2 }],
854863
async collRef => {
855-
const query = collRef.orderBy('foo').startAfter(1);
856-
const result = await getQuery(query);
864+
const query1 = query(collRef, orderBy('foo'), startAfter(1));
865+
const result = await getQuery(query1);
857866
verifyResults(result, { foo: 2 });
858867
}
859868
);
@@ -863,8 +872,8 @@ describe('Query', () => {
863872
return withTestCollectionAndInitialData(
864873
[{ foo: 1 }, { foo: 2 }],
865874
async collRef => {
866-
const query = collRef.orderBy('foo').endAt(1);
867-
const result = await getQuery(query);
875+
const query1 = query(collRef, orderBy('foo'), endAt(1));
876+
const result = await getQuery(query1);
868877
verifyResults(result, { foo: 1 });
869878
}
870879
);
@@ -874,8 +883,8 @@ describe('Query', () => {
874883
return withTestCollectionAndInitialData(
875884
[{ foo: 1 }, { foo: 2 }],
876885
async collRef => {
877-
const query = collRef.orderBy('foo').endBefore(2);
878-
const result = await getQuery(query);
886+
const query1 = query(collRef, orderBy('foo'), endBefore(2));
887+
const result = await getQuery(query1);
879888
verifyResults(result, { foo: 1 });
880889
}
881890
);
@@ -885,13 +894,13 @@ describe('Query', () => {
885894
return withTestCollectionAndInitialData(
886895
[{ foo: 1 }, { foo: 2 }],
887896
async collRef => {
888-
let query = collRef.orderBy('foo').limit(1);
889-
let result = await getQuery(query);
897+
let query1 = query(collRef, orderBy('foo'), limit(1));
898+
let result = await getQuery(query1);
890899
verifyResults(result, { foo: 1 });
891900

892901
// Pass the document snapshot from the previous result
893-
query = query.startAfter(result.docs[0]);
894-
result = await getQuery(query);
902+
query1 = query(query1, startAfter(result.docs[0]));
903+
result = await getQuery(query1);
895904
verifyResults(result, { foo: 2 });
896905
}
897906
);
@@ -912,8 +921,8 @@ describe('Query', () => {
912921
await setDoc(fooDoc, { foo: 1 });
913922
await setDoc(barDoc, { bar: 1 });
914923

915-
const query = collectionGroup(collRef.firestore, collectionGroupId);
916-
const result = await getQuery(query);
924+
const query1 = collectionGroup(collRef.firestore, collectionGroupId);
925+
const result = await getQuery<firestore.DocumentData>(query1);
917926

918927
verifyResults(result, { bar: 1 }, { foo: 1 });
919928
});
@@ -976,10 +985,10 @@ describe('equality', () => {
976985
return withTestCollectionAndInitialData(
977986
[{ foo: 1 }, { foo: 2 }],
978987
async collRef => {
979-
const query1a = collRef.orderBy('foo');
980-
const query1b = collRef.orderBy('foo', 'asc');
981-
const query2 = collRef.orderBy('foo', 'desc');
982-
const query3 = collection(collRef, 'a/b').orderBy('foo');
988+
const query1a = query(collRef, orderBy('foo'));
989+
const query1b = query(collRef, orderBy('foo', 'asc'));
990+
const query2 = query(collRef, orderBy('foo', 'desc'));
991+
const query3 = query(collection(collRef, 'a/b'), orderBy('foo'));
983992

984993
expect(queryEqual(query1a, query1b)).to.be.true;
985994
expect(queryEqual(query1a, query2)).to.be.false;
@@ -992,9 +1001,9 @@ describe('equality', () => {
9921001
return withTestCollectionAndInitialData(
9931002
[{ foo: 1 }, { foo: 2 }],
9941003
async collRef => {
995-
const query1a = collRef.limit(10);
996-
const query1b = collRef.limit(10);
997-
const query2 = collRef.limit(100);
1004+
const query1a = query(collRef, limit(10));
1005+
const query1b = query(collRef, limit(10));
1006+
const query2 = query(collRef, limit(100));
9981007

9991008
const snap1a = await getQuery(query1a);
10001009
const snap1b = await getQuery(query1b);

packages/firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"test:exp:persistence": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --require ts-node/register --require exp/index.ts --require test/util/node_persistence.ts --config ../../config/mocharc.node.js",
3131
"test": "run-s lint test:all",
3232
"test:ci": "node ../../scripts/run_tests_in_ci.js",
33-
"test:all": "run-p test:browser test:travis test:minified test:exp",
33+
"test:all": "run-p test:browser test:travis test:minified test:exp test:lite",
3434
"test:browser": "karma start --single-run",
3535
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
3636
"test:node": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --config ../../config/mocharc.node.js",

0 commit comments

Comments
 (0)