Added tests

This commit is contained in:
Henry
2016-05-12 14:20:16 -07:00
parent c305fba0a7
commit 69c4c3a2c8
7 changed files with 68 additions and 23 deletions

View File

@@ -55,6 +55,7 @@ define(
"transactionService",
[
"startTransaction",
"size",
"commit",
"cancel"
]
@@ -161,11 +162,9 @@ define(
});
it("returns true if the object has been modified since it" +
" was last persisted", function () {
model.modified = 0;
model.persisted = 0;
mockTransactionService.size.andReturn(0);
expect(capability.dirty()).toBe(false);
model.modified = 1;
mockTransactionService.size.andReturn(1);
expect(capability.dirty()).toBe(true);
});
});

View File

@@ -56,7 +56,8 @@ define(
"persistenceCapability",
["persist", "refresh"]
);
mockPersistence.persist.andReturn(fastPromise());
mockPersistence.refresh.andReturn(fastPromise());
capability = new TransactionalPersistenceCapability(mockQ, mockTransactionService, mockPersistence, mockDomainObject);
});
@@ -67,26 +68,26 @@ define(
expect(mockPersistence.persist).toHaveBeenCalled();
});
it("if transaction is active, persist call is queued", function() {
it("if transaction is active, persist and cancel calls are" +
" queued", function() {
mockTransactionService.isActive.andReturn(true);
capability.persist();
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
//Test that it was the persist call that was queued
mockTransactionService.addToTransaction.mostRecentCall.args[0]();
expect(mockPersistence.persist).toHaveBeenCalled();
});
it("if transaction is active, refresh call is queued as cancel" +
" function", function() {
mockTransactionService.isActive.andReturn(true);
capability.persist();
//Test that it was the persist call that was queued
mockTransactionService.addToTransaction.mostRecentCall.args[1]();
expect(mockPersistence.refresh).toHaveBeenCalled();
});
it("persist call is only added to transaction once", function() {
mockTransactionService.isActive.andReturn(true);
capability.persist();
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
capability.persist();
expect(mockTransactionService.addToTransaction.calls.length).toBe(1);
});
});
}
);