Skip to content

Commit

Permalink
Parse subdocument schema as Object
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-victor committed Apr 21, 2017
1 parent 9193d28 commit b37d883
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/bodymen-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ export default class BodymenSchema {
options = {type: RegExp, default: options}
} else if (_.isFunction(options)) {
options = {type: options}
} else if (_.isObject(options)) {
if (!_.isFunction(options.type)) {
options.type = Object
}
}

return options || {}
Expand Down
21 changes: 20 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('Bodymen handler', (t) => {
})

test('Bodymen middleware', (t) => {
t.plan(5)
t.plan(7)

request(route())
.post('/tests')
Expand Down Expand Up @@ -96,4 +96,23 @@ test('Bodymen middleware', (t) => {
if (err) throw err
t.same(res.body, {links: [{icon: 'path to icon'}]}, 'should respond with correct object')
})

// parse subdocuments as Object
request(route(new Schema({sub: {name: String}})))
.post('/tests')
.send({sub: {name: 'test'}})
.expect(200)
.end((err, res) => {
if (err) throw err
t.same(res.body, {sub: {name: 'test'}}, 'should respond with correct object')
})

request(route(new Schema({links: [{icon: String}]})))
.post('/tests')
.send({links: [{icon: 'path to icon'}]})
.expect(200)
.end((err, res) => {
if (err) throw err
t.same(res.body, {links: [{icon: 'path to icon'}]}, 'should respond with correct object')
})
})

0 comments on commit b37d883

Please sign in to comment.