Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions __tests__/issueCommentTest/assign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,48 @@ describe('/assign', () => {
expect((await observeReq.body()).assignees.sort()).toEqual(['other-user', 'some-user'])
})

it('assigns only the authorized subset when the arguments mix authorized and unknown users', async () => {
issueCommentEventAssign.comment.body = '/assign @some-user @stranger'

server.use(
http.get(
`${utils.api}/orgs/Codertocat/members/some-user`,
utils.mockResponse(204),
),
http.get(
`${utils.api}/orgs/Codertocat/members/stranger`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/collaborators/some-user`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/collaborators/stranger`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/comments`,
utils.mockResponse(404),
),
)

const observeReq = new utils.ObserveRequest()
server.use(
http.post(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/assignees`,
utils.mockResponse(201, issueAssignedResp, observeReq),
),
)

const commentContext = new utils.MockContext(issueCommentEventAssign)

await handleIssueComment(commentContext)
await observeReq.called()
// the write carries getOrgCollabCommentUsers' filtered list, not the raw arguments
expect(await observeReq.body()).toEqual({ assignees: ['some-user'] })
})

it('assigns users from every /assign line in the comment', async () => {
issueCommentEventAssign.comment.body = '/assign @some-user\nplease also take a look\n/assign @other-user'

Expand Down
42 changes: 42 additions & 0 deletions __tests__/issueCommentTest/cc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,48 @@ describe('/cc', () => {
expect((await observeReq.body()).reviewers.sort()).toEqual(['other-user', 'some-user'])
})

it('requests reviews from only the authorized subset when the arguments mix authorized and unknown users', async () => {
issueCommentEvent.comment.body = '/cc @some-user @stranger'

server.use(
http.get(
`${utils.api}/orgs/Codertocat/members/some-user`,
utils.mockResponse(204),
),
http.get(
`${utils.api}/orgs/Codertocat/members/stranger`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/collaborators/some-user`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/collaborators/stranger`,
utils.mockResponse(404),
),
http.get(
`${utils.api}/repos/Codertocat/Hello-World/issues/1/comments`,
utils.mockResponse(404),
),
)

const observeReq = new utils.ObserveRequest()
server.use(
http.post(
`${utils.api}/repos/Codertocat/Hello-World/pulls/1/requested_reviewers`,
utils.mockResponse(201, pullReviewRequested, observeReq),
),
)

const commentContext = new utils.MockContext(issueCommentEvent)

await handleIssueComment(commentContext)
await observeReq.called()
// the write carries getOrgCollabCommentUsers' filtered list, not the raw arguments
expect(await observeReq.body()).toEqual({ reviewers: ['some-user'] })
})

it('ccs user if they are an org member', async () => {
issueCommentEvent.comment.body = '/cc @some-user'

Expand Down
Loading