-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jefferson-health/createSpec
added update and param tests
- Loading branch information
Showing
6 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var paramFn = require('../src/param'); | ||
|
||
describe('Param Function', function() { | ||
describe('param', function() { | ||
it('should call find on the resource for the resourceId and assign the result to req', function (done) { | ||
let resourceId = 1; | ||
let resource = {id: resourceId}; | ||
let resolved = Promise.resolve(resource); | ||
let next = sinon.spy(); | ||
let req = { | ||
with: [ 'relations' ], | ||
query: {where: {id: {'=' : 1}}} | ||
}; | ||
let _this = { | ||
resource: { | ||
find: function() { | ||
return resolved; | ||
} | ||
}, | ||
errorHandler: sinon.spy() | ||
}; | ||
sinon.spy(_this.resource, 'find'); | ||
paramFn.call(_this, req, {}, next, resourceId); | ||
|
||
resolved.then(function() { | ||
_this.resource.find.should.have.been.calledWith(resourceId, Object.assign({with: req.with},req.query)); | ||
next.should.have.been.calledOnce; | ||
req.resource.should.equal(resource); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict'; | ||
|
||
var updateFns = require('../src/update'); | ||
|
||
describe('Update Functions', function() { | ||
describe('beforeUpdate', function() { | ||
it('should call next by default', () => { | ||
let nextSpy = sinon.spy(); | ||
updateFns.beforeUpdate({}, {}, nextSpy); | ||
nextSpy.should.have.been.calledOnce; | ||
}); | ||
}); | ||
|
||
describe('update', function() { | ||
it('should call update on the resource and assign the result to req', function (done) { | ||
let updatedResource = {id: 1}; | ||
let resolved = Promise.resolve(updatedResource); | ||
let next = sinon.spy(); | ||
let req = { body: { | ||
id: 0 | ||
}}; | ||
let _this = { | ||
resource: { | ||
update: function() { | ||
return resolved; | ||
} | ||
}, | ||
errorHandler: sinon.spy() | ||
}; | ||
sinon.spy(_this.resource, 'update'); | ||
updateFns.update.call(_this, req, {}, next); | ||
|
||
resolved.then(function() { | ||
_this.resource.update.should.have.been.calledWith(req.body); | ||
next.should.have.been.calledOnce; | ||
req.updatedResource.should.equal(updatedResource); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('afterUpdate', function() { | ||
it('should send a 200 response and the updated resource by default', function() { | ||
let res = { | ||
status: function() { | ||
return res; | ||
}, | ||
end: function() { | ||
return res; | ||
}, | ||
send: function() { | ||
return res; | ||
} | ||
}; | ||
let req = { | ||
updatedResource: { | ||
id: 2 | ||
} | ||
}; | ||
sinon.spy(res,'status'); | ||
sinon.spy(res,'send'); | ||
sinon.spy(res,'end'); | ||
updateFns.afterUpdate(req, res); | ||
res.status.should.have.been.calledOnce; | ||
res.status.should.have.been.calledWith(200); | ||
res.send.should.have.been.calledWith(req.updatedResource); | ||
res.end.should.have.been.calledOnce; | ||
res.end.should.have.been.calledAfter(res.send); | ||
}); | ||
}); | ||
}); |