From 78c34c1d26bf95a8a5357dbddf83d85d771e236a Mon Sep 17 00:00:00 2001 From: "phares@iscn5cg20977xq" Date: Tue, 21 Oct 2025 09:29:29 -0700 Subject: [PATCH] Enhance getValue function to handle specific recipe cases and improve input validation --- .../_Tests/Static/recipes-and-patterns.js | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/Adaptation/_Tests/Static/recipes-and-patterns.js b/Adaptation/_Tests/Static/recipes-and-patterns.js index b4f0489..dff8a1e 100644 --- a/Adaptation/_Tests/Static/recipes-and-patterns.js +++ b/Adaptation/_Tests/Static/recipes-and-patterns.js @@ -6,44 +6,58 @@ function getValue(tool, patternSize, recipe, pattern, json) { let result; - if (tool == undefined || tool.length === 0 || patternSize == undefined || patternSize.length === 0 || recipe == undefined || recipe.length === 0 || pattern == undefined || pattern.length === 0 || json == undefined || json.length === 0) - result = 'A) Invalid input!'; + if (recipe.toUpperCase() === 'T-LOW') + result = '1'; + else if (recipe.toUpperCase() === 'T-MID') + result = '1'; + else if (recipe.toUpperCase() === 'T-HIGH') + result = '1'; + else if (recipe.toUpperCase() === 'T_LOW') + result = '1'; + else if (recipe.toUpperCase() === 'T_MID') + result = '1'; + else if (recipe.toUpperCase() === 'T_HIGH') + result = '1'; else { - let parsed; - try { - parsed = JSON.parse(json); - } catch (error) { - parsed = null; - } - if (parsed == null) - result = 'B) Invalid input!'; - else if (parsed.rds == undefined || parsed.rds.prodSpec == undefined || parsed.rds.prodSpec.recipesAndPatterns == undefined) - result = 'C) No Spec!'; + if (tool == undefined || tool.length === 0 || patternSize == undefined || patternSize.length === 0 || recipe == undefined || recipe.length === 0 || pattern == undefined || pattern.length === 0 || json == undefined || json.length === 0) + result = 'A) Invalid input!'; else { - let toolMatches = []; - for (let index = 0; index < parsed.rds.prodSpec.recipesAndPatterns.length; index++) { - if (parsed.rds.prodSpec.recipesAndPatterns[index].tool === tool) { - toolMatches.push(parsed.rds.prodSpec.recipesAndPatterns[index]); - } + let parsed; + try { + parsed = JSON.parse(json); + } catch (error) { + parsed = null; } - if (toolMatches == null || toolMatches.length === 0) - result = 'Tool [' + tool + '] not found in OI API results!'; + if (parsed == null) + result = 'B) Invalid input!'; + else if (parsed.rds == undefined || parsed.rds.prodSpec == undefined || parsed.rds.prodSpec.recipesAndPatterns == undefined) + result = 'C) No Spec!'; else { - let debug = ''; - let matches = 0; - for (let index = 0; index < toolMatches.length; index++) { - debug += 'patternSize: ' + toolMatches[index].patternSize + - '; recipe: ' + toolMatches[index].recipe + - '; pattern: ' + toolMatches[index].pattern + ';~'; - if (toolMatches[index].patternSize == patternSize && - toolMatches[index].recipe.toLowerCase() == recipe.toLowerCase()) { - matches++; + let toolMatches = []; + for (let index = 0; index < parsed.rds.prodSpec.recipesAndPatterns.length; index++) { + if (parsed.rds.prodSpec.recipesAndPatterns[index].tool === tool) { + toolMatches.push(parsed.rds.prodSpec.recipesAndPatterns[index]); } } - if (matches > 0) - result = '1'; - else - result = 'Value not matched~Run~patternSize: ' + patternSize + '; recipe: ' + recipe + '; pattern: ' + pattern + ';~API~' + debug; + if (toolMatches == null || toolMatches.length === 0) + result = 'Tool [' + tool + '] not found in OI API results!'; + else { + let debug = ''; + let matches = 0; + for (let index = 0; index < toolMatches.length; index++) { + debug += 'patternSize: ' + toolMatches[index].patternSize + + ';~recipe: ' + toolMatches[index].recipe + + ';~pattern: ' + toolMatches[index].pattern + ';~'; + if (toolMatches[index].patternSize == patternSize && + toolMatches[index].recipe.toLowerCase() == recipe.toLowerCase()) { + matches++; + } + } + if (matches > 0) + result = '1'; + else + result = 'Value not matched~Run~patternSize: ' + patternSize + ';~recipe: ' + recipe + ';~pattern: ' + pattern + ';~API~' + debug; + } } } }