From 70c072be0bb07f63a0d66bcf91c3649b39179430 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 8 Aug 2016 13:18:40 -0700 Subject: [PATCH] [Persistence] Test more cases Add more test cases for TransactingMutationListener to distinguish active-transaction case from no-transaction case. --- .../runs/TransactingMutationListenerSpec.js | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/platform/core/test/runs/TransactingMutationListenerSpec.js b/platform/core/test/runs/TransactingMutationListenerSpec.js index d523b2ecd1..2529b04bce 100644 --- a/platform/core/test/runs/TransactingMutationListenerSpec.js +++ b/platform/core/test/runs/TransactingMutationListenerSpec.js @@ -72,39 +72,49 @@ define( .toHaveBeenCalledWith(jasmine.any(Function)); }); + [false, true].forEach(function (isActive) { + var verb = isActive ? "is": "isn't"; - describe("when mutation occurs during a transaction", function () { - beforeEach(function () { - mockTransactionService.isActive.andReturn(true); - mockMutationTopic.listen.mostRecentCall - .args[0](mockDomainObject); - }); + function onlyWhenInactive(expectation) { + return isActive ? expectation.not : expectation; + } - it("adds to the active transaction", function () { - expect(mockTransactionService.addToTransaction) - .toHaveBeenCalledWith( - jasmine.any(Function), - jasmine.any(Function) - ); + describe("when a transaction " + verb + " active", function () { + var innerVerb = isActive ? "does" : "doesn't"; + + beforeEach(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) - ); - }); - }); - }); } );