Skip to content

Commit

Permalink
Tests(SCIMMY.Types.Filter): add missing branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sleelin committed Oct 17, 2024
1 parent 71af5cd commit bf9470e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib/types/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
}
}

Expand Down Expand Up @@ -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)]));
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/lib/types/filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit bf9470e

Please sign in to comment.