[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 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; return CreationService;
} }
); );

View File

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