Skip to content

Commit

Permalink
Merge pull request #333 from geek/master
Browse files Browse the repository at this point in the history
Support strict.find setting
  • Loading branch information
geek committed Feb 4, 2016
2 parents 6eb4e18 + 7f6ae09 commit 63be4ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion seneca.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ var internals = {
fixedargs: true,

// Adding a pattern overrides existing pattern only if matches exactly.
add: false
add: false,

// If no action is found and find is false, then no error returned along with empty object
find: true
},

// Action cache. Makes inbound messages idempotent.
Expand Down Expand Up @@ -1012,6 +1015,7 @@ function make_seneca (initial_options) {
var callargs = args
var actstats
var act_callpoint = callpoint()
args.default$ = args.default$ || (!so.strict.find ? {} : args.default$)

prior_ctxt = prior_ctxt || { chain: [], entry: true, depth: 1 }

Expand Down
27 changes: 27 additions & 0 deletions test/seneca.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,4 +1615,31 @@ describe('seneca', function () {
done()
})
})

it('supports strict.find for allowing not found actions', function (done) {
var seneca = Seneca({ log: 'silent', strict: { find: false } })
seneca.act({ a: 1 }, function (err, out) {
expect(err).to.not.exist()
expect(Object.keys(out).length).to.equal(0)
done()
})
})

it('supports strict.find for disabling not found actions', function (done) {
var seneca = Seneca({ log: 'silent', strict: { find: true } })
seneca.act({ a: 1 }, function (err, out) {
expect(err).to.exist()
expect(out).to.not.exist()
done()
})
})

it('supports strict.find not overriding existing default$', function (done) {
var seneca = Seneca({ log: 'silent', strict: { find: false } })
seneca.act({ a: 1, default$: { foo: 'bar' } }, function (err, out) {
expect(err).to.not.exist()
expect(Object.keys(out).length).to.equal(1)
done()
})
})
})

0 comments on commit 63be4ae

Please sign in to comment.