From 6996883b85d8ac4fd270e7c1f6485f4bb1a02c77 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 22 Sep 2015 15:42:39 -0700 Subject: [PATCH] [Entanglement] Update specs Update specs for move/copy/link services to account for re-validation at time an action is performed. nasa/openmctweb#98 --- .../src/actions/AbstractComposeAction.js | 3 +- .../test/services/CopyServiceSpec.js | 39 ++++++--- .../test/services/LinkServiceSpec.js | 2 +- .../test/services/MoveServiceSpec.js | 86 ++++++++++--------- 4 files changed, 76 insertions(+), 54 deletions(-) diff --git a/platform/entanglement/src/actions/AbstractComposeAction.js b/platform/entanglement/src/actions/AbstractComposeAction.js index 6d747bc764..f68391adc9 100644 --- a/platform/entanglement/src/actions/AbstractComposeAction.js +++ b/platform/entanglement/src/actions/AbstractComposeAction.js @@ -44,7 +44,8 @@ define( * @method platform/entanglement.AbstractComposeService#perform */ /** - * Check if one object can be composed into another. + * Check if this composition change is valid for these objects. + * * @param {DomainObject} domainObject the domain object to * move, copy, or link. * @param {DomainObject} parent the domain object whose composition diff --git a/platform/entanglement/test/services/CopyServiceSpec.js b/platform/entanglement/test/services/CopyServiceSpec.js index 6d7b1d5069..31c8dbccf4 100644 --- a/platform/entanglement/test/services/CopyServiceSpec.js +++ b/platform/entanglement/test/services/CopyServiceSpec.js @@ -41,19 +41,24 @@ define( } describe("CopyService", function () { + var policyService; + + beforeEach(function () { + policyService = jasmine.createSpyObj( + 'policyService', + ['allow'] + ); + policyService.allow.andReturn(true); + }); + describe("validate", function () { - var policyService, - copyService, + var copyService, object, parentCandidate, validate; beforeEach(function () { - policyService = jasmine.createSpyObj( - 'policyService', - ['allow'] - ); copyService = new CopyService( null, null, @@ -148,7 +153,7 @@ define( ); createObjectPromise = synchronousPromise(undefined); creationService.createObject.andReturn(createObjectPromise); - copyService = new CopyService(null, creationService); + copyService = new CopyService(null, creationService, policyService); copyResult = copyService.perform(object, newParent); copyFinished = jasmine.createSpy('copyFinished'); copyResult.then(copyFinished); @@ -180,7 +185,8 @@ define( }); describe("on domainObject with composition", function () { - var childObject, + var newObject, + childObject, compositionCapability, compositionPromise; @@ -216,6 +222,17 @@ define( composition: compositionCapability } }); + newObject = domainObjectFactory({ + name: 'object', + id: 'abc2', + model: { + name: 'some object', + composition: [] + }, + capabilities: { + composition: compositionCapability + } + }); newParent = domainObjectFactory({ name: 'newParent', id: '456', @@ -227,9 +244,11 @@ define( 'creationService', ['createObject'] ); - createObjectPromise = synchronousPromise(undefined); + policyService.allow.andReturn(true); + + createObjectPromise = synchronousPromise(newObject); creationService.createObject.andReturn(createObjectPromise); - copyService = new CopyService(mockQ, creationService); + copyService = new CopyService(mockQ, creationService, policyService); copyResult = copyService.perform(object, newParent); copyFinished = jasmine.createSpy('copyFinished'); copyResult.then(copyFinished); diff --git a/platform/entanglement/test/services/LinkServiceSpec.js b/platform/entanglement/test/services/LinkServiceSpec.js index 69c6ebd48c..5a92119e81 100644 --- a/platform/entanglement/test/services/LinkServiceSpec.js +++ b/platform/entanglement/test/services/LinkServiceSpec.js @@ -41,6 +41,7 @@ define( 'policyService', ['allow'] ); + mockPolicyService.allow.andReturn(true); linkService = new LinkService(mockPolicyService); }); @@ -66,7 +67,6 @@ define( validate = function () { return linkService.validate(object, parentCandidate); }; - mockPolicyService.allow.andReturn(true); }); it("does not allow invalid parentCandidate", function () { diff --git a/platform/entanglement/test/services/MoveServiceSpec.js b/platform/entanglement/test/services/MoveServiceSpec.js index 02494a0afb..16eaa9dcbf 100644 --- a/platform/entanglement/test/services/MoveServiceSpec.js +++ b/platform/entanglement/test/services/MoveServiceSpec.js @@ -40,58 +40,57 @@ define( var moveService, policyService, + object, + objectContextCapability, + currentParent, + parentCandidate, linkService; beforeEach(function () { + objectContextCapability = jasmine.createSpyObj( + 'objectContextCapability', + [ + 'getParent' + ] + ); + + object = domainObjectFactory({ + name: 'object', + id: 'a', + capabilities: { + context: objectContextCapability, + type: { type: 'object' } + } + }); + + currentParent = domainObjectFactory({ + name: 'currentParent', + id: 'b' + }); + + objectContextCapability.getParent.andReturn(currentParent); + + parentCandidate = domainObjectFactory({ + name: 'parentCandidate', + model: { composition: [] }, + id: 'c', + capabilities: { + type: { type: 'parentCandidate' } + } + }); policyService = jasmine.createSpyObj( 'policyService', ['allow'] ); linkService = new MockLinkService(); + policyService.allow.andReturn(true); moveService = new MoveService(policyService, linkService); }); describe("validate", function () { - var object, - objectContextCapability, - currentParent, - parentCandidate, - validate; + var validate; beforeEach(function () { - - objectContextCapability = jasmine.createSpyObj( - 'objectContextCapability', - [ - 'getParent' - ] - ); - - object = domainObjectFactory({ - name: 'object', - id: 'a', - capabilities: { - context: objectContextCapability, - type: { type: 'object' } - } - }); - - currentParent = domainObjectFactory({ - name: 'currentParent', - id: 'b' - }); - - objectContextCapability.getParent.andReturn(currentParent); - - parentCandidate = domainObjectFactory({ - name: 'parentCandidate', - model: { composition: [] }, - id: 'c', - capabilities: { - type: { type: 'parentCandidate' } - } - }); - validate = function () { return moveService.validate(object, parentCandidate); }; @@ -145,14 +144,15 @@ define( describe("perform", function () { - var object, - newParent, - actionCapability, + var actionCapability, locationCapability, locationPromise, + newParent, moveResult; beforeEach(function () { + newParent = parentCandidate; + actionCapability = jasmine.createSpyObj( 'actionCapability', ['perform'] @@ -175,7 +175,9 @@ define( name: 'object', capabilities: { action: actionCapability, - location: locationCapability + location: locationCapability, + context: objectContextCapability, + type: { type: 'object' } } });