diff --git a/src/plugins/TwoPhaseCommit/TwoPhaseCore.js b/src/plugins/TwoPhaseCommit/TwoPhaseCore.js index 406c3c493..02887504e 100644 --- a/src/plugins/TwoPhaseCommit/TwoPhaseCore.js +++ b/src/plugins/TwoPhaseCommit/TwoPhaseCore.js @@ -33,7 +33,6 @@ define([ passToCore('persist'); passToCore('loadRoot'); passToCore('loadSubTree'); - passToCore('getParent'); passToCore('getNamespace'); passToCore('getChildrenMeta'); passToCore('getChildrenPaths'); @@ -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) { diff --git a/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js b/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js index f2a417c07..7cd569204 100644 --- a/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js +++ b/test/unit/plugins/TwoPhaseCommit/TwoPhaseCore.spec.js @@ -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() {