Skip to content

Commit

Permalink
Fix item's parent reference
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Dec 11, 2024
1 parent 24d6dc7 commit 8820ec4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
unreleased:
fixed bugs:
- >-
Fixed a bug where item's parent reference was missing from request and
response callback
7.43.0:
date: 2024-10-30
new features:
Expand Down
1 change: 1 addition & 0 deletions lib/runner/create-item-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = function (payload, defaults) {
// we clone item from the payload, so that we can make any changes we need there, without mutating the
// collection
context.item = new sdk.Item(payload.item.toJSON());
context.item.setParent(payload.item.parent());

// get a reference to the Auth instance from the item, so changes are synced back
context.auth = context.originalItem.getAuth();
Expand Down
2 changes: 2 additions & 0 deletions lib/runner/request-helpers-presend.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ module.exports = [
item = new sdk.Item({ request }),
originalItem = context.originalItem;

item.setParent(originalItem.parent());

// auth handler gave a no go, and an intermediate request.
// make the intermediate request the response is passed to `init` hook
// we are overriding the originalItem because in pre we have a entire new request
Expand Down
4 changes: 4 additions & 0 deletions lib/runner/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ module.exports = {

hasVaultSecrets = vaultValues ? vaultValues.count() > 0 : false,

itemParent = context.item.parent(),
urlObj = context.item.request.url,
// @note URL string is used to resolve nested variables as URL parser doesn't support them well.
urlString = urlObj.toString(),
Expand Down Expand Up @@ -310,6 +311,9 @@ module.exports = {
item = context.item = new sdk.Item(context.item.toObjectResolved(null,
variableDefinitions, { ignoreOwnVariables: true }));

// restore the parent reference
item.setParent(itemParent);

// re-parse and update the URL from the resolved string
urlString && (item.request.url = new sdk.Url(urlString));

Expand Down
8 changes: 8 additions & 0 deletions test/integration/sanity/response-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,13 @@ describe('response callback', function () {
// cursor
expect(testrun).to.have.nested.property('response.firstCall.args[1]').that.has.property('ref');
});

it('should have item\'s parent reference intact', function () {
const parent = testrun.beforeItem.firstCall.args[2].parent();

expect(testrun.request.firstCall.args[4].parent()).to.equal(parent);
expect(testrun.request.secondCall.args[4].parent()).to.equal(parent);
expect(testrun.response.firstCall.args[4].parent()).to.equal(parent);
});
});
});

0 comments on commit 8820ec4

Please sign in to comment.