Skip to content

Commit eb447a7

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

File tree

2 files changed

+56
-40
lines changed

2 files changed

+56
-40
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-30
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,12 @@ export class QueryParams {
195195
copy.limitSet_=this.limitSet_;
196196
copy.limit_=this.limit_;
197197
copy.startSet_=this.startSet_;
198+
copy.startAfterSet_=this.startAfterSet_;
198199
copy.indexStartValue_=this.indexStartValue_;
199200
copy.startNameSet_=this.startNameSet_;
200201
copy.indexStartName_=this.indexStartName_;
201202
copy.endSet_=this.endSet_;
203+
copy.endBeforeSet_=this.endBeforeSet_;
202204
copy.indexEndValue_=this.indexEndValue_;
203205
copy.endNameSet_=this.endNameSet_;
204206
copy.indexEndName_=this.indexEndName_;
@@ -277,21 +279,7 @@ export function queryParamsStartAfter(
277279
indexValue: unknown,
278280
key?: string|null
279281
): 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-
}
282+
letparams: QueryParams=queryParamsStartAt(queryParams,indexValue,key);
295283
params.startAfterSet_=true;
296284
returnparams;
297285
}
@@ -322,21 +310,7 @@ export function queryParamsEndBefore(
322310
indexValue: unknown,
323311
key?: string|null
324312
): 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-
}
313+
letparams: QueryParams=queryParamsEndAt(queryParams,indexValue,key);
340314
params.endBeforeSet_=true;
341315
returnparams;
342316
}

0 commit comments

Comments
 (0)
close