Skip to content

Commit

Permalink
fix(protocol-tag-utils): remove protocol if all tags are removed by n…
Browse files Browse the repository at this point in the history
…ame #1059
  • Loading branch information
TillaTheHun0 committed Oct 31, 2024
1 parent 56f5adf commit 6c756ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 2 additions & 6 deletions protocol-tag-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@ export const removeAll = (protocol, tags) => update(protocol, [], tags)
*/
export const removeAllByName = (protocol, name, tags) => {
const [start, end] = findProtocolBoundaries(protocol)(tags)

let [before, cur, after] = [tags.slice(0, start), tags.slice(start, end), tags.slice(end)]

cur = cur.filter(complement(byName(name)))

return [before, cur, after].flat(1)
const [before, cur, after] = [tags.slice(0, start), tags.slice(start, end), tags.slice(end)]
return [before, create(protocol, cur.filter(complement(byName(name)))), after].flat(1)
}

/**
Expand Down
11 changes: 11 additions & 0 deletions protocol-tag-utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ describe('suite', () => {
)
})

test('should remove protocol, if all tags are removed', () => {
assert.deepStrictEqual(
removeAllByName(
AO,
'Variant',
removeAllByName(AO, 'Type', TAGS)
),
[RAND, ZONE_TAGS].flat(1)
)
})

test('should do nothing', () => {
assert.deepStrictEqual(removeAllByName(AO, 'Foo', TAGS), TAGS)
assert.deepStrictEqual(removeAllByName(AO, 'Random', TAGS), TAGS)
Expand Down

0 comments on commit 6c756ec

Please sign in to comment.