[Entanglement] Update test cases around error-throwing

...per code review feedback, nasa/openmctweb#97
This commit is contained in:
Victor Woeltjen
2015-09-23 12:43:03 -07:00
parent 97892869ae
commit 6dbccd5000
3 changed files with 47 additions and 28 deletions

View File

@@ -131,6 +131,15 @@ define(
copyResult, copyResult,
copyFinished; copyFinished;
beforeEach(function () {
creationService = jasmine.createSpyObj(
'creationService',
['createObject']
);
createObjectPromise = synchronousPromise(undefined);
creationService.createObject.andReturn(createObjectPromise);
});
describe("on domain object without composition", function () { describe("on domain object without composition", function () {
beforeEach(function () { beforeEach(function () {
object = domainObjectFactory({ object = domainObjectFactory({
@@ -147,12 +156,6 @@ define(
composition: [] composition: []
} }
}); });
creationService = jasmine.createSpyObj(
'creationService',
['createObject']
);
createObjectPromise = synchronousPromise(undefined);
creationService.createObject.andReturn(createObjectPromise);
copyService = new CopyService(null, creationService, policyService); copyService = new CopyService(null, creationService, policyService);
copyResult = copyService.perform(object, newParent); copyResult = copyService.perform(object, newParent);
copyFinished = jasmine.createSpy('copyFinished'); copyFinished = jasmine.createSpy('copyFinished');
@@ -240,10 +243,6 @@ define(
composition: [] composition: []
} }
}); });
creationService = jasmine.createSpyObj(
'creationService',
['createObject']
);
policyService.allow.andReturn(true); policyService.allow.andReturn(true);
createObjectPromise = synchronousPromise(newObject); createObjectPromise = synchronousPromise(newObject);
@@ -285,18 +284,36 @@ define(
}); });
}); });
it("throws an expection when performed on invalid inputs", function () { describe("on invalid inputs", function () {
var copyService = beforeEach(function () {
new CopyService(mockQ, creationService, policyService); object = domainObjectFactory({
name: 'object',
capabilities: {
type: { type: 'object' }
}
});
newParent = domainObjectFactory({
name: 'parentCandidate',
capabilities: {
type: { type: 'parentCandidate' }
}
});
});
function perform() { it("throws an error", function () {
copyService.perform(object, newParent); var copyService =
} new CopyService(mockQ, creationService, policyService);
policyService.allow.andReturn(true); function perform() {
expect(perform).not.toThrow(); copyService.perform(object, newParent);
policyService.allow.andReturn(false); // Cause validate to fail }
expect(perform).toThrow();
spyOn(copyService, "validate");
copyService.validate.andReturn(true);
expect(perform).not.toThrow();
copyService.validate.andReturn(false);
expect(perform).toThrow();
});
}); });
}); });

View File

@@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global define,describe,beforeEach,it,jasmine,expect */ /*global define,describe,beforeEach,it,jasmine,expect,spyOn */
define( define(
[ [
@@ -221,14 +221,15 @@ define(
expect(whenComplete).toHaveBeenCalledWith(linkedObject); expect(whenComplete).toHaveBeenCalledWith(linkedObject);
}); });
it("throws an expection when performed on invalid inputs", function () { it("throws an error when performed on invalid inputs", function () {
function perform() { function perform() {
linkService.perform(object, parentObject); linkService.perform(object, parentObject);
} }
mockPolicyService.allow.andReturn(true); spyOn(linkService, 'validate');
linkService.validate.andReturn(true);
expect(perform).not.toThrow(); expect(perform).not.toThrow();
mockPolicyService.allow.andReturn(false); // Cause validate to fail linkService.validate.andReturn(false);
expect(perform).toThrow(); expect(perform).toThrow();
}); });
}); });

View File

@@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global define,describe,beforeEach,it,jasmine,expect */ /*global define,describe,beforeEach,it,jasmine,expect,spyOn */
define( define(
[ [
'../../src/services/MoveService', '../../src/services/MoveService',
@@ -196,14 +196,15 @@ define(
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
}); });
it("throws an expection when performed on invalid inputs", function () { it("throws an error when performed on invalid inputs", function () {
function perform() { function perform() {
moveService.perform(object, newParent); moveService.perform(object, newParent);
} }
policyService.allow.andReturn(true); spyOn(moveService, "validate");
moveService.validate.andReturn(true);
expect(perform).not.toThrow(); expect(perform).not.toThrow();
policyService.allow.andReturn(false); // Cause validate to fail moveService.validate.andReturn(false);
expect(perform).toThrow(); expect(perform).toThrow();
}); });