mirror of
https://github.com/nasa/openmct.git
synced 2025-04-24 21:10:05 +00:00
[Persistence] Test NestedTransaction
This commit is contained in:
parent
850da9de52
commit
2ebf05ae5b
@ -21,13 +21,58 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||||
|
|
||||||
define(
|
define(["../../src/services/NestedTransaction"], function (NestedTransaction) {
|
||||||
["../../src/services/NestedTransaction"],
|
var TRANSACTION_METHODS = ['add', 'commit', 'cancel', 'size'];
|
||||||
function (NestedTransaction) {
|
|
||||||
|
|
||||||
describe("A NestedTransaction", function () {
|
describe("A NestedTransaction", function () {
|
||||||
|
var mockTransaction,
|
||||||
|
nestedTransaction;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockTransaction =
|
||||||
|
jasmine.createSpyObj('transaction', TRANSACTION_METHODS);
|
||||||
|
nestedTransaction = new NestedTransaction(mockTransaction);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
);
|
it("exposes a Transaction's interface", function () {
|
||||||
|
TRANSACTION_METHODS.forEach(function (method) {
|
||||||
|
expect(nestedTransaction[method])
|
||||||
|
.toEqual(jasmine.any(Function));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when callbacks are added", function () {
|
||||||
|
var mockCommit,
|
||||||
|
mockCancel,
|
||||||
|
remove;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockCommit = jasmine.createSpy('commit');
|
||||||
|
mockCancel = jasmine.createSpy('cancel');
|
||||||
|
remove = nestedTransaction.add(mockCommit, mockCancel);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not interact with its parent transaction", function () {
|
||||||
|
TRANSACTION_METHODS.forEach(function (method) {
|
||||||
|
expect(mockTransaction[method])
|
||||||
|
.not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("and the transaction is committed", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
nestedTransaction.commit();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds to its parent transaction", function () {
|
||||||
|
expect(mockTransaction.add).toHaveBeenCalledWith(
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user