Skip to content

Commit 724336d

Browse files
committed
Update query unit tests
1 parent 015dcf2 commit 724336d

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

packages/database-compat/test/query.test.ts

+52-10
Original file line numberDiff line numberDiff line change
@@ -375,34 +375,76 @@ describe('Query Tests', () => {
375375
expect(queryId(path)).to.equal('default');
376376

377377
expect(queryId(path.startAt('pri','name'))).to.equal(
378-
'{"sn":"name","sp":"pri"}'
378+
'{"sin":true,"sn":"name","sp":"pri"}'
379379
);
380380
expect(queryId(path.startAfter('pri','name'))).to.equal(
381-
'{"sn":"name-","sp":"pri"}'
381+
'{"sin":false,"sn":"name","sp":"pri"}'
382382
);
383+
expect(queryId(path.endAt('pri','name'))).to.equal(
384+
'{"ein":true,"en":"name","ep":"pri"}'
385+
);
386+
expect(queryId(path.endBefore('pri','name'))).to.equal(
387+
'{"ein":false,"en":"name","ep":"pri"}'
388+
);
389+
383390
expect(queryId(path.startAt('spri').endAt('epri'))).to.equal(
384-
'{"ep":"epri","sp":"spri"}'
391+
'{"ein":true,"ep":"epri","sin":true,"sp":"spri"}'
392+
);
393+
expect(queryId(path.startAt('spri').endBefore('epri'))).to.equal(
394+
'{"ein":false,"ep":"epri","sin":true,"sp":"spri"}'
385395
);
386396
expect(queryId(path.startAfter('spri').endAt('epri'))).to.equal(
387-
'{"ep":"epri","sn":"[MAX_NAME]","sp":"spri"}'
397+
'{"ein":true,"ep":"epri","sin":false,"sp":"spri"}'
398+
);
399+
expect(queryId(path.startAfter('spri').endBefore('epri'))).to.equal(
400+
'{"ein":false,"ep":"epri","sin":false,"sp":"spri"}'
388401
);
402+
389403
expect(
390404
queryId(path.startAt('spri','sname').endAt('epri','ename'))
391-
).to.equal('{"en":"ename","ep":"epri","sn":"sname","sp":"spri"}');
405+
).to.equal(
406+
'{"ein":true,"en":"ename","ep":"epri","sin":true,"sn":"sname","sp":"spri"}'
407+
);
408+
expect(
409+
queryId(path.startAt('spri','sname').endBefore('epri','ename'))
410+
).to.equal(
411+
'{"ein":false,"en":"ename","ep":"epri","sin":true,"sn":"sname","sp":"spri"}'
412+
);
392413
expect(
393414
queryId(path.startAfter('spri','sname').endAt('epri','ename'))
394-
).to.equal('{"en":"ename","ep":"epri","sn":"sname-","sp":"spri"}');
415+
).to.equal(
416+
'{"ein":true,"en":"ename","ep":"epri","sin":false,"sn":"sname","sp":"spri"}'
417+
);
418+
expect(
419+
queryId(path.startAfter('spri','sname').endBefore('epri','ename'))
420+
).to.equal(
421+
'{"ein":false,"en":"ename","ep":"epri","sin":false,"sn":"sname","sp":"spri"}'
422+
);
423+
395424
expect(queryId(path.startAt('pri').limitToFirst(100))).to.equal(
396-
'{"l":100,"sp":"pri","vf":"l"}'
425+
'{"l":100,"sin":true,"sp":"pri","vf":"l"}'
397426
);
398427
expect(queryId(path.startAfter('pri').limitToFirst(100))).to.equal(
399-
'{"l":100,"sn":"[MAX_NAME]","sp":"pri","vf":"l"}'
428+
'{"l":100,"sin":false,"sp":"pri","vf":"l"}'
429+
);
430+
expect(queryId(path.endAt('pri').limitToLast(100))).to.equal(
431+
'{"ein":true,"ep":"pri","l":100,"vf":"r"}'
400432
);
433+
expect(queryId(path.endBefore('pri').limitToLast(100))).to.equal(
434+
'{"ein":false,"ep":"pri","l":100,"vf":"r"}'
435+
);
436+
401437
expect(queryId(path.startAt('bar').orderByChild('foo'))).to.equal(
402-
'{"i":"foo","sp":"bar"}'
438+
'{"i":"foo","sin":true,"sp":"bar"}'
403439
);
404440
expect(queryId(path.startAfter('bar').orderByChild('foo'))).to.equal(
405-
'{"i":"foo","sn":"[MAX_NAME]","sp":"bar"}'
441+
'{"i":"foo","sin":false,"sp":"bar"}'
442+
);
443+
expect(queryId(path.endAt('bar').orderByChild('foo'))).to.equal(
444+
'{"ein":true,"ep":"bar","i":"foo"}'
445+
);
446+
expect(queryId(path.endBefore('bar').orderByChild('foo'))).to.equal(
447+
'{"ein":false,"ep":"bar","i":"foo"}'
406448
);
407449
});
408450

packages/database/src/core/view/QueryParams.ts

+4-31
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { KEY_INDEX } from '../snap/indexes/KeyIndex';
2222
import{PathIndex}from'../snap/indexes/PathIndex';
2323
import{PRIORITY_INDEX,PriorityIndex}from'../snap/indexes/PriorityIndex';
2424
import{VALUE_INDEX}from'../snap/indexes/ValueIndex';
25-
import{predecessor,successor}from'../util/NextPushId';
2625
import{MAX_NAME,MIN_NAME}from'../util/util';
2726

2827
import{IndexedFilter}from'./filter/IndexedFilter';
@@ -195,10 +194,12 @@ export class QueryParams {
195194
copy.limitSet_=this.limitSet_;
196195
copy.limit_=this.limit_;
197196
copy.startSet_=this.startSet_;
197+
copy.startAfterSet_=this.startAfterSet_;
198198
copy.indexStartValue_=this.indexStartValue_;
199199
copy.startNameSet_=this.startNameSet_;
200200
copy.indexStartName_=this.indexStartName_;
201201
copy.endSet_=this.endSet_;
202+
copy.endBeforeSet_=this.endBeforeSet_;
202203
copy.indexEndValue_=this.indexEndValue_;
203204
copy.endNameSet_=this.endNameSet_;
204205
copy.indexEndName_=this.indexEndName_;
@@ -277,21 +278,7 @@ export function queryParamsStartAfter(
277278
indexValue: unknown,
278279
key?: string|null
279280
): QueryParams{
280-
letparams: QueryParams;
281-
if(queryParams.index_===KEY_INDEX){
282-
if(typeofindexValue==='string'){
283-
indexValue=successor(indexValueasstring);
284-
}
285-
params=queryParamsStartAt(queryParams,indexValue,key);
286-
}else{
287-
letchildKey: string;
288-
if(key==null){
289-
childKey=MAX_NAME;
290-
}else{
291-
childKey=successor(key);
292-
}
293-
params=queryParamsStartAt(queryParams,indexValue,childKey);
294-
}
281+
constparams: QueryParams=queryParamsStartAt(queryParams,indexValue,key);
295282
params.startAfterSet_=true;
296283
returnparams;
297284
}
@@ -322,21 +309,7 @@ export function queryParamsEndBefore(
322309
indexValue: unknown,
323310
key?: string|null
324311
): QueryParams{
325-
letchildKey: string;
326-
letparams: QueryParams;
327-
if(queryParams.index_===KEY_INDEX){
328-
if(typeofindexValue==='string'){
329-
indexValue=predecessor(indexValueasstring);
330-
}
331-
params=queryParamsEndAt(queryParams,indexValue,key);
332-
}else{
333-
if(key==null){
334-
childKey=MIN_NAME;
335-
}else{
336-
childKey=predecessor(key);
337-
}
338-
params=queryParamsEndAt(queryParams,indexValue,childKey);
339-
}
312+
constparams: QueryParams=queryParamsEndAt(queryParams,indexValue,key);
340313
params.endBeforeSet_=true;
341314
returnparams;
342315
}

0 commit comments

Comments
 (0)
close