Skip to content

Commit

Permalink
Fix websocket match condition
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Aug 27, 2024
1 parent bc69078 commit d6bf7d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions sci-log-db/src/__tests__/unit/websocket.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ describe('Websocket unit tests', function (this: Suite) {
],
expected: false,
},
{
input: [
{tags: ['b', 'p'], snippetType: 'aType'},
{filter: {snippetType: []}},
],
expected: true,
},
{
input: [{tags: ['b', 'p'], snippetType: 'aType'}, {filter: {tags: []}}],
expected: true,
},
{
input: [
{tags: ['b', 'p'], snippetType: 'aType'},
{filter: {tags: [], snippetType: []}},
],
expected: true,
},
].forEach((t, i) => {
it(`Should test matchesFilterSettings ${i}`, () => {
expect(
Expand Down
6 changes: 4 additions & 2 deletions sci-log-db/src/utils/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ export function matchesFilterSettings(
): boolean {
const tagCondition =
!config.filter?.tags ||
config.filter?.tags?.some(tag => snippet.tags?.includes(tag));
config.filter.tags.length === 0 ||
config.filter.tags.some(tag => snippet.tags?.includes(tag));
const snippetTypeCondition =
!config.filter?.snippetType ||
config.filter?.snippetType?.includes(snippet.snippetType);
config.filter.snippetType.length === 0 ||
config.filter.snippetType.includes(snippet.snippetType);
return tagCondition && snippetTypeCondition;
}

0 comments on commit d6bf7d3

Please sign in to comment.