[Persistence] Test more cases

Add more test cases for TransactingMutationListener to
distinguish active-transaction case from no-transaction
case.
This commit is contained in:
Victor Woeltjen 2016-08-08 13:18:40 -07:00
parent eb2fbcd8d0
commit 70c072be0b

View File

@ -72,14 +72,33 @@ define(
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
}); });
[false, true].forEach(function (isActive) {
var verb = isActive ? "is": "isn't";
function onlyWhenInactive(expectation) {
return isActive ? expectation.not : expectation;
}
describe("when a transaction " + verb + " active", function () {
var innerVerb = isActive ? "does" : "doesn't";
describe("when mutation occurs during a transaction", function () {
beforeEach(function () { beforeEach(function () {
mockTransactionService.isActive.andReturn(true); mockTransactionService.isActive.andReturn(isActive);
});
describe("and mutation occurs", function () {
beforeEach(function () {
mockMutationTopic.listen.mostRecentCall mockMutationTopic.listen.mostRecentCall
.args[0](mockDomainObject); .args[0](mockDomainObject);
}); });
it(innerVerb + " start a new transaction", function () {
onlyWhenInactive(
expect(mockTransactionService.startTransaction)
).toHaveBeenCalled();
});
it("adds to the active transaction", function () { it("adds to the active transaction", function () {
expect(mockTransactionService.addToTransaction) expect(mockTransactionService.addToTransaction)
.toHaveBeenCalledWith( .toHaveBeenCalledWith(
@ -87,24 +106,15 @@ define(
jasmine.any(Function) jasmine.any(Function)
); );
}); });
});
describe("when mutation occurs outside a transaction", function () { it(innerVerb + " immediately commit", function () {
beforeEach(function () { onlyWhenInactive(
mockTransactionService.isActive.andReturn(false); expect(mockTransactionService.commit)
mockMutationTopic.listen.mostRecentCall ).toHaveBeenCalled();
.args[0](mockDomainObject); });
}); });
it("adds to the active transaction", function () {
expect(mockTransactionService.addToTransaction)
.toHaveBeenCalledWith(
jasmine.any(Function),
jasmine.any(Function)
);
}); });
}); });
}); });
} }
); );