test(review 與 OpenCode TLS): 補齊 Pull Review 與 TLS 設定覆蓋

This commit is contained in:
2026-06-22 09:41:09 +00:00
parent 1477822f4b
commit 228d5ceb4a
4 changed files with 93 additions and 2 deletions
+19 -1
View File
@@ -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, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome } from './gitea.js';
import { getPRDiff, filterDiff, postComment, createPullReview, postPullReviewComment, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome } from './gitea.js';
afterEach(() => mock.restoreAll());
@@ -77,6 +77,24 @@ describe('gitea', () => {
assert.ok(capturedOpts.headers['Authorization'].startsWith('token '));
});
it('createPullReview posts body and comments in one pull review', async () => {
let capturedUrl, capturedBody;
mock.method(axios, 'post', async (url, body) => {
capturedUrl = url;
capturedBody = body;
return { data: { id: 8 } };
});
const result = await createPullReview({
body: 'review body',
comments: [{ path: 'app/a.js', body: 'inline', new_position: 3 }],
});
assert.deepEqual(result, { id: 8 });
assert.ok(capturedUrl.endsWith('/reviews'));
assert.equal(capturedBody.event, 'COMMENT');
assert.equal(capturedBody.body, 'review body');
assert.deepEqual(capturedBody.comments, [{ path: 'app/a.js', body: 'inline', new_position: 3 }]);
});
it('postPullReviewComment propagates axios errors', async () => {
mock.method(axios, 'post', async () => { throw new Error('not in diff'); });
await assert.rejects(() => postPullReviewComment({ path: 'a.js', line: 1, body: 'x' }), /not in diff/);