Debugging test failures

This commit is contained in:
Andrew Henry
2015-11-02 08:44:08 -08:00
parent 4eaeea1e14
commit 6c4c53dde7
2 changed files with 39 additions and 22 deletions

View File

@ -88,10 +88,13 @@ define(
*/ */
function copy(originalObject, originalParent) { function copy(originalObject, originalParent) {
//Make a clone of the model of the object to be copied //Make a clone of the model of the object to be copied
var modelClone = makeClone(originalObject.getModel()); var modelClone = {
delete modelClone.composition; id: uuid(),
delete modelClone.location; model: makeClone(originalObject.getModel()),
modelClone.id = uuid(); persistenceSpace: originalParent.getCapability('persistence')
}
delete modelClone.model.composition;
delete modelClone.model.location;
return $q.when(originalObject.useCapability('composition')).then(function(composees){ return $q.when(originalObject.useCapability('composition')).then(function(composees){
return (composees || []).reduce(function(promise, composee){ return (composees || []).reduce(function(promise, composee){
//If the object is composed of other //If the object is composed of other
@ -101,18 +104,15 @@ define(
return copy(composee, originalObject).then(function(composeeClone){ return copy(composee, originalObject).then(function(composeeClone){
//Once copied, associate each cloned //Once copied, associate each cloned
// composee with its parent clone // composee with its parent clone
composeeClone.location = modelClone.id; composeeClone.model.location = modelClone.id;
modelClone.composition = modelClone.composition || []; modelClone.model.composition = modelClone.model.composition || [];
return modelClone.composition.push(composeeClone.id); return modelClone.model.composition.push(composeeClone.id);
}); });
});}, $q.when(undefined) });}, $q.when(undefined)
).then(function (){ ).then(function (){
//Add the clone to the list of clones that will //Add the clone to the list of clones that will
//be returned by this function //be returned by this function
clones.push({ clones.push(modelClone);
model: modelClone,
persistenceSpace: originalParent.getCapability('persistence')
});
return modelClone; return modelClone;
}); });
}); });
@ -136,11 +136,13 @@ define(
self = this; self = this;
return function(objectClones) { return function(objectClones) {
return self.$q.all(objectClones.map(function(clone, index){ return self.$q.all(objectClones.map(function(clone, index){
return self.persistenceService.createObject(clone.persistenceSpace, clone.model.id, clone.model) return self.persistenceService.createObject(clone.persistenceSpace, clone.id, clone.model)
.then(function(){ .then(function(){
progress && progress("copying", objectClones.length, ++persisted); progress && progress("copying", objectClones.length, ++persisted);
}); });
})).then(function(){ return objectClones}); })).then(function(qall){
return objectClones
});
} }
} }
@ -161,8 +163,8 @@ define(
parentClone.model.location = parent.getId(); parentClone.model.location = parent.getId();
return self.persistenceService return self.persistenceService
.updateObject(parentClone.persistenceSpace, parentClone.model.id, parentClone.model) .updateObject(parentClone.persistenceSpace, parentClone.id, parentClone.model)
.then(function(){return parent.getCapability('composition').add(parentClone.model.id)}) .then(function(){return parent.getCapability('composition').add(parentClone.id)})
.then(function(){return parent.getCapability("persistence").persist()}); .then(function(){return parent.getCapability("persistence").persist()});
} }
} }

View File

@ -125,10 +125,12 @@ define(
creationService, creationService,
createObjectPromise, createObjectPromise,
copyService, copyService,
mockPersistenceService,
object, object,
newParent, newParent,
copyResult, copyResult,
copyFinished; copyFinished,
persistObjectPromise;
beforeEach(function () { beforeEach(function () {
creationService = jasmine.createSpyObj( creationService = jasmine.createSpyObj(
@ -138,6 +140,13 @@ define(
createObjectPromise = synchronousPromise(undefined); createObjectPromise = synchronousPromise(undefined);
creationService.createObject.andReturn(createObjectPromise); creationService.createObject.andReturn(createObjectPromise);
policyService.allow.andReturn(true); policyService.allow.andReturn(true);
mockPersistenceService = jasmine.createSpyObj(
'persistenceService',
['createObject']
);
persistObjectPromise = synchronousPromise(undefined);
mockPersistenceService.createObject.andReturn(persistObjectPromise);
}); });
describe("on domain object without composition", function () { describe("on domain object without composition", function () {
@ -156,26 +165,32 @@ define(
composition: [] composition: []
} }
}); });
copyService = new CopyService(null, creationService, policyService); mockQ = jasmine.createSpyObj('mockQ', ['when', 'all', 'reject']);
mockQ.when.andCallFake(synchronousPromise);
mockQ.all.andCallFake(synchronousPromise);
copyService = new CopyService(mockQ, creationService, policyService, mockPersistenceService);
copyResult = copyService.perform(object, newParent); copyResult = copyService.perform(object, newParent);
copyFinished = jasmine.createSpy('copyFinished'); copyFinished = jasmine.createSpy('copyFinished');
copyResult.then(copyFinished); copyResult.then(copyFinished);
}); });
it("uses creation service", function () { /**
* Test invalidated. Copy service no longer uses creation service.
*/
/*it("uses creation service", function () {
expect(creationService.createObject) expect(creationService.createObject)
.toHaveBeenCalledWith(jasmine.any(Object), newParent); .toHaveBeenCalledWith(jasmine.any(Object), newParent);
expect(createObjectPromise.then) expect(createObjectPromise.then)
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
}); });*/
it("deep clones object model", function () { it("deep clones object model", function () {
var newModel = creationService //var newModel = creationService
var newModel = mockPersistenceService
.createObject .createObject
.mostRecentCall .mostRecentCall
.args[0]; .args[2];
expect(newModel).toEqual(object.model); expect(newModel).toEqual(object.model);
expect(newModel).not.toBe(object.model); expect(newModel).not.toBe(object.model);
}); });