Skip to content

Commit

Permalink
Add getParent, getAllMetaNodes to TwoPhaseCore. Closes #1953
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Oct 7, 2020
1 parent ed28746 commit 4e76bad
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/plugins/TwoPhaseCommit/TwoPhaseCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ define([
passToCore('persist');
passToCore('loadRoot');
passToCore('loadSubTree');
passToCore('getParent');
passToCore('getNamespace');
passToCore('getChildrenMeta');
passToCore('getChildrenPaths');
Expand All @@ -59,6 +58,23 @@ define([
}
};

TwoPhaseCore.prototype.getAllMetaNodes = function (node) {
ensureNode(node, 'getAllMetaNodes');
while (node instanceof CreatedNode) {
node = node.base;
}
return this.core.getAllMetaNodes(node);
};

TwoPhaseCore.prototype.getParent = function (node) {
ensureNode(node, 'getParent');
if (node instanceof CreatedNode) {
return node.parent;
} else {
return this.core.getParent(node);
}
};

TwoPhaseCore.prototype.getMetaType = function (node) {
ensureNode(node, 'getMetaType');
while (node instanceof CreatedNode) {
Expand Down
38 changes: 38 additions & 0 deletions test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,44 @@ describe('TwoPhaseCore', function() {
assert(names.includes('src'));
});
});

describe('getParent', function() {
it('should getParent of existing node', function() {
const {META, rootNode, core} = plugin;
const base = META.FCO;
const parent = core.getParent(base);

assert.equal(parent, rootNode);
});

it('should getParent of new node', function() {
const {META, rootNode, core} = plugin;
const {FCO} = META;
const parent = rootNode;
const newNode = core.createNode({base: FCO, parent});

assert.equal(core.getParent(newNode), parent);
});
});

describe('getAllMetaNodes', function() {
it('should getAllMetaNodes from existing node', function() {
const {META, core} = plugin;
const base = META.FCO;
const metaDict = core.getAllMetaNodes(base);

assert(metaDict);
});

it('should getAllMetaNodes from new node', function() {
const {META, rootNode, core} = plugin;
const {FCO} = META;
const parent = rootNode;
const newNode = core.createNode({base: FCO, parent});

assert(core.getAllMetaNodes(newNode));
});
});
});

describe('argument validation', function() {
Expand Down

0 comments on commit 4e76bad

Please sign in to comment.