From bf9470e812c35098c7fadb85bed1ee1440a267de Mon Sep 17 00:00:00 2001 From: Sam Lee-Lindsay Date: Thu, 17 Oct 2024 16:45:43 +1100 Subject: [PATCH] Tests(SCIMMY.Types.Filter): add missing branch coverage --- src/lib/types/filter.js | 9 +++++---- test/lib/types/filter.json | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/lib/types/filter.js b/src/lib/types/filter.js index 16987bb..ff486e2 100644 --- a/src/lib/types/filter.js +++ b/src/lib/types/filter.js @@ -721,9 +721,10 @@ export class Filter extends Array { })); // If there was a filter, some comparator, and no chained attribute name... - if (parts.indexOf(part) === parts.length - 1 && comparator !== undefined) + if (parts.indexOf(part) === parts.length - 1 && comparator !== undefined) { // ...add the expression as a branch I guess? - for (let branch of branches) branch.push([negative?.value, spent.join("."), comparator?.value, value?.value]); + for (let branch of branches) branch.push([negative?.value, spent.join("."), comparator.value, value?.value]); + } if (!results.length) { // Extract results from the filter @@ -741,7 +742,7 @@ export class Filter extends Array { } // No filter, but if we're at the end of the chain, join the last expression with the results else if (parts.indexOf(part) === parts.length - 1) { - for (let result of results) result.push([negative?.value, spent.join("."), comparator?.value, value?.value]); + for (let result of results) result.push([negative?.value, spent.join("."), comparator.value, value?.value]); } } @@ -791,7 +792,7 @@ export class Filter extends Array { // Push all expressions to results, objectifying if necessary for (let expression of expressions) { - results.push(...(Array.isArray(query) ? (expression.every(t => Array.isArray(t)) ? expression : [expression]) : [Filter.#objectify(expression)])); + results.push(...(Array.isArray(query) && expression.every(Array.isArray) ? expression : [Filter.#objectify(expression)])); } } diff --git a/test/lib/types/filter.json b/test/lib/types/filter.json index 7be205d..9a801db 100644 --- a/test/lib/types/filter.json +++ b/test/lib/types/filter.json @@ -118,12 +118,36 @@ {"emails": [{"type": ["eq", "work"]}, ["pr"]]} ] }, + { + "source": "emails[type eq \"work\"].value pr", + "target": [ + {"emails": {"type": ["eq", "work"]}, "value": ["pr"]} + ] + }, { "source": "emails[not type eq \"work\"] pr", "target": [ {"emails": [{"type": ["not", "eq", "work"]}, ["pr"]]} ] }, + { + "source": "emails[type eq \"work\"] co \"A\"", + "target": [ + {"emails": [{"type": ["eq", "work"]}, ["co", "A"]]} + ] + }, + { + "source": "emails[not type eq \"work\"] co \"A\"", + "target": [ + {"emails": [{"type": ["not", "eq", "work"]}, ["co", "A"]]} + ] + }, + { + "source": "not emails[not type eq \"work\"] co \"A\"", + "target": [ + {"emails": [{"type": ["not", "eq", "work"]}, ["not", "co", "A"]]} + ] + }, { "source": "userType eq \"Employee\" and emails[type eq \"work\" or primary eq true]", "target": [