[Creation] createObject returns newObject

createObject returns a promise which is resolved when the object
has been persisted.  The promise is resolved with an instance of the
new domainObject.
This commit is contained in:
larkin 2015-06-11 11:56:46 -07:00
parent e6d830bfdc
commit 8811f2a53e
2 changed files with 33 additions and 3 deletions

View File

@ -77,7 +77,19 @@ define(
return undefined;
}
return parentPersistence.persist();
return parentPersistence.persist().then(function () {
// Locate and return new Object in context of parent.
return parent
.useCapability('composition')
.then(function (children) {
var i;
for (i = 0; i < children.length; i += 1) {
if (children[i].getId() === id) {
return children[i];
}
}
});
});
});
}
@ -126,4 +138,4 @@ define(
return CreationService;
}
);
);

View File

@ -34,8 +34,10 @@ define(
mockQ,
mockLog,
mockParentObject,
mockNewObject,
mockMutationCapability,
mockPersistenceCapability,
mockCompositionCapability,
mockCapabilities,
creationService;
@ -69,6 +71,10 @@ define(
"parentObject",
[ "getId", "getCapability", "useCapability" ]
);
mockNewObject = jasmine.createSpyObj(
"newObject",
[ "getId" ]
);
mockMutationCapability = jasmine.createSpyObj(
"mutation",
[ "invoke" ]
@ -77,9 +83,14 @@ define(
"persistence",
[ "persist", "getSpace" ]
);
mockCompositionCapability = jasmine.createSpyObj(
"composition",
["invoke"]
);
mockCapabilities = {
mutation: mockMutationCapability,
persistence: mockPersistenceCapability
persistence: mockPersistenceCapability,
composition: mockCompositionCapability
};
mockPersistenceService.createObject.andReturn(
@ -93,8 +104,15 @@ define(
return mockCapabilities[key].invoke(value);
});
mockPersistenceCapability.persist.andReturn(
mockPromise(true)
);
mockMutationCapability.invoke.andReturn(mockPromise(true));
mockPersistenceCapability.getSpace.andReturn("testSpace");
mockCompositionCapability.invoke.andReturn(
mockPromise([mockNewObject])
);
creationService = new CreationService(
mockPersistenceService,