From 75faa2c34f623c7a723ad93a2c509d298651aaae Mon Sep 17 00:00:00 2001 From: Bryan Ingle Date: Tue, 27 Jun 2023 20:58:38 -0600 Subject: [PATCH] Release. Bump version number --- package.json | 2 +- test/SpecRunner.js | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e354531..a70c3f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@barchart/common-js", - "version": "4.28.1", + "version": "4.29.0", "description": "Library of common JavaScript utilities", "author": { "name": "Bryan Ingle", diff --git a/test/SpecRunner.js b/test/SpecRunner.js index a308d38..a20d93d 100644 --- a/test/SpecRunner.js +++ b/test/SpecRunner.js @@ -9,8 +9,8 @@ module.exports = (() => { 'use strict'; /** - * Describes all of the reasons for API failure. Since there can be multiple reasons, the reasons are - * stored in a tree structure. + * Describes all of the reasons for API failure. Since there can be multiple + * reasons, the reasons are stored in a tree structure. * * @public * @param {Object=} data - Data regarding the API request itself, likely independent of the failure data (which is maintained in the tree structure). @@ -18,8 +18,8 @@ module.exports = (() => { class FailureReason { constructor(data) { this._data = data || null; - this._head = new Tree(); - this._current = this._head; + this._root = new Tree(); + this._current = this._root; } /** @@ -45,10 +45,18 @@ module.exports = (() => { * Resets the current node to the head of the tree. * * @public + * @param {Boolean=} previous * @returns {FailureReason} - The current instance, allowing for method chaining. */ - reset() { - this._current = this._head; + reset(previous) { + assert.argumentIsOptional(previous, 'previous', Boolean); + let node; + if (previous && this._current.getIsInner()) { + node = this._current.getParent(); + } else { + node = this._root; + } + this._current = node; return this; } @@ -59,7 +67,7 @@ module.exports = (() => { * @returns {Array} */ format() { - const reasons = this._head.toJSObj(item => { + const reasons = this._root.toJSObj(item => { const formatted = {}; formatted.code = item ? item.type.code : null; formatted.message = item ? item.format(this._data) : null; @@ -67,7 +75,7 @@ module.exports = (() => { formatted.data = item.data; } return formatted; - }); + }, true); return reasons.children; } @@ -81,7 +89,7 @@ module.exports = (() => { */ hasFailureType(type) { assert.argumentIsRequired(type, 'type', FailureType, 'FailureType'); - return this._head.search(item => item.type === type, false, false) !== null; + return this._root.search(item => item.type === type, false, false) !== null; } /** @@ -92,7 +100,7 @@ module.exports = (() => { * @returns {Boolean} */ getIsSevere() { - return this._head.search(item => item.type.severe, false, false) !== null; + return this._root.search(item => item.type.severe, false, false) !== null; } /** @@ -103,7 +111,7 @@ module.exports = (() => { * @returns {Number|null} */ getErrorCode() { - const node = this._head.search(item => item.type.error !== null, true, false); + const node = this._root.search(item => item.type.error !== null, true, false); if (node !== null) { return node.getValue().type.error; } else { @@ -150,7 +158,7 @@ module.exports = (() => { static getHttpStatusCode(reason) { assert.argumentIsRequired(reason, 'reason', FailureReason, 'FailureReason'); let returnVal = null; - reason._head.walk(item => { + reason._root.walk(item => { let code = FailureType.getHttpStatusCode(item.type); if (returnVal === null || returnVal !== 400) { returnVal = code;