Add tests

This commit is contained in:
Abdelhamid
2022-03-23 12:34:46 +02:00
parent 0ad701a62e
commit dc9f7ee311

View File

@@ -52,11 +52,11 @@ describe('addToProject', () => {
expect(outputs.itemId).toEqual('project-next-item-id') expect(outputs.itemId).toEqual('project-next-item-id')
}) })
test('adds matching issues with a label filter', async () => { test('adds matching issues with a label filter without label-operator', async () => {
mockGetInput({ mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1', 'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token', 'github-token': 'gh_token',
labeled: 'bug' labeled: 'bug, new'
}) })
github.context.payload = { github.context.payload = {
@@ -94,7 +94,7 @@ describe('addToProject', () => {
expect(outputs.itemId).toEqual('project-next-item-id') expect(outputs.itemId).toEqual('project-next-item-id')
}) })
test('does not add un-matching issues with a label filter', async () => { test('does not add un-matching issues with a label filter without label-operator', async () => {
mockGetInput({ mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1', 'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token', 'github-token': 'gh_token',
@@ -114,6 +114,71 @@ describe('addToProject', () => {
expect(infoSpy).toHaveBeenCalledWith(`Skipping issue 1 because it does not have one of the labels: bug`) expect(infoSpy).toHaveBeenCalledWith(`Skipping issue 1 because it does not have one of the labels: bug`)
expect(gqlMock).not.toHaveBeenCalled() expect(gqlMock).not.toHaveBeenCalled()
}) })
test('adds matching issues with labels filter with AND label-operator', async () => {
mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token',
labeled: 'bug, new',
'label-operator': 'AND'
})
github.context.payload = {
issue: {
number: 1,
labels: [{name: 'bug'}, {name: 'new'}]
}
}
mockGraphQL(
{
test: /getProject/,
return: {
organization: {
projectNext: {
id: 'project-next-id'
}
}
}
},
{
test: /addProjectNextItem/,
return: {
addProjectNextItem: {
projectNextItem: {
id: 'project-next-item-id'
}
}
}
}
)
await addToProject()
expect(outputs.itemId).toEqual('project-next-item-id')
})
test('does not add un-matching issues with labels filter with AND label-operator', async () => {
mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token',
labeled: 'bug, new',
'label-operator': 'AND'
})
github.context.payload = {
issue: {
number: 1,
labels: [{name: 'bug'}, {name: 'other'}]
}
}
const infoSpy = jest.spyOn(core, 'info')
const gqlMock = mockGraphQL()
await addToProject()
expect(infoSpy).toHaveBeenCalledWith(`Skipping issue 1 because it doesn't match all the labels: bug, new`)
expect(gqlMock).not.toHaveBeenCalled()
})
}) })
function mockGetInput(mocks: Record<string, string>): jest.SpyInstance { function mockGetInput(mocks: Record<string, string>): jest.SpyInstance {