refactor: replace monolithic BitbucketClient with domain-client composition root
This commit is contained in:
@@ -2,68 +2,118 @@
|
||||
* Unit tests for BitbucketRouter
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { BitbucketRouter, ToolResult } from '../../src/router.js';
|
||||
|
||||
// Mock the BitbucketClient
|
||||
vi.mock('../../src/bitbucket-client.js', () => {
|
||||
// Mock domain clients - use simple object mocks instead of nested vi.fn
|
||||
vi.mock('../../src/clients/pull-request-client.js', () => {
|
||||
const mockPRClient = {
|
||||
listPullRequests: async () => [
|
||||
{ id: 1, title: 'Test PR 1', state: 'OPEN' },
|
||||
{ id: 2, title: 'Test PR 2', state: 'MERGED' }
|
||||
],
|
||||
getPullRequest: async () => ({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
state: 'OPEN',
|
||||
source: { branch: { name: 'feature' } },
|
||||
destination: { branch: { name: 'main' } }
|
||||
}),
|
||||
getPullRequestStatus: async () => ({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
state: 'OPEN',
|
||||
status: 'NORMAL'
|
||||
}),
|
||||
getPullRequestActivities: async () => ({
|
||||
values: [{ action: 'OPEN' }]
|
||||
}),
|
||||
getPullRequestChanges: async () => ({
|
||||
values: [{ type: 'modified', path: 'src/test.ts' }]
|
||||
}),
|
||||
getPullRequestCommits: async () => ({
|
||||
values: [{ hash: 'abc123' }]
|
||||
}),
|
||||
getPullRequestDiff: async () => ({
|
||||
diff: '--- test.ts\n+++ test.ts\n@@ -1 +1 @@'
|
||||
}),
|
||||
getPullRequestPatch: async () => ({
|
||||
patch: '--- original\n+++ modified'
|
||||
}),
|
||||
getPullRequestParticipants: async () => ({
|
||||
values: [{ user: { display_name: 'Test User' } }]
|
||||
}),
|
||||
getPullRequestReviewers: async () => [
|
||||
{ user: { display_name: 'Reviewer 1' } }
|
||||
],
|
||||
getPullRequestTasks: async () => ({
|
||||
values: []
|
||||
}),
|
||||
getPullRequestTaskCount: async () => ({ count: 0 }),
|
||||
getFullPullRequest: async () => ({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
description: 'Test description'
|
||||
}),
|
||||
createPullRequest: async () => ({ id: 1 }),
|
||||
updatePullRequest: async () => ({ id: 1 }),
|
||||
mergePullRequest: async () => ({ id: 1 }),
|
||||
declinePullRequest: async () => ({ id: 1 }),
|
||||
approvePullRequest: async () => ({ id: 1 }),
|
||||
unapprovePullRequest: async () => ({ id: 1 }),
|
||||
requestChangesPullRequest: async () => ({ id: 1 }),
|
||||
removeRequestChangesPullRequest: async () => ({ id: 1 })
|
||||
};
|
||||
|
||||
return {
|
||||
BitbucketClient: vi.fn().mockImplementation(() => ({
|
||||
listPullRequests: vi.fn().mockResolvedValue([
|
||||
{ id: 1, title: 'Test PR 1', state: 'OPEN' },
|
||||
{ id: 2, title: 'Test PR 2', state: 'MERGED' }
|
||||
]),
|
||||
getPullRequest: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
state: 'OPEN',
|
||||
source: { branch: { name: 'feature' } },
|
||||
destination: { branch: { name: 'main' } }
|
||||
}),
|
||||
getPullRequestStatus: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
state: 'OPEN',
|
||||
status: 'NORMAL'
|
||||
}),
|
||||
getPullRequestActivities: vi.fn().mockResolvedValue({
|
||||
values: [{ action: 'OPEN' }]
|
||||
}),
|
||||
getPullRequestChanges: vi.fn().mockResolvedValue({
|
||||
values: [{ type: 'modified', path: 'src/test.ts' }]
|
||||
}),
|
||||
getPullRequestComments: vi.fn().mockResolvedValue({
|
||||
values: [{ id: 1, content: { raw: 'Test comment' } }]
|
||||
}),
|
||||
getPullRequestComment: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
content: { raw: 'Test comment' }
|
||||
}),
|
||||
getPullRequestCommits: vi.fn().mockResolvedValue({
|
||||
values: [{ hash: 'abc123' }]
|
||||
}),
|
||||
getPullRequestDiff: vi.fn().mockResolvedValue({
|
||||
diff: '--- test.ts\n+++ test.ts\n@@ -1 +1 @@'
|
||||
}),
|
||||
getPullRequestPatch: vi.fn().mockResolvedValue({
|
||||
patch: '--- original\n+++ modified'
|
||||
}),
|
||||
getPullRequestParticipants: vi.fn().mockResolvedValue({
|
||||
values: [{ user: { display_name: 'Test User' } }]
|
||||
}),
|
||||
getPullRequestReviewers: vi.fn().mockResolvedValue([
|
||||
{ user: { display_name: 'Reviewer 1' } }
|
||||
]),
|
||||
getPullRequestTasks: vi.fn().mockResolvedValue({
|
||||
values: []
|
||||
}),
|
||||
getPullRequestTaskCount: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
getFullPullRequest: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
title: 'Test PR',
|
||||
description: 'Test description'
|
||||
})
|
||||
}))
|
||||
PullRequestClient: class {
|
||||
constructor() {
|
||||
Object.assign(this, mockPRClient);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/clients/repository-client.js', () => {
|
||||
const mockRepoClient = {
|
||||
listWorkspaces: async () => ({ values: [] }),
|
||||
listRepositories: async () => ({ values: [] }),
|
||||
getRepository: async () => ({ slug: 'test' }),
|
||||
listBranches: async () => ({ values: [] })
|
||||
};
|
||||
|
||||
return {
|
||||
RepositoryClient: class {
|
||||
constructor() {
|
||||
Object.assign(this, mockRepoClient);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/clients/comment-client.js', () => {
|
||||
const mockCommentClient = {
|
||||
getPullRequestComments: async () => ({
|
||||
values: [{ id: 1, content: { raw: 'Test comment' } }]
|
||||
}),
|
||||
getPullRequestComment: async () => ({
|
||||
id: 1,
|
||||
content: { raw: 'Test comment' }
|
||||
}),
|
||||
addPullRequestComment: async () => ({ id: 1 }),
|
||||
updatePullRequestComment: async () => ({ id: 1 }),
|
||||
deletePullRequestComment: async () => ({ success: true }),
|
||||
createPullRequestTask: async () => ({ id: 1 }),
|
||||
updatePullRequestTask: async () => ({ id: 1 }),
|
||||
deletePullRequestTask: async () => ({ success: true })
|
||||
};
|
||||
|
||||
return {
|
||||
CommentClient: class {
|
||||
constructor() {
|
||||
Object.assign(this, mockCommentClient);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user