[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);
mockCompositionCapability.invoke
.andReturn(mockPromise([mockDomainObject]));
return mockPromise(true);
return mockPromise(mockDomainObject);
});
// Should find it in the composition

View File

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

View File

@ -32,7 +32,9 @@ define(
describe("The persisted model provider", function () {
var mockQ,
mockPersistenceService,
SPACE = "some space",
SPACE = "space0",
spaces = [ "space1" ],
modTimes,
provider;
function mockPromise(value) {
@ -51,12 +53,14 @@ define(
}
beforeEach(function () {
modTimes = {};
mockQ = { when: mockPromise, all: mockAll };
mockPersistenceService = {
readObject: function (space, id) {
return mockPromise({
space: space,
id: id
id: id,
modified: (modTimes[space] || {})[id]
});
}
};
@ -64,7 +68,8 @@ define(
provider = new PersistedModelProvider(
mockPersistenceService,
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
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 parentObject.getCapability('persistence')
.persist()

View File

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