test: add integration tests for repository browsing and write operations

This commit is contained in:
2026-05-20 19:27:59 +02:00
parent c340873c6b
commit 93688bc90c

View File

@@ -292,3 +292,116 @@ describe('Error Handling', () => {
}
});
});
const RUN_WRITES = process.env.RUN_WRITE_TESTS === 'true';
describe('Repository / Workspace (read)', () => {
let client: BitbucketClient;
beforeAll(() => {
client = new BitbucketClient();
});
it('should list workspaces', async () => {
if (!HAS_TOKEN) return;
const result = await client.listWorkspaces({ pagelen: 10 });
expect(result).toHaveProperty('values');
expect(Array.isArray(result.values)).toBe(true);
});
it('should list repositories in workspace', async () => {
if (!HAS_TOKEN) return;
const result = await client.listRepositories(WORKSPACE, { pagelen: 10 });
expect(result).toHaveProperty('values');
expect(Array.isArray(result.values)).toBe(true);
});
it('should get a specific repository', async () => {
if (!HAS_TOKEN) return;
const result = await client.getRepository(WORKSPACE, REPO_SLUG);
expect(result).toHaveProperty('slug');
expect(result).toHaveProperty('full_name');
});
it('should list branches', async () => {
if (!HAS_TOKEN) return;
const result = await client.listBranches(WORKSPACE, REPO_SLUG, { pagelen: 10 });
expect(result).toHaveProperty('values');
expect(Array.isArray(result.values)).toBe(true);
if (result.values.length > 0) {
expect(result.values[0]).toHaveProperty('name');
}
});
it('should filter branches by name', async () => {
if (!HAS_TOKEN) return;
const result = await client.listBranches(WORKSPACE, REPO_SLUG, { filter_by_name: 'main' });
expect(result).toHaveProperty('values');
});
});
describe('PR Write Operations (requires RUN_WRITE_TESTS=true)', () => {
let client: BitbucketClient;
beforeAll(() => {
client = new BitbucketClient();
});
it('should approve a PR', async () => {
if (!HAS_TOKEN || !RUN_WRITES) return;
const prs = await client.listPullRequests(WORKSPACE, REPO_SLUG, { state: 'OPEN' });
if (prs.length === 0) { console.log('No open PRs, skipping'); return; }
const result = await client.approvePullRequest(WORKSPACE, REPO_SLUG, prs[0].id);
expect(result).toBeDefined();
});
it('should unapprove a PR', async () => {
if (!HAS_TOKEN || !RUN_WRITES) return;
const prs = await client.listPullRequests(WORKSPACE, REPO_SLUG, { state: 'OPEN' });
if (prs.length === 0) { console.log('No open PRs, skipping'); return; }
const result = await client.unapprovePullRequest(WORKSPACE, REPO_SLUG, prs[0].id);
expect(result).toHaveProperty('success', true);
});
});
describe('Comment / Task Write Operations (requires RUN_WRITE_TESTS=true)', () => {
let client: BitbucketClient;
beforeAll(() => {
client = new BitbucketClient();
});
it('should add, update, then delete a comment', async () => {
if (!HAS_TOKEN || !RUN_WRITES) return;
const prs = await client.listPullRequests(WORKSPACE, REPO_SLUG, { state: 'OPEN' });
if (prs.length === 0) { console.log('No open PRs, skipping'); return; }
const prId = prs[0].id;
const added = await client.addPullRequestComment(WORKSPACE, REPO_SLUG, prId, { content: 'Integration test comment' });
expect(added).toHaveProperty('id');
const commentId = added.id;
const updated = await client.updatePullRequestComment(WORKSPACE, REPO_SLUG, prId, commentId, { content: 'Updated comment' });
expect(updated).toHaveProperty('id', commentId);
const deleted = await client.deletePullRequestComment(WORKSPACE, REPO_SLUG, prId, commentId);
expect(deleted).toHaveProperty('success', true);
});
it('should create, resolve, then delete a task', async () => {
if (!HAS_TOKEN || !RUN_WRITES) return;
const prs = await client.listPullRequests(WORKSPACE, REPO_SLUG, { state: 'OPEN' });
if (prs.length === 0) { console.log('No open PRs, skipping'); return; }
const prId = prs[0].id;
const created = await client.createPullRequestTask(WORKSPACE, REPO_SLUG, prId, { content: 'Integration test task' });
expect(created).toHaveProperty('id');
const taskId = created.id;
const resolved = await client.updatePullRequestTask(WORKSPACE, REPO_SLUG, prId, taskId, { state: 'RESOLVED' });
expect(resolved).toBeDefined();
const deleted = await client.deletePullRequestTask(WORKSPACE, REPO_SLUG, prId, taskId);
expect(deleted).toHaveProperty('success', true);
});
});