[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

@@ -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;