Skip to content

Commit

Permalink
test whether GraphQLQueryErrors will still handle pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvanderlinden committed Dec 5, 2018
1 parent c24033a commit ba2595b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
65 changes: 64 additions & 1 deletion test/integration.test.ts
Expand Up @@ -11,11 +11,13 @@ import {
createGetContents,
createCheckSuiteCompletedEvent,
createCheckRunCreatedEvent,
createCommitsWithCheckSuiteWithCheckRun
createCommitsWithCheckSuiteWithCheckRun,
createPullRequestQuery
} from './mock'
import { immediate } from '../src/delay'
import appFn from '../src/index'
import { CommentAuthorAssociation } from '../src/models'
import { GraphQLQueryError } from 'probot/lib/github'
it('full happy path', async () => {
const config = `
minApprovals:
Expand Down Expand Up @@ -297,6 +299,67 @@ it('to report error when processing pull request results in error', async () =>
expect(consoleError).toHaveBeenCalled()
})

it('to report error and continue when graphql query contained errors', async () => {
const Raven = require('raven')
const captureException = jest.fn()
Raven.captureException = captureException
const consoleError = jest.fn()
console.error = consoleError

const config = `
minApprovals:
OWNER: 1
`

const pullRequestInfo = createPullRequestInfo({
reviews: {
nodes: [
approvedReview({
authorAssociation: CommentAuthorAssociation.OWNER
})
]
},
commits: createCommitsWithCheckSuiteWithCheckRun({
checkRun: successCheckRun
})
})

const pullRequestQuery = createPullRequestQuery(pullRequestInfo)

const github = createGithubApi({
repos: {
getContents: createGetContents({
'.github/auto-merge.yml': () => Buffer.from(config)
})
},
pullRequests: {
merge: jest.fn()
},
query: jest.fn(async () => Promise.reject(
new GraphQLQueryError([{
message: 'Some problem'
}], '', {}, pullRequestQuery)
))
})

const app = createApplication({
appFn,
logger: createEmptyLogger(),
github
})

await app.receive(
createPullRequestOpenedEvent({
owner: 'bobvanderlinden',
repo: 'probot-auto-merge',
number: 1
})
)

expect(captureException).toHaveBeenCalledTimes(1)
expect(github.pullRequests.merge).toHaveBeenCalled()
})

it('when no permission to source repository throw a no permission error', async () => {
const Raven = require('raven')
const captureException = jest.fn()
Expand Down
16 changes: 10 additions & 6 deletions test/mock.ts
Expand Up @@ -355,16 +355,20 @@ export function createGithubApiFromPullRequestInfo (opts: {
return createGithubApi(createPartialGithubApiFromPullRequestInfo(opts))
}

function createPartialGithubApiFromPullRequestInfo (opts: {
pullRequestInfo: PullRequestInfo,
config: string
}): DeepPartial<GitHubAPI> {
const pullRequestQueryResult: PullRequestQuery = {
export function createPullRequestQuery (pullRequestInfo: PullRequestInfo): PullRequestQuery {
return {
repository: {
__typename: 'Repository',
pullRequest: opts.pullRequestInfo as any
pullRequest: pullRequestInfo as any
}
}
}

function createPartialGithubApiFromPullRequestInfo (opts: {
pullRequestInfo: PullRequestInfo,
config: string
}): DeepPartial<GitHubAPI> {
const pullRequestQueryResult = createPullRequestQuery(opts.pullRequestInfo)
return {
query: jest.fn(() => {
return pullRequestQueryResult
Expand Down

0 comments on commit ba2595b

Please sign in to comment.