Skip to content

Commit

Permalink
Feature/estimated document count (#43)
Browse files Browse the repository at this point in the history
* Add support for mongoose 'countDocuments' function

* Add support for mongoose 'estimatedDocumentCount' function

* Update doc
  • Loading branch information
sepulvedablanco authored and alonronin committed Oct 31, 2018
1 parent c3eb02b commit bf69779
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ beforeEach(() => {

- [x] `find` - for find query
- [x] `findOne` - for findOne query
- [x] `count` - for count query
- [x] `count` - for count query (deprecated)
- [x] `countDocuments` for count query
- [x] `estimatedDocumentCount` for count collection documents
- [x] `distinct` - for distinct query
- [x] `findOneAndUpdate` - for findOneAndUpdate query
- [x] `findOneAndRemove` - for findOneAndRemove query
Expand Down
42 changes: 42 additions & 0 deletions ___tests___/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ describe('mockingoose', () => {
});
});

it('should countDocuments', () => {
const count = 2;
mockingoose.User.toReturn(count, 'countDocuments');

return User.countDocuments().then(result => {
expect(result).toBe(count);
});
});

it('should estimatedDocumentCount', () => {
const count = 2;
mockingoose.User.toReturn(count, 'estimatedDocumentCount');

return User.estimatedDocumentCount().then(result => {
expect(result).toBe(count);
});
});

it('should count exec and cb', (done) => {
const count = 2;
mockingoose.User.toReturn(count, 'count');
Expand All @@ -98,6 +116,30 @@ describe('mockingoose', () => {
});
});

it('should countDocuments exec and cb', (done) => {
const count = 2;
mockingoose.User.toReturn(count, 'countDocuments');

User
.countDocuments()
.exec((err, result) => {
expect(result).toBe(count);
done();
});
});

it('should estimatedDocumentCount exec and cb', (done) => {
const count = 2;
mockingoose.User.toReturn(count, 'estimatedDocumentCount');

User
.estimatedDocumentCount()
.exec((err, result) => {
expect(result).toBe(count);
done();
});
});

it('should update with exec and callback', (done) => {
mockingoose.User.toReturn({ ok: 1, nModified: 1, n: 1 }, 'update');

Expand Down
4 changes: 2 additions & 2 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bf69779

Please sign in to comment.