Skip to content

Commit

Permalink
Cover multiple cards comment scenario with test
Browse files Browse the repository at this point in the history
  • Loading branch information
ukupat committed Mar 23, 2024
1 parent 970784f commit 5fb4169
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,9 @@ describe('Adding card link to PR', () => {
const pr = basePR
const conf = { githubIncludePrBranchName: true }

beforeEach(() => {
it('adds link', async () => {
getBranchNameMock.mockResolvedValueOnce('1-card')
searchTrelloCardsMock.mockResolvedValueOnce([{ id: 'card' }])
})

it('adds link', async () => {
getCardInfoMock.mockResolvedValueOnce({ shortUrl: 'short-url' })

await run(pr, conf)
Expand All @@ -315,12 +312,34 @@ describe('Adding card link to PR', () => {
expect(createComment).toHaveBeenCalledWith('short-url')
})

it('adds multiple cards link', async () => {
getBranchNameMock.mockResolvedValue('1-2-card')
searchTrelloCardsMock
.mockResolvedValueOnce([{ id: '1-card', idShort: 1 }])
.mockResolvedValueOnce([{ id: '2-card', idShort: 2 }])
getCardInfoMock
.mockResolvedValueOnce({ shortUrl: '1-short-url' })
.mockResolvedValueOnce({ shortUrl: '2-short-url' })

await run(pr, { ...conf, githubAllowMultipleCardsInPrBranchName: true })

expect(getCardInfo).toHaveBeenNthCalledWith(1, '1-card')
expect(getCardInfo).toHaveBeenNthCalledWith(2, '2-card')
expect(createComment).toHaveBeenCalledWith('1-short-url\n2-short-url')
})

it('skips link adding when already in PR description', async () => {
getBranchNameMock.mockResolvedValueOnce('1-card')
searchTrelloCardsMock.mockResolvedValueOnce([{ id: 'card' }])

await run({ ...pr, body: 'https://trello.com/c/card/title' }, conf)

expect(createComment).not.toHaveBeenCalled()
})

it('skips link adding when already in PR comment', async () => {
getBranchNameMock.mockResolvedValueOnce('1-card')
searchTrelloCardsMock.mockResolvedValueOnce([{ id: 'card' }])
getPullRequestCommentsMock.mockResolvedValueOnce([{ body: 'https://trello.com/c/card/title' }])

await run(pr, conf)
Expand Down

0 comments on commit 5fb4169

Please sign in to comment.