From 52416cd07245397448330ed13d39b9d4df659cf9 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Tue, 16 Jul 2019 12:21:01 +0200 Subject: [PATCH] Added support for arbitrary_key (#910) --- test/integration/test-runner.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/integration/test-runner.js b/test/integration/test-runner.js index eed24ea95..fecb93635 100644 --- a/test/integration/test-runner.js +++ b/test/integration/test-runner.js @@ -36,7 +36,8 @@ const supportedFeatures = [ 'groovy_scripting', 'headers', 'transform_and_set', - 'catch_unauthorized' + 'catch_unauthorized', + 'arbitrary_key' ] class TestRunner { @@ -429,7 +430,20 @@ class TestRunner { * @returns {TestRunner} */ set (key, name) { - this.stash.set(name, delve(this.response, key)) + if (key.includes('_arbitrary_key_')) { + var currentVisit = null + for (const path of key.split('.')) { + if (path === '_arbitrary_key_') { + const keys = Object.keys(currentVisit) + const arbitraryKey = keys[getRandomInt(0, keys.length)] + this.stash.set(name, arbitraryKey) + } else { + currentVisit = delve(this.response, path) + } + } + } else { + this.stash.set(name, delve(this.response, key)) + } return this } @@ -883,4 +897,8 @@ function getNumbers (val1, val2) { return [val1Numeric, val2Numeric] } +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min)) + min +} + module.exports = TestRunner