[Core] Update existing specs

Update existing specs for changes from WTD-1033.
This commit is contained in:
Victor Woeltjen 2015-03-24 16:43:50 -07:00
parent 35371f89ab
commit 6e2ec8dbe7
3 changed files with 45 additions and 11 deletions

View File

@ -21,14 +21,9 @@ define(
// Pick a domain object model to use, favoring the one
// with the most recent timestamp
function pick(a, b) {
if (!a) {
return b;
}
if (!b) {
return b;
}
return (a.modified || Number.NEGATIVE_INFINITY) >
(b.modified || Number.NEGATIVE_INFINITY) ? a : b;
var aModified = (a || {}).modified || Number.NEGATIVE_INFINITY,
bModified = (b || {}).modified || Number.NEGATIVE_INFINITY;
return (aModified > bModified) ? a : (b || a);
}
// Merge results from multiple providers into one

View File

@ -16,16 +16,30 @@ define(
SPACE = "some space",
persistence;
function asPromise(value) {
return (value || {}).then ? value : {
then: function (callback) {
return asPromise(callback(value));
}
};
}
beforeEach(function () {
mockPersistenceService = jasmine.createSpyObj(
"persistenceService",
[ "updateObject" ]
[ "updateObject", "readObject" ]
);
mockDomainObject = {
getId: function () { return id; },
getModel: function () { return model; },
useCapability: jasmine.createSpy()
};
// Simulate mutation capability
mockDomainObject.useCapability.andCallFake(function (capability, mutator) {
if (capability === 'mutation') {
model = mutator(model) || model;
}
});
persistence = new PersistenceCapability(
mockPersistenceService,
SPACE,
@ -50,6 +64,31 @@ define(
expect(persistence.getSpace()).toEqual(SPACE);
});
it("updates persisted timestamp on persistence", function () {
model.modified = 12321;
persistence.persist();
expect(model.persisted).toEqual(12321);
});
it("refreshes the domain object model from persistence", function () {
var refreshModel = { someOtherKey: "some other value" };
mockPersistenceService.readObject.andReturn(asPromise(refreshModel));
persistence.refresh();
expect(model).toEqual(refreshModel);
});
it("does not overwrite unpersisted changes on refresh", function () {
var refreshModel = { someOtherKey: "some other value" },
mockCallback = jasmine.createSpy();
model.modified = 2;
model.persisted = 1;
mockPersistenceService.readObject.andReturn(asPromise(refreshModel));
persistence.refresh().then(mockCallback);
expect(model).not.toEqual(refreshModel);
// Should have also indicated that no changes were actually made
expect(mockCallback).toHaveBeenCalledWith(false);
});
});
}
);

View File

@ -12,8 +12,8 @@ define(
var mockQ,
mockProviders,
modelList = [
{ "a": { someKey: "some value" } },
{ "b": { someOtherKey: "some other value" } }
{ "a": { someKey: "some value" }, "b": undefined },
{ "b": { someOtherKey: "some other value" }, "a": undefined }
],
aggregator;