diff --git a/src/test/gitea.test.js b/src/test/gitea.test.js index 9d92158..b6a4748 100644 --- a/src/test/gitea.test.js +++ b/src/test/gitea.test.js @@ -1,7 +1,7 @@ import { describe, it, afterEach, mock } from 'node:test'; import assert from 'node:assert/strict'; import axios from 'axios'; -import { getPRDiff, filterDiff, postComment, postPullReviewComment, postPullReview, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome, listPullReviews, getPullReviewComments, listAllReviewComments, resolvePullReviewComment, getFileContentAtRef } from '../gitea.js'; +import { getPRDiff, filterDiff, parseReviewIgnore, getReviewIgnore, DEFAULT_REVIEW_IGNORE, postComment, postPullReviewComment, postPullReview, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome, listPullReviews, getPullReviewComments, listAllReviewComments, resolvePullReviewComment, getFileContentAtRef } from '../gitea.js'; afterEach(() => mock.restoreAll()); @@ -259,3 +259,31 @@ describe('filterDiff', () => { assert.ok(result.includes('src/main.js')); }); }); + +describe('parseReviewIgnore', () => { + it('parses prefixes, skipping blanks and comments', () => { + const text = '# comment\n\n.gitea/\n dist/ \n# another\nREADME.md\n'; + assert.deepEqual(parseReviewIgnore(text), ['.gitea/', 'dist/', 'README.md']); + }); + + it('returns an empty array for empty/nullish input', () => { + assert.deepEqual(parseReviewIgnore(''), []); + assert.deepEqual(parseReviewIgnore(null), []); + }); +}); + +describe('getReviewIgnore', () => { + it('uses patterns fetched from .reviewignore when present', async () => { + mock.method(axios, 'get', async () => ({ + data: { content: Buffer.from('a/\nb/\n# c\n').toString('base64'), encoding: 'base64' }, + })); + const patterns = await getReviewIgnore(); + assert.deepEqual(patterns, ['a/', 'b/']); + }); + + it('falls back to the default list when .reviewignore is missing/empty', async () => { + mock.method(axios, 'get', async () => ({ data: {} })); + const patterns = await getReviewIgnore(); + assert.deepEqual(patterns, DEFAULT_REVIEW_IGNORE); + }); +});