[Tests] Update Link Service Tests

This commit is contained in:
Pete Richards 2015-08-06 15:05:42 -07:00
parent 1d162888dd
commit 197ec0eb2c

View File

@ -28,7 +28,7 @@ define(
'../DomainObjectFactory',
'../ControlledPromise'
],
function (LinkService, domainObjectFactory) {
function (LinkService, domainObjectFactory, ControlledPromise) {
"use strict";
describe("LinkService", function () {
@ -51,7 +51,6 @@ define(
validate;
beforeEach(function () {
object = domainObjectFactory({
name: 'object'
});
@ -119,20 +118,29 @@ define(
describe("perform", function () {
var object,
linkedObject,
parentModel,
parentObject,
mutationPromise,
compositionPromise,
persistencePromise,
compositionCapability,
persistenceCapability;
beforeEach(function () {
mutationPromise = jasmine.createSpyObj(
'promise',
['then']
);
mutationPromise = new ControlledPromise();
compositionPromise = new ControlledPromise();
persistencePromise = new ControlledPromise();
persistenceCapability = jasmine.createSpyObj(
'persistenceCapability',
['persist']
);
persistenceCapability.persist.andReturn(persistencePromise);
compositionCapability = jasmine.createSpyObj(
'compositionCapability',
['invoke']
);
compositionCapability.invoke.andReturn(compositionPromise);
parentModel = {
composition: []
};
@ -146,7 +154,8 @@ define(
return mutationPromise;
}
},
persistence: persistenceCapability
persistence: persistenceCapability,
composition: compositionCapability
}
});
@ -155,7 +164,11 @@ define(
id: 'xyz'
});
parentObject.getCapability.andReturn(persistenceCapability);
linkedObject = domainObjectFactory({
name: 'object-link',
id: 'xyz'
});
});
@ -172,16 +185,22 @@ define(
it("persists parent", function () {
linkService.perform(object, parentObject);
expect(mutationPromise.then).toHaveBeenCalled();
mutationPromise.then.calls[0].args[0]();
mutationPromise.resolve();
expect(parentObject.getCapability)
.toHaveBeenCalledWith('persistence');
expect(persistenceCapability.persist).toHaveBeenCalled();
});
it("returns object representing new link", function () {
linkService.perform(object, parentObject);
var returnPromise, whenComplete;
returnPromise = linkService.perform(object, parentObject);
whenComplete = jasmine.createSpy('whenComplete');
returnPromise.then(whenComplete);
mutationPromise.resolve();
persistencePromise.resolve();
compositionPromise.resolve([linkedObject]);
expect(whenComplete).toHaveBeenCalledWith(linkedObject)
});
});
});