Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions __tests__/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,49 @@ describe('dist/index.js', () => {
])
})

it('issue_comment /assign with argument users assigns the org member and drops the stranger', async () => {
gh.route('GET', '/orgs/Codertocat/members/octocat', { status: 204 })
gh.route('GET', `${repo}/collaborators/octocat`, { status: 404, body: { message: 'Not Found' } })
gh.route('GET', '/orgs/Codertocat/members/stranger', { status: 404, body: { message: 'Not Found' } })
gh.route('GET', `${repo}/collaborators/stranger`, { status: 404, body: { message: 'Not Found' } })
gh.route('GET', `${repo}/issues/1/comments`, { status: 200, body: [] })
gh.route('POST', `${repo}/issues/1/assignees`, { status: 201, body: {} })

const result = await runBundle({
eventName: 'issue_comment',
payload: comment('/assign @octocat @stranger'),
inputs: { ...token, 'prow-commands': '/assign' },
apiUrl: gh.url,
})

expect(result.status, result.stdout).toBe(0)
expect(result.errors).toEqual([])
// the argument users' authorization reads are the /cc cases' ground; here only the write matters
expect(gh.requestsMatching('POST', /./).map(r => [r.path, r.body])).toEqual([[`${repo}/issues/1/assignees`, { assignees: ['octocat'] }]])
})

it('issue_comment /milestone sets the milestone whose title matches the argument', async () => {
gh.route('GET', `${repo}/collaborators/Codertocat`, { status: 204 })
gh.route('GET', `${repo}/milestones`, { status: 200, body: [{ number: 3, title: 'v1.0' }, { number: 7, title: 'Sprint 2' }] })
gh.route('PATCH', `${repo}/issues/1`, { status: 200, body: {} })

const result = await runBundle({
eventName: 'issue_comment',
payload: comment('/milestone Sprint 2'),
inputs: { ...token, 'prow-commands': '/milestone' },
apiUrl: gh.url,
})

expect(result.status, result.stdout).toBe(0)
expect(result.errors).toEqual([])
expect(gh.requests.map(r => `${r.method} ${r.path}`)).toEqual([
`GET ${repo}/collaborators/Codertocat`,
`GET ${repo}/milestones`,
`PATCH ${repo}/issues/1`,
])
expect(gh.requestsMatching('PATCH', /\/issues\/1$/)[0].body).toEqual({ milestone: 7 })
})

it('issue_comment /milestone clear unsets the milestone for a collaborator', async () => {
gh.route('GET', `${repo}/collaborators/Codertocat`, { status: 204 })
gh.route('PATCH', `${repo}/issues/1`, { status: 200, body: {} })
Expand Down
Loading