mirror of
https://github.com/nasa/openmct.git
synced 2025-05-11 13:03:03 +00:00
[Persistence] Cover TransactingMutationListener
Add test cases sufficient for line coverage of TransactingMutationListener.
This commit is contained in:
parent
02f34d1c04
commit
eb2fbcd8d0
@ -27,7 +27,9 @@ define(
|
|||||||
describe("TransactingMutationListener", function () {
|
describe("TransactingMutationListener", function () {
|
||||||
var mockTopic,
|
var mockTopic,
|
||||||
mockMutationTopic,
|
mockMutationTopic,
|
||||||
mockTransactionService;
|
mockTransactionService,
|
||||||
|
mockDomainObject,
|
||||||
|
mockPersistence;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockTopic = jasmine.createSpy('topic');
|
mockTopic = jasmine.createSpy('topic');
|
||||||
@ -40,11 +42,24 @@ define(
|
|||||||
'addToTransaction',
|
'addToTransaction',
|
||||||
'commit'
|
'commit'
|
||||||
]);
|
]);
|
||||||
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
|
'domainObject',
|
||||||
|
['getId', 'getCapability', 'getModel']
|
||||||
|
);
|
||||||
|
mockPersistence = jasmine.createSpyObj(
|
||||||
|
'persistence',
|
||||||
|
['persist', 'refresh', 'persisted']
|
||||||
|
);
|
||||||
|
|
||||||
mockTopic.andCallFake(function (t) {
|
mockTopic.andCallFake(function (t) {
|
||||||
return (t === 'mutation') && mockMutationTopic;
|
return (t === 'mutation') && mockMutationTopic;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||||
|
return (c === 'persistence') && mockPersistence;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockPersistence.persisted.andReturn(true);
|
||||||
|
|
||||||
return new TransactingMutationListener(
|
return new TransactingMutationListener(
|
||||||
mockTopic,
|
mockTopic,
|
||||||
@ -58,6 +73,38 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("when mutation occurs during a transaction", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockTransactionService.isActive.andReturn(true);
|
||||||
|
mockMutationTopic.listen.mostRecentCall
|
||||||
|
.args[0](mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds to the active transaction", function () {
|
||||||
|
expect(mockTransactionService.addToTransaction)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when mutation occurs outside a transaction", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockTransactionService.isActive.andReturn(false);
|
||||||
|
mockMutationTopic.listen.mostRecentCall
|
||||||
|
.args[0](mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds to the active transaction", function () {
|
||||||
|
expect(mockTransactionService.addToTransaction)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user