Skip to content

Commit

Permalink
updated tests to isFilterConcise
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Nov 30, 2023
1 parent 8dab9a4 commit bff7ad0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/store/index-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export class IndexLevel {
}


private static isFilterConcise(filter: Filter, queryOptions: QueryOptions): boolean {
public static isFilterConcise(filter: Filter, queryOptions: QueryOptions): boolean {
// if there is a specific recordId in the filter, return true immediately.
if (filter.recordId !== undefined) {
return true;
Expand All @@ -586,7 +586,6 @@ export class IndexLevel {
}
// NOTE: remaining conditions will not have cursor
if (
filter.protocol !== undefined ||
filter.protocolPath !== undefined ||
filter.contextId !== undefined ||
filter.parentId !== undefined ||
Expand Down
46 changes: 46 additions & 0 deletions tests/store/index-level.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,50 @@ describe('IndexLevel', () => {
digits.forEach((n,i) => expect(encodedDigits.at(i)).to.equal(IndexLevel.encodeNumberValue(n)));
});
});

describe('isFilterConcise', () => {
const queryOptionsWithCursor = { sortProperty: 'sort', cursor: 'cursor' };
const queryOptionsWithoutCursor = { sortProperty: 'sort' };

it('recordId is always concise', async () => {
expect(IndexLevel.isFilterConcise({ recordId: 'record-id' }, queryOptionsWithCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ recordId: 'record-id' }, queryOptionsWithoutCursor)).to.equal(true);
});

it('other than if `recordId` exists, if a cursor exists it is never concise', async () => {
expect(IndexLevel.isFilterConcise({ schema: 'schema', contextId: 'contextId', parentId: 'parentId' }, queryOptionsWithCursor)).to.equal(false);

// control
expect(IndexLevel.isFilterConcise({ schema: 'schema', contextId: 'contextId', parentId: 'parentId' }, queryOptionsWithoutCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ recordId: 'record-id' }, queryOptionsWithCursor)).to.equal(true);
});

it('if there is no cursor - protocolPath, contextId, parentId, or schema return a concise filter', async () => {
expect(IndexLevel.isFilterConcise({ protocolPath: 'protocolPath' }, queryOptionsWithoutCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ protocolPath: 'protocolPath' }, queryOptionsWithCursor)).to.equal(false); // control

expect(IndexLevel.isFilterConcise({ contextId: 'contextId' }, queryOptionsWithoutCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ contextId: 'contextId' }, queryOptionsWithCursor)).to.equal(false); // control

expect(IndexLevel.isFilterConcise({ contextId: 'parentId' }, queryOptionsWithoutCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ contextId: 'parentId' }, queryOptionsWithCursor)).to.equal(false); // control

expect(IndexLevel.isFilterConcise({ contextId: 'schema' }, queryOptionsWithoutCursor)).to.equal(true);
expect(IndexLevel.isFilterConcise({ contextId: 'schema' }, queryOptionsWithCursor)).to.equal(false); // control
});

it('if there is no cursor, and it is not one of the conditions, return not concise', async () => {
expect(IndexLevel.isFilterConcise({ dataSize: { gt: 123 } }, queryOptionsWithoutCursor)).to.equal(false);

// control
expect(IndexLevel.isFilterConcise({ schema: 'schema', contextId: 'contextId', parentId: 'parentId' }, queryOptionsWithoutCursor)).to.equal(true);
});

it('if protocol filter exists by itself it is not a concise filter', async () => {
expect(IndexLevel.isFilterConcise({ protocol: 'protocol' }, queryOptionsWithoutCursor)).to.equal(false);

// control
expect(IndexLevel.isFilterConcise({ protocol: 'protocol', protocolPath: 'path/to' }, queryOptionsWithoutCursor)).to.equal(true);
});
});
});

0 comments on commit bff7ad0

Please sign in to comment.