Skip to content

Commit

Permalink
Add tests passing, still need to potentially add more mock testing fo…
Browse files Browse the repository at this point in the history
…r GH but unsure.
  • Loading branch information
bordoni committed May 13, 2024
1 parent 5bdbefc commit ea164e8
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 678 deletions.
192 changes: 192 additions & 0 deletions __tests__/github/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,198 @@ describe('matchLabelConditions', () => {

expect(matchedLabelConditions).toEqual(false)
})

test('adds matching issues with a label filter without label-operator', async () => {
mockGetInput({
labeled: 'bug, new',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'bug',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})

test('adds matching issues with labels filter with AND label-operator', async () => {
mockGetInput({
labeled: 'bug, new',
'label-operator': 'AND',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'bug',
},
{
name: 'new',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})

test('does not add un-matching issues with labels filter with AND label-operator', async () => {
mockGetInput({
labeled: 'bug, new',
'label-operator': 'AND',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'bug',
},
{
name: 'other',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(false)
})

test('does not add matching issues with labels filter with NOT label-operator', async () => {
mockGetInput({
labeled: 'bug, new',
'label-operator': 'NOT',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'bug',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(false)
})

test('adds issues that do not have labels present in the label list with NOT label-operator', async () => {
mockGetInput({
labeled: 'bug, new',
'label-operator': 'NOT',
})
const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'other',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})

test('adds matching issues with multiple label filters', async () => {
mockGetInput({
labeled: 'accessibility,backend,bug',
})
const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'accessibility',
},
{
name: 'backend',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})

test('does not add un-matching issues with multiple label filters', async () => {
mockGetInput({
labeled: 'accessibility, backend, bug',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'data',
},
{
name: 'frontend',
},
{
name: 'improvement',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(false)
})

test('handles spaces and extra commas gracefully in label filter input', async () => {
mockGetInput({
labeled: 'accessibility , backend ,, , bug',
'label-operator': 'AND',
})

const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'accessibility',
},
{
name: 'backend',
},
{
name: 'bug',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})

test('compares labels case-insensitively', async () => {
mockGetInput({
labeled: 'FOO, Bar, baz',
'label-operator': 'AND',
})
const issue: GetLabelsParams = {
number: 1,
labels: [
{
name: 'foo',
},
{
name: 'BAR',
},
{
name: 'baZ',
},
],
}
const matchedLabelConditions = await matchLabelConditions(issue)

expect(matchedLabelConditions).toEqual(true)
})
})

function mockGetInput(mocks: Record<string, string>): jest.SpyInstance {
Expand Down
Loading

0 comments on commit ea164e8

Please sign in to comment.