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 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;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user