|
| 1 | +import type { Issue } from './types' |
| 2 | +import { describe, expect, it } from 'bun:test' |
| 3 | +import { matchesFilter } from './filter' |
| 4 | + |
| 5 | +function makeIssue(overrides: Partial<Issue> = {}): Issue { |
| 6 | + return { |
| 7 | + id: 'i1', |
| 8 | + identifier: '#1', |
| 9 | + title: 'Test', |
| 10 | + description: null, |
| 11 | + priority: null, |
| 12 | + state: 'In Progress', |
| 13 | + branch_name: null, |
| 14 | + url: null, |
| 15 | + assignees: [], |
| 16 | + labels: [], |
| 17 | + blocked_by: [], |
| 18 | + created_at: null, |
| 19 | + updated_at: null, |
| 20 | + ...overrides, |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +describe('matchesFilter', () => { |
| 25 | + it('empty filter passes all issues', () => { |
| 26 | + const issue = makeIssue() |
| 27 | + expect(matchesFilter(issue, { assignee: [], label: [] })).toBe(true) |
| 28 | + }) |
| 29 | + |
| 30 | + it('assignee filter: matches when issue assignee is in list (OR)', () => { |
| 31 | + const issue = makeIssue({ assignees: ['user1'] }) |
| 32 | + expect(matchesFilter(issue, { assignee: ['user1', 'user2'], label: [] })).toBe(true) |
| 33 | + }) |
| 34 | + |
| 35 | + it('assignee filter: matches second item in list (OR)', () => { |
| 36 | + const issue = makeIssue({ assignees: ['user2'] }) |
| 37 | + expect(matchesFilter(issue, { assignee: ['user1', 'user2'], label: [] })).toBe(true) |
| 38 | + }) |
| 39 | + |
| 40 | + it('assignee filter: no match when assignee not in list', () => { |
| 41 | + const issue = makeIssue({ assignees: ['other'] }) |
| 42 | + expect(matchesFilter(issue, { assignee: ['user1', 'user2'], label: [] })).toBe(false) |
| 43 | + }) |
| 44 | + |
| 45 | + it('assignee filter: no match when issue has no assignee', () => { |
| 46 | + const issue = makeIssue({ assignees: [] }) |
| 47 | + expect(matchesFilter(issue, { assignee: ['user1'], label: [] })).toBe(false) |
| 48 | + }) |
| 49 | + |
| 50 | + it('assignee filter: case-insensitive matching', () => { |
| 51 | + const issue = makeIssue({ assignees: ['User1'] }) |
| 52 | + expect(matchesFilter(issue, { assignee: ['user1'], label: [] })).toBe(true) |
| 53 | + }) |
| 54 | + |
| 55 | + it('assignee filter: case-insensitive (filter uppercase, assignee lowercase)', () => { |
| 56 | + const issue = makeIssue({ assignees: ['alice'] }) |
| 57 | + expect(matchesFilter(issue, { assignee: ['Alice'], label: [] })).toBe(true) |
| 58 | + }) |
| 59 | + |
| 60 | + it('assignee filter: matches when any of multiple issue assignees is in filter list', () => { |
| 61 | + const issue = makeIssue({ assignees: ['alice', 'bob'] }) |
| 62 | + expect(matchesFilter(issue, { assignee: ['bob'], label: [] })).toBe(true) |
| 63 | + }) |
| 64 | + |
| 65 | + it('label filter: matches when issue has at least one matching label (OR)', () => { |
| 66 | + const issue = makeIssue({ labels: ['bug', 'urgent'] }) |
| 67 | + expect(matchesFilter(issue, { assignee: [], label: ['bug', 'feature'] })).toBe(true) |
| 68 | + }) |
| 69 | + |
| 70 | + it('label filter: matches second item in list (OR)', () => { |
| 71 | + const issue = makeIssue({ labels: ['feature'] }) |
| 72 | + expect(matchesFilter(issue, { assignee: [], label: ['bug', 'feature'] })).toBe(true) |
| 73 | + }) |
| 74 | + |
| 75 | + it('label filter: no match when issue has none of the required labels', () => { |
| 76 | + const issue = makeIssue({ labels: ['docs'] }) |
| 77 | + expect(matchesFilter(issue, { assignee: [], label: ['bug', 'feature'] })).toBe(false) |
| 78 | + }) |
| 79 | + |
| 80 | + it('label filter: no match when issue has no labels', () => { |
| 81 | + const issue = makeIssue({ labels: [] }) |
| 82 | + expect(matchesFilter(issue, { assignee: [], label: ['bug'] })).toBe(false) |
| 83 | + }) |
| 84 | + |
| 85 | + it('label filter: case-insensitive (filter uppercase, labels already lowercase)', () => { |
| 86 | + const issue = makeIssue({ labels: ['bug'] }) |
| 87 | + expect(matchesFilter(issue, { assignee: [], label: ['Bug'] })).toBe(true) |
| 88 | + }) |
| 89 | + |
| 90 | + it('label filter: case-insensitive (issue label uppercase, filter lowercase)', () => { |
| 91 | + const issue = makeIssue({ labels: ['Bug'] }) |
| 92 | + expect(matchesFilter(issue, { assignee: [], label: ['bug'] })).toBe(true) |
| 93 | + }) |
| 94 | + |
| 95 | + it('combined assignee + label: both must match (AND)', () => { |
| 96 | + const issue = makeIssue({ assignees: ['user1'], labels: ['bug'] }) |
| 97 | + expect(matchesFilter(issue, { assignee: ['user1'], label: ['bug'] })).toBe(true) |
| 98 | + }) |
| 99 | + |
| 100 | + it('combined: fails when assignee matches but label does not', () => { |
| 101 | + const issue = makeIssue({ assignees: ['user1'], labels: ['docs'] }) |
| 102 | + expect(matchesFilter(issue, { assignee: ['user1'], label: ['bug'] })).toBe(false) |
| 103 | + }) |
| 104 | + |
| 105 | + it('combined: fails when label matches but assignee does not', () => { |
| 106 | + const issue = makeIssue({ assignees: ['other'], labels: ['bug'] }) |
| 107 | + expect(matchesFilter(issue, { assignee: ['user1'], label: ['bug'] })).toBe(false) |
| 108 | + }) |
| 109 | +}) |
0 commit comments