Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
add instance resource tests for testing that custom data is cleaned u…
Browse files Browse the repository at this point in the history
…p during save()
  • Loading branch information
typerandom committed May 16, 2016
1 parent f775f34 commit 122e074
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/sp.resource.instanceResource_test.js
Expand Up @@ -165,13 +165,15 @@ describe('Resources: ', function () {

describe('call to save()', function(){
var sandbox, cb, saveResourceSpy;

before(function(){
cb = function(){};
sandbox = sinon.sandbox.create();
saveResourceSpy = sandbox.stub(ds, 'saveResource');

instanceResource.save(cb);
});

after(function(){
sandbox.restore();
});
Expand All @@ -182,6 +184,59 @@ describe('Resources: ', function () {
/* jshint +W030 */
saveResourceSpy.should.have.been.calledWith(instanceResource, cb);
});

describe('with custom data', function () {
var hasReservedFieldsSpy;
var hasRemovedPropertiesSpy;
var deleteReservedFieldsSpy;
var deleteRemovedPropertiesSpy;

before(function () {
var customDataMock = {
_hasReservedFields: function () {},
_hasRemovedProperties: function () {},
_deleteReservedFields: function () {},
_deleteRemovedProperties: function () {}
};

hasReservedFieldsSpy = sandbox.stub(customDataMock, '_hasReservedFields').returns(true);
hasRemovedPropertiesSpy = sandbox.stub(customDataMock, '_hasRemovedProperties').returns(true);
deleteReservedFieldsSpy = sandbox.stub(customDataMock, '_deleteReservedFields').returns(customDataMock);
deleteRemovedPropertiesSpy = sandbox.stub(customDataMock, '_deleteRemovedProperties');

instanceResource.customData = customDataMock;
instanceResource.save();
});

after(function () {
delete instanceResource['customData'];
sandbox.restore();
});

it('should call customData._hasReservedFields()', function () {
/* jshint -W030 */
hasReservedFieldsSpy.should.have.been.calledOnce;
/* jshint +W030 */
});

it('should call customData._deleteReservedFields()', function () {
/* jshint -W030 */
hasReservedFieldsSpy.should.have.been.calledOnce;
/* jshint +W030 */
});

it('should call customData._hasRemovedProperties()', function () {
/* jshint -W030 */
hasRemovedPropertiesSpy.should.have.been.calledOnce;
/* jshint +W030 */
});

it('should call customData._deleteRemovedProperties()', function () {
/* jshint -W030 */
deleteRemovedPropertiesSpy.should.have.been.calledOnce;
/* jshint +W030 */
});
});
});

describe('call to delete()', function(){
Expand Down

0 comments on commit 122e074

Please sign in to comment.