[Core] Update existing specs
Update existing specs for changes from WTD-1033.
This commit is contained in:
@@ -21,14 +21,9 @@ define(
|
|||||||
// Pick a domain object model to use, favoring the one
|
// Pick a domain object model to use, favoring the one
|
||||||
// with the most recent timestamp
|
// with the most recent timestamp
|
||||||
function pick(a, b) {
|
function pick(a, b) {
|
||||||
if (!a) {
|
var aModified = (a || {}).modified || Number.NEGATIVE_INFINITY,
|
||||||
return b;
|
bModified = (b || {}).modified || Number.NEGATIVE_INFINITY;
|
||||||
}
|
return (aModified > bModified) ? a : (b || a);
|
||||||
if (!b) {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
return (a.modified || Number.NEGATIVE_INFINITY) >
|
|
||||||
(b.modified || Number.NEGATIVE_INFINITY) ? a : b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge results from multiple providers into one
|
// Merge results from multiple providers into one
|
||||||
|
|||||||
@@ -16,16 +16,30 @@ define(
|
|||||||
SPACE = "some space",
|
SPACE = "some space",
|
||||||
persistence;
|
persistence;
|
||||||
|
|
||||||
|
function asPromise(value) {
|
||||||
|
return (value || {}).then ? value : {
|
||||||
|
then: function (callback) {
|
||||||
|
return asPromise(callback(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockPersistenceService = jasmine.createSpyObj(
|
mockPersistenceService = jasmine.createSpyObj(
|
||||||
"persistenceService",
|
"persistenceService",
|
||||||
[ "updateObject" ]
|
[ "updateObject", "readObject" ]
|
||||||
);
|
);
|
||||||
mockDomainObject = {
|
mockDomainObject = {
|
||||||
getId: function () { return id; },
|
getId: function () { return id; },
|
||||||
getModel: function () { return model; },
|
getModel: function () { return model; },
|
||||||
useCapability: jasmine.createSpy()
|
useCapability: jasmine.createSpy()
|
||||||
};
|
};
|
||||||
|
// Simulate mutation capability
|
||||||
|
mockDomainObject.useCapability.andCallFake(function (capability, mutator) {
|
||||||
|
if (capability === 'mutation') {
|
||||||
|
model = mutator(model) || model;
|
||||||
|
}
|
||||||
|
});
|
||||||
persistence = new PersistenceCapability(
|
persistence = new PersistenceCapability(
|
||||||
mockPersistenceService,
|
mockPersistenceService,
|
||||||
SPACE,
|
SPACE,
|
||||||
@@ -50,6 +64,31 @@ define(
|
|||||||
expect(persistence.getSpace()).toEqual(SPACE);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -12,8 +12,8 @@ define(
|
|||||||
var mockQ,
|
var mockQ,
|
||||||
mockProviders,
|
mockProviders,
|
||||||
modelList = [
|
modelList = [
|
||||||
{ "a": { someKey: "some value" } },
|
{ "a": { someKey: "some value" }, "b": undefined },
|
||||||
{ "b": { someOtherKey: "some other value" } }
|
{ "b": { someOtherKey: "some other value" }, "a": undefined }
|
||||||
],
|
],
|
||||||
aggregator;
|
aggregator;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user