Skip to content

Commit 189085e

Browse files
committed
update integration tests
1 parent d346596 commit 189085e

File tree

1 file changed

+73
-65
lines changed

1 file changed

+73
-65
lines changed

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

Lines changed: 73 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import chaiAsPromised from 'chai-as-promised';
2222

2323
import {
2424
countQuery,
25-
getAggregateFromServerDirect
25+
getAggregateFromServerDirect,
26+
aggregateQueryEqual,
27+
aggregateQuerySnapshotEqual
2628
} from '../../src/lite-api/aggregate';
2729
import { Bytes } from '../../src/lite-api/bytes';
2830
import {
@@ -2046,16 +2048,28 @@ describe('withConverter() support', () => {
20462048

20472049
describe('countQuery()', () => {
20482050
const converter = {
2049-
toFirestore(input: { id: string, content: string}): DocumentData {
2050-
return { key: input.id, value:input.content };
2051+
toFirestore(input: { id: string; content: string }): DocumentData {
2052+
return { key: input.id, value: input.content };
20512053
},
2052-
fromFirestore(snapshot: QueryDocumentSnapshot): {id: string, content: string} {
2054+
fromFirestore(snapshot: QueryDocumentSnapshot): {
2055+
id: string;
2056+
content: string;
2057+
} {
20532058
const data = snapshot.data();
2054-
return {content:data.value, id:data.documentId} ;
2059+
return { content: data.value, id: data.documentId };
20552060
}
20562061
};
20572062

2058-
it.only('empty collection count equals to 0', () => {
2063+
const testDocs = [
2064+
{ key: 'a', value: 'Adam' },
2065+
{ key: 'b', value: 'Bob' },
2066+
{ key: 'c', value: 'Chris' },
2067+
{ key: 'a', value: 'Anna' },
2068+
{ key: 'b', value: 'Bill' },
2069+
{ key: 'c', value: 'Cooper' }
2070+
];
2071+
2072+
it('empty collection count equals to 0', () => {
20592073
return withTestCollection(async coll => {
20602074
const countQuery_ = countQuery(query(coll));
20612075
expect(countQuery_.type).to.equal('AggregateQuery');
@@ -2065,114 +2079,108 @@ describe('countQuery()', () => {
20652079
});
20662080
});
20672081

2068-
it.only('test collection count equals to 6', () => {
2069-
const testDocs = [
2070-
{ key: 'a' },
2071-
{ key: 'b' },
2072-
{ key: 'c' },
2073-
{ key: 'd' },
2074-
{ key: 'e' },
2075-
{ key: 'f' }
2076-
];
2082+
it('test collection count equals to 6', () => {
20772083
return withTestCollectionAndInitialData(testDocs, async collection => {
20782084
const countQuery_ = countQuery(query(collection));
20792085
const snapshot = await getAggregateFromServerDirect(countQuery_);
20802086
expect(snapshot.getCount()).to.equal(6);
20812087
});
20822088
});
20832089

2084-
it.only('test collection count with filter', () => {
2085-
const testDocs = [
2086-
{ key: 'a' },
2087-
{ key: 'b' },
2088-
{ key: 'c' },
2089-
{ key: 'a' },
2090-
{ key: 'b' },
2091-
{ key: 'c' }
2092-
];
2090+
it('test collection count with filter', () => {
20932091
return withTestCollectionAndInitialData(testDocs, async collection => {
2094-
let query_ = query(collection, where('key', '==', 'a'));
2092+
const query_ = query(collection, where('key', '==', 'a'));
20952093

20962094
const countQuery_ = countQuery(query_);
20972095
const snapshot = await getAggregateFromServerDirect(countQuery_);
20982096
expect(snapshot.getCount()).to.equal(2);
20992097
});
21002098
});
21012099

2102-
it.only('test collection count with filter effected by small limit', () => {
2103-
const testDocs = [
2104-
{ key: 'a' },
2105-
{ key: 'b' },
2106-
{ key: 'c' },
2107-
{ key: 'a' },
2108-
{ key: 'b' },
2109-
{ key: 'c' }
2110-
];
2100+
it('test collection count with filter effected by small limit', () => {
21112101
// limit that is less that the actual count would work like count up_to.
21122102
return withTestCollectionAndInitialData(testDocs, async collection => {
2113-
let query_ = query(collection, where('key', '==', 'a'), limit(1));
2103+
const query_ = query(collection, where('key', '==', 'a'), limit(1));
21142104

21152105
const countQuery_ = countQuery(query_);
21162106
const snapshot = await getAggregateFromServerDirect(countQuery_);
21172107
expect(snapshot.getCount()).to.equal(1);
21182108
});
21192109
});
21202110

2121-
it.only('test collection count with filter not effected by large limit', () => {
2122-
const testDocs = [
2123-
{ key: 'a' },
2124-
{ key: 'b' },
2125-
{ key: 'c' },
2126-
{ key: 'a' },
2127-
{ key: 'b' },
2128-
{ key: 'c' }
2129-
];
2111+
it('test collection count with filter not effected by large limit', () => {
21302112
//limit that is larger than actual count wouldn't impact the return value
21312113
return withTestCollectionAndInitialData(testDocs, async collection => {
2132-
let query_ = query(collection, where('key', '==', 'a'), limit(3));
2114+
const query_ = query(collection, where('key', '==', 'a'), limit(3));
21332115

21342116
const countQuery_ = countQuery(query_);
21352117
const snapshot = await getAggregateFromServerDirect(countQuery_);
21362118
expect(snapshot.getCount()).to.equal(2);
21372119
});
21382120
});
21392121

2140-
it.only('test collection count with converter on query', () => {
2141-
const testDocs = [
2142-
{ key: 'a', value:"Adam" },
2143-
{ key: 'b' , value: "Bob"},
2144-
{ key: 'c', value: "Chris" },
2145-
{ key: 'a', value:"Anna" },
2146-
{ key: 'b' , value: "Bill"},
2147-
{ key: 'c', value: "Cooper" }
2148-
];
2122+
it('test collection count with converter on query', () => {
21492123
//testing out the converter impact on the AggregateQuery type
21502124
return withTestCollectionAndInitialData(testDocs, async collection => {
2151-
let query_ = query(collection, where('key', '==', 'a')).withConverter(converter);
2125+
const query_ = query(collection, where('key', '==', 'a')).withConverter(
2126+
converter
2127+
);
21522128

21532129
const countQuery_ = countQuery(query_);
21542130
const snapshot = await getAggregateFromServerDirect(countQuery_);
21552131
expect(snapshot.getCount()).to.equal(2);
21562132
});
21572133
});
21582134

2159-
it.only('test collection count with converter on collection', () => {
2160-
const testDocs = [
2161-
{ key: 'a', value:"Adam" },
2162-
{ key: 'b' , value: "Bob"},
2163-
{ key: 'c', value: "Chris" },
2164-
{ key: 'a', value:"Anna" },
2165-
{ key: 'b' , value: "Bill"},
2166-
{ key: 'c', value: "Cooper" }
2167-
];
2135+
it('test collection count with converter on collection', () => {
21682136
//testing out the converter impact on the AggregateQuery type
21692137
return withTestCollectionAndInitialData(testDocs, async collection => {
21702138
const ref = collection.withConverter(converter);
2171-
let query_ = query(ref,where('key', '==', 'a'));
2139+
const query_ = query(ref, where('key', '==', 'a'));
21722140

21732141
const countQuery_ = countQuery(query_);
21742142
const snapshot = await getAggregateFromServerDirect(countQuery_);
21752143
expect(snapshot.getCount()).to.equal(2);
21762144
});
21772145
});
2146+
2147+
it('aggregateQueryEqual returns true on same queries', () => {
2148+
return withTestCollectionAndInitialData(testDocs, async collection => {
2149+
const query_1 = query(collection, where('key', '==', 'a'));
2150+
const query_2 = query(collection, where('key', '==', 'a'));
2151+
2152+
const countQuery_1 = countQuery(query_1);
2153+
const countQuery_2 = countQuery(query_2);
2154+
expect(aggregateQueryEqual(countQuery_1, countQuery_2)).to.be.true;
2155+
});
2156+
});
2157+
2158+
it('aggregateQueryEqual returns false on different queries', () => {
2159+
return withTestCollectionAndInitialData(testDocs, async collection => {
2160+
const query_1 = query(collection, where('key', '==', 'a'));
2161+
const query_2 = query(collection, where('key', '!=', 'a'));
2162+
2163+
const countQuery_1 = countQuery(query_1);
2164+
const countQuery_2 = countQuery(query_2);
2165+
expect(aggregateQueryEqual(countQuery_1, countQuery_2)).to.be.false;
2166+
});
2167+
});
2168+
2169+
it('aggregateQuerySnapshotEqual returns true on same queries', () => {
2170+
return withTestCollectionAndInitialData(testDocs, async collection => {
2171+
const query_original = query(collection, where('key', '==', 'a'));
2172+
const query_copy = query(collection, where('key', '==', 'a'));
2173+
2174+
const countQuery_original_1 = countQuery(query_original);
2175+
const countQuery_original_2 = countQuery(query_original);
2176+
const countQuery_copy = countQuery(query_copy);
2177+
2178+
const snapshot_original_1 = await getAggregateFromServerDirect(countQuery_original_1);
2179+
const snapshot_original_2 = await getAggregateFromServerDirect(countQuery_original_2);
2180+
const snapshot_copy = await getAggregateFromServerDirect(countQuery_copy);
2181+
2182+
expect(aggregateQuerySnapshotEqual(snapshot_original_1, snapshot_original_2)).to.be.true;
2183+
expect(aggregateQuerySnapshotEqual(snapshot_original_1, snapshot_copy)).to.be.true;
2184+
});
2185+
});
21782186
});

0 commit comments

Comments
 (0)