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

Commit

Permalink
add tests for InstanceResource.invalidate()
Browse files Browse the repository at this point in the history
  • Loading branch information
typerandom committed Mar 9, 2016
1 parent 4e316ad commit 0c0341f
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions test/sp.resource.instanceResource_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var common = require('./common');
var sinon = common.sinon;
var nock = common.nock;

var u = common.u;
var nock = common.nock;
var sinon = common.sinon;
var assert = common.assert;

var Resource = require('../lib/resource/Resource');
var InstanceResource = require('../lib/resource/InstanceResource');
Expand All @@ -23,7 +25,7 @@ describe('Resources: ', function () {
}, ds);
});

describe('call to get resource', function(){
describe('call to get()', function(){
describe('without property name', function(){
var sandbox, error, cb, getResourceSpy;
before(function(){
Expand Down Expand Up @@ -161,7 +163,7 @@ describe('Resources: ', function () {
});
});

describe('call to save resource', function(){
describe('call to save()', function(){
var sandbox, cb, saveResourceSpy;
before(function(){
cb = function(){};
Expand All @@ -182,7 +184,7 @@ describe('Resources: ', function () {
});
});

describe('call to delete resource', function(){
describe('call to delete()', function(){
var sandbox, cb, deleteResourceSpy;
before(function(){
cb = function(){};
Expand All @@ -201,5 +203,39 @@ describe('Resources: ', function () {
deleteResourceSpy.should.have.been.calledWith(instanceResource, cb);
});
});

describe('call to invalidate()', function () {
var sandbox, evictStub, evictedKeys;

before(function (done) {
evictedKeys = [];
sandbox = sinon.sandbox.create();

evictStub = sandbox.stub(ds, '_evict', function (key, callback) {
evictedKeys.push(key);
callback();
});

instanceResource.href = '32a0c55b-9fad-4aeb-8187-1149b4f980ce';
instanceResource.customData = {
href: instanceResource.href + '/ceb8c607-78ca-4cc0-872a-098e895ec1a5'
};

instanceResource.invalidate(done);
});

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

it('should invalidate the account and all of its child resources', function (done) {
assert.equal(evictedKeys.length, 2);
assert.equal(evictedKeys[0], instanceResource.href);
assert.equal(evictedKeys[1], instanceResource.customData.href);
done();
});
});
});
});

0 comments on commit 0c0341f

Please sign in to comment.