mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Persistence] Test more cases
Add more test cases for TransactingMutationListener to distinguish active-transaction case from no-transaction case.
This commit is contained in:
parent
eb2fbcd8d0
commit
70c072be0b
@ -72,39 +72,49 @@ define(
|
|||||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[false, true].forEach(function (isActive) {
|
||||||
|
var verb = isActive ? "is": "isn't";
|
||||||
|
|
||||||
describe("when mutation occurs during a transaction", function () {
|
function onlyWhenInactive(expectation) {
|
||||||
beforeEach(function () {
|
return isActive ? expectation.not : expectation;
|
||||||
mockTransactionService.isActive.andReturn(true);
|
}
|
||||||
mockMutationTopic.listen.mostRecentCall
|
|
||||||
.args[0](mockDomainObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("adds to the active transaction", function () {
|
describe("when a transaction " + verb + " active", function () {
|
||||||
expect(mockTransactionService.addToTransaction)
|
var innerVerb = isActive ? "does" : "doesn't";
|
||||||
.toHaveBeenCalledWith(
|
|
||||||
jasmine.any(Function),
|
beforeEach(function () {
|
||||||
jasmine.any(Function)
|
mockTransactionService.isActive.andReturn(isActive);
|
||||||
);
|
});
|
||||||
|
|
||||||
|
describe("and mutation occurs", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockMutationTopic.listen.mostRecentCall
|
||||||
|
.args[0](mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it(innerVerb + " start a new transaction", function () {
|
||||||
|
onlyWhenInactive(
|
||||||
|
expect(mockTransactionService.startTransaction)
|
||||||
|
).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds to the active transaction", function () {
|
||||||
|
expect(mockTransactionService.addToTransaction)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(innerVerb + " immediately commit", function () {
|
||||||
|
onlyWhenInactive(
|
||||||
|
expect(mockTransactionService.commit)
|
||||||
|
).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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…
Reference in New Issue
Block a user