mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[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:
parent
e6d830bfdc
commit
8811f2a53e
@ -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;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user