From 1cfab75d293ef2cf368cc323a00275dbb10f6f02 Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:17:39 -0700 Subject: [PATCH 1/4] add get path ids method --- lib/collection/item.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/collection/item.js b/lib/collection/item.js index 9186f0b75..90f211616 100644 --- a/lib/collection/item.js +++ b/lib/collection/item.js @@ -343,6 +343,21 @@ _.assign(Item.prototype, /** @lends Item.prototype */ { pushItem(this); this.forEachParent({ withRoot: true }, pushItem); + return path.reverse(); + }, + + /** + * Returns the path of the item using the item and parent ids + * + * @returns {Array} + */ + getPathIds: function () { + const path = [], + pushItem = (item) => { path.push(item.id); }; + + pushItem(this); + this.forEachParent({ withRoot: true }, pushItem); + return path.reverse(); } }); From 554f32d7e8e01801c18b47fecb1371e949aa1542 Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:28:21 -0700 Subject: [PATCH 2/4] Add getPathIds to return parent ids for an item --- lib/collection/item.js | 2 +- test/unit/item.test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/collection/item.js b/lib/collection/item.js index 90f211616..bf2e6c272 100644 --- a/lib/collection/item.js +++ b/lib/collection/item.js @@ -353,7 +353,7 @@ _.assign(Item.prototype, /** @lends Item.prototype */ { */ getPathIds: function () { const path = [], - pushItem = (item) => { path.push(item.id); }; + pushItem = (item) => { path.push(item.id ?? item._postman_id); }; pushItem(this); this.forEachParent({ withRoot: true }, pushItem); diff --git a/test/unit/item.test.js b/test/unit/item.test.js index ff9956d9d..667ba6c8b 100644 --- a/test/unit/item.test.js +++ b/test/unit/item.test.js @@ -240,6 +240,40 @@ describe('Item', function () { }); }); + describe('.getPathIds()', function () { + it('should return correct path for 1 level nested item', function () { + const collection = new sdk.Collection(fixtures.nestedCollectionV2), + req = collection.oneDeep('R1'); + + expect(req.getPathIds()).to.deep.equal([ + 'e5f2e9cf-173b-c60a-7336-ac804a87d762', + 'R1-id' + ]); + }); + + it('should return correct path for 2 level nested item', function () { + const collection = new sdk.Collection(fixtures.nestedCollectionV2), + req = collection.oneDeep('F1.R1'); + + expect(req.getPathIds()).to.deep.equal([ + 'e5f2e9cf-173b-c60a-7336-ac804a87d762', + 'F1-id', + 'F1.R1-id' + ]); + }); + + it('should return correct path for 3 level nested item', function () { + const collection = new sdk.Collection(fixtures.nestedCollectionV2), + req = collection.oneDeep('F2.F3.R1'); + + expect(req.getPathIds()).to.deep.equal([ + 'e5f2e9cf-173b-c60a-7336-ac804a87d762', + 'F2-id', + 'F2.F3-id', + 'F2.F3.R1-id' + ]); + }); + }); describe('.getAuth()', function () { var item, From 42744782e6fa4e2ed4eb88f6708a77518eb6f6b8 Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:37:07 -0700 Subject: [PATCH 3/4] change operator --- lib/collection/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/collection/item.js b/lib/collection/item.js index bf2e6c272..562b0e725 100644 --- a/lib/collection/item.js +++ b/lib/collection/item.js @@ -353,7 +353,7 @@ _.assign(Item.prototype, /** @lends Item.prototype */ { */ getPathIds: function () { const path = [], - pushItem = (item) => { path.push(item.id ?? item._postman_id); }; + pushItem = (item) => { path.push(item.id || item._postman_id); }; pushItem(this); this.forEachParent({ withRoot: true }, pushItem); From 59c9b4f8e747b43c4b42f8e355ce86df81aca701 Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:50:54 -0700 Subject: [PATCH 4/4] remove _postman_id --- lib/collection/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/collection/item.js b/lib/collection/item.js index 562b0e725..90f211616 100644 --- a/lib/collection/item.js +++ b/lib/collection/item.js @@ -353,7 +353,7 @@ _.assign(Item.prototype, /** @lends Item.prototype */ { */ getPathIds: function () { const path = [], - pushItem = (item) => { path.push(item.id || item._postman_id); }; + pushItem = (item) => { path.push(item.id); }; pushItem(this); this.forEachParent({ withRoot: true }, pushItem);