Skip to content

Commit

Permalink
Added unit test for setting method context feature. Updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Scanferla committed Apr 9, 2015
1 parent 8f4c949 commit ce63525
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
13 changes: 2 additions & 11 deletions README.md
Expand Up @@ -7,36 +7,27 @@

Node module to allow CQRS-ing with Meteor.


## Example

```js
var bodyParser = require("body-parser");
var express = require("express");
var MongoClient = require("mongodb").MongoClient;
var MW = require("meteor-wapi");

var mongoUrl = process.env.MONGO_URL || "mongodb://localhost:3001/meteor";

MongoClient.connect(mongoUrl, function (err, db) {
if (err) {
return cb(err);
}
var mw = new MW(db);

var optionalContext = {
prefix: "echo: "
};

mv.methods({
mw.methods({
echo: function (string) {
return this.prefix + string;
}
}, optionalContext);

var path = "/method";
var app = express()
.post(path, mw.getRouter())
.use("/call", mw.getRouter())
.listen(process.env.PORT || 4000);
});
```
26 changes: 26 additions & 0 deletions test/unit/methods/_runMethod.js
Expand Up @@ -33,6 +33,32 @@ describe("Unit suite - The `_runMethod` method", function () {
.catch(done);
});

it("should call the method with the additional context we provide when registering it", function (done) {
var ctx = {
_methods: {
method: {
fn: sinon.spy(),
context: {
prop: "value"
}
}
}
};
methods._runMethod.call(ctx, {userId: null}, "method", [])
.then(function () {
try {
ctx._methods.method.fn.firstCall.thisValue.should.eql({
userId: null,
prop: "value"
});
} catch (e) {
return done(e);
}
done();
})
.catch(done);
});

});

describe("Unit suite - The promise returned by `_runMethod`", function () {
Expand Down

0 comments on commit ce63525

Please sign in to comment.