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

Feature Request - Handle MongooseModel.method().cursor() streams #25

Open
paynoattn opened this issue Aug 29, 2017 · 3 comments
Open

Feature Request - Handle MongooseModel.method().cursor() streams #25

paynoattn opened this issue Aug 29, 2017 · 3 comments

Comments

@paynoattn
Copy link

paynoattn commented Aug 29, 2017

The .cursor() method on mongoose model methods returns a readable stream, not a promise. Given how stream-oriented node js, and how you can easilly .pipe your mongoose queries to your server response like so:

const Model = mongoose.model('model', mySchema);

// ...
Model.find().limit(10).cursor().pipe(res);

It would be nice to have a stub method that returned a readable stream like so

MyMock = sinon.stub(Model)
MyMock.expects('find')
      .chain('limit').withArgs(10)
      .chain('cursor')
      .streams([1,2,3])

For now, the only way I can do this is to create a custom readable stream that the mock returns like so.

const Readable = require('stream').readable,
      rs = new Readable({objectMode: true}),
      array = [1,2,3];
array.forEach(x => rs.push(x));
rs.push(null);

MyMock.expects('find')
      .chain('limit').withArgs(10)
      .chain('cursor')
      .returns(rs);
@gaguirre
Copy link
Collaborator

gaguirre commented Oct 2, 2017

Hi @paynoattn, will take a look this week.
A PR for this would be great! 😃

@natanavra
Copy link

Any news on this one?

1 similar comment
@myatsuphyo
Copy link

Any news on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants