test(ai-review review): 補上 Review 發布測試
This commit is contained in:
+27
-1
@@ -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, postPullReviewComment, postPullReview, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, getBotReviewOutcome } from './gitea.js';
|
||||
|
||||
afterEach(() => mock.restoreAll());
|
||||
|
||||
@@ -82,6 +82,32 @@ describe('gitea', () => {
|
||||
await assert.rejects(() => postPullReviewComment({ path: 'a.js', line: 1, body: 'x' }), /not in diff/);
|
||||
});
|
||||
|
||||
it('postPullReview posts one review with multiple comments', async () => {
|
||||
let capturedUrl, capturedBody, capturedOpts;
|
||||
mock.method(axios, 'post', async (url, body, opts) => {
|
||||
capturedUrl = url;
|
||||
capturedBody = body;
|
||||
capturedOpts = opts;
|
||||
return { data: { id: 9 } };
|
||||
});
|
||||
|
||||
const result = await postPullReview({
|
||||
body: 'summary',
|
||||
comments: [{ path: 'app/a.js', new_position: 10, body: 'comment' }],
|
||||
});
|
||||
|
||||
assert.deepEqual(result, { id: 9 });
|
||||
assert.ok(capturedUrl.includes('/api/v1/repos/'));
|
||||
assert.ok(capturedUrl.endsWith('/reviews'));
|
||||
assert.equal(capturedBody.event, 'COMMENT');
|
||||
assert.equal(capturedBody.body, 'summary');
|
||||
assert.equal(capturedBody.comments.length, 1);
|
||||
assert.equal(capturedBody.comments[0].path, 'app/a.js');
|
||||
assert.equal(capturedBody.comments[0].new_position, 10);
|
||||
assert.equal(capturedBody.comments[0].body, 'comment');
|
||||
assert.ok(capturedOpts.headers['Authorization'].startsWith('token '));
|
||||
});
|
||||
|
||||
it('getCommitMessageBySha reads commit message from Gitea API', async () => {
|
||||
let capturedUrl;
|
||||
mock.method(axios, 'get', async (url) => {
|
||||
|
||||
Reference in New Issue
Block a user