diff --git a/src/main.test.ts b/src/main.test.ts index cbdbd29..de10af7 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -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) @@ -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)