Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test coverage for #83 #144

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/collections/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class FindCursor {
this.options = options ?? {};

const isOverPageSizeLimit = this.options.sort &&
this.options.sort.$vector == null &&
(this.options.limit == null || this.options.limit > 20);
this.options.sort.$vector == null &&
(this.options.limit == null || this.options.limit > 20);
if (isOverPageSizeLimit) {
throw new Error('Cannot set sort option without limit <= 20, JSON API can currently only return 20 documents with sort');
}
Expand Down
18 changes: 18 additions & 0 deletions tests/collections/cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ describe(`StargateMongoose - ${testClient} Connection - collections.cursor`, asy
});
assert.strictEqual(docCount, sampleUsers.length);
});
it('should only store at most `pageSize` documents at a time', async () => {
const docs = [];
for (let i = 0; i < 35; ++i) {
docs.push({ name: `doc ${i}` });
}
while (docs.length > 0) {
const toInsert = docs.splice(0, 20);
await collection.insertMany(toInsert);
}

const cursor = new FindCursor(collection, {});
let docCount = 0;
await cursor.forEach(() => {
assert.equal(cursor.page.length, docCount < 20 ? 20 : 15);
docCount++;
});
assert.strictEqual(docCount, 35);
});
});

describe('Cursor noops', () => {
Expand Down