[Composition] Update specs

Update specs for changes to the return value of
composition.add, nasa/openmctweb#97
This commit is contained in:
Victor Woeltjen 2015-09-02 11:45:52 -07:00
parent b1238b0c96
commit b2649de649
5 changed files with 34 additions and 20 deletions

View File

@ -161,7 +161,7 @@ define(
mockDomainObject.getId.andReturn(id); mockDomainObject.getId.andReturn(id);
mockCompositionCapability.invoke mockCompositionCapability.invoke
.andReturn(mockPromise([mockDomainObject])); .andReturn(mockPromise([mockDomainObject]));
return mockPromise(true); return mockPromise(mockDomainObject);
}); });
// Should find it in the composition // Should find it in the composition

View File

@ -52,10 +52,10 @@ define(
// Take the most recently modified model, for cases where // Take the most recently modified model, for cases where
// multiple persistence spaces return models. // multiple persistence spaces return models.
function takeMostRecent(modelA, modelB) { function takeMostRecent(modelA, modelB) {
return (!modelA || modelA.modified === undefined) ? modelB : return (!modelB || modelB.modified === undefined) ? modelA :
(!modelB || modelB.modified === undefined) ? modelA : (!modelA || modelA.modified === undefined) ? modelB :
modelA.modified > modelB.modified ? modelA : modelB.modified > modelA.modified ? modelB :
modelB; modelA;
} }
PersistedModelProvider.prototype.getModels = function (ids) { PersistedModelProvider.prototype.getModels = function (ids) {

View File

@ -32,7 +32,9 @@ define(
describe("The persisted model provider", function () { describe("The persisted model provider", function () {
var mockQ, var mockQ,
mockPersistenceService, mockPersistenceService,
SPACE = "some space", SPACE = "space0",
spaces = [ "space1" ],
modTimes,
provider; provider;
function mockPromise(value) { function mockPromise(value) {
@ -51,12 +53,14 @@ define(
} }
beforeEach(function () { beforeEach(function () {
modTimes = {};
mockQ = { when: mockPromise, all: mockAll }; mockQ = { when: mockPromise, all: mockAll };
mockPersistenceService = { mockPersistenceService = {
readObject: function (space, id) { readObject: function (space, id) {
return mockPromise({ return mockPromise({
space: space, space: space,
id: id id: id,
modified: (modTimes[space] || {})[id]
}); });
} }
}; };
@ -64,7 +68,8 @@ define(
provider = new PersistedModelProvider( provider = new PersistedModelProvider(
mockPersistenceService, mockPersistenceService,
mockQ, mockQ,
SPACE SPACE,
spaces
); );
}); });
@ -82,6 +87,24 @@ define(
}); });
}); });
it("reads object models from multiple spaces", function () {
var models;
modTimes.space1 = {
'x': 12321
};
provider.getModels(["a", "x", "zz"]).then(function (m) {
models = m;
});
expect(models).toEqual({
a: { space: SPACE, id: "a" },
x: { space: 'space1', id: "x", modified: 12321 },
zz: { space: SPACE, id: "zz" }
});
});
}); });
} }
); );

View File

@ -59,15 +59,6 @@ define(
// Note that this was checked-for explicitly during validate step // Note that this was checked-for explicitly during validate step
var composition = parentObject.getCapability('composition'); var composition = parentObject.getCapability('composition');
function findChild(children) {
var i;
for (i = 0; i < children.length; i += 1) {
if (children[i].getId() === object.getId()) {
return children[i];
}
}
}
return composition.add(object).then(function (result) { return composition.add(object).then(function (result) {
return parentObject.getCapability('persistence') return parentObject.getCapability('persistence')
.persist() .persist()

View File

@ -207,7 +207,7 @@ define(
it("persists parent", function () { it("persists parent", function () {
linkService.perform(object, parentObject); linkService.perform(object, parentObject);
expect(addPromise.then).toHaveBeenCalled(); expect(addPromise.then).toHaveBeenCalled();
addPromise.resolve(); addPromise.resolve(linkedObject);
expect(parentObject.getCapability) expect(parentObject.getCapability)
.toHaveBeenCalledWith('persistence'); .toHaveBeenCalledWith('persistence');
expect(persistenceCapability.persist).toHaveBeenCalled(); expect(persistenceCapability.persist).toHaveBeenCalled();
@ -219,7 +219,7 @@ define(
whenComplete = jasmine.createSpy('whenComplete'); whenComplete = jasmine.createSpy('whenComplete');
returnPromise.then(whenComplete); returnPromise.then(whenComplete);
addPromise.resolve(); addPromise.resolve(linkedObject);
persistencePromise.resolve(); persistencePromise.resolve();
compositionPromise.resolve([linkedObject]); compositionPromise.resolve([linkedObject]);
expect(whenComplete).toHaveBeenCalledWith(linkedObject); expect(whenComplete).toHaveBeenCalledWith(linkedObject);