github/memex#899: Adds test coverage around owner types

This commit is contained in:
Shaun Kirk Wong
2022-03-25 21:32:04 +00:00
committed by GitHub
parent a113ff8a4a
commit 959b0d462b

View File

@@ -292,6 +292,96 @@ describe('addToProject', () => {
expect(infoSpy).not.toHaveBeenCalled() expect(infoSpy).not.toHaveBeenCalled()
expect(gqlMock).not.toHaveBeenCalled() expect(gqlMock).not.toHaveBeenCalled()
}) })
test('constructs the correct graphQL query given an organization owner', async () => {
mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token',
labeled: 'bug, new'
})
github.context.payload = {
issue: {
number: 1,
labels: [{name: 'bug'}]
}
}
const gqlMock = mockGraphQL(
{
test: /getProject/,
return: {
organization: {
projectNext: {
id: 'project-next-id'
}
}
}
},
{
test: /addProjectNextItem/,
return: {
addProjectNextItem: {
projectNextItem: {
id: 'project-next-item-id'
}
}
}
}
)
await addToProject()
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('organization(login: $ownerName)'), {
ownerName: 'github',
projectNumber: 1
})
})
test('constructs the correct graphQL query given a user owner', async () => {
mockGetInput({
'project-url': 'https://github.com/users/monalisa/projects/1',
'github-token': 'gh_token',
labeled: 'bug, new'
})
github.context.payload = {
issue: {
number: 1,
labels: [{name: 'bug'}]
}
}
const gqlMock = mockGraphQL(
{
test: /getProject/,
return: {
organization: {
projectNext: {
id: 'project-next-id'
}
}
}
},
{
test: /addProjectNextItem/,
return: {
addProjectNextItem: {
projectNextItem: {
id: 'project-next-item-id'
}
}
}
}
)
await addToProject()
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('user(login: $ownerName)'), {
ownerName: 'monalisa',
projectNumber: 1
})
})
}) })
function mockGetInput(mocks: Record<string, string>): jest.SpyInstance { function mockGetInput(mocks: Record<string, string>): jest.SpyInstance {