Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/services/bitbucket/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,55 @@ describe('BitbucketClient — addReviewer', () => {
});
});

describe('BitbucketClient — createPR / updatePR reviewers', () => {
afterEach(() => { vi.unstubAllGlobals(); });

it('serializes createPR reviewers as user.name, not user.slug', async () => {
const calls: Array<{ url: string; method: string; body?: unknown }> = [];
vi.stubGlobal('fetch', async (url: string, init: RequestInit) => {
const body = init.body ? JSON.parse(init.body as string) : undefined;
calls.push({ url, method: init.method ?? 'GET', body });
return new Response(JSON.stringify({}), { status: 201 });
});

const client = new BitbucketClient(new HttpClient(makeConfig()));
await client.createPR({
project: 'PROJ',
repo: 'REPO',
title: 'Test PR',
source: 'feat',
target: 'main',
reviewers: ['jsmith', 'jdoe']
});

expect(calls).toHaveLength(1);
const body = calls[0].body as { reviewers: Array<{ user: Record<string, unknown> }> };
expect(body.reviewers).toEqual([{ user: { name: 'jsmith' } }, { user: { name: 'jdoe' } }]);
});

it('serializes updatePR reviewers as user.name, not user.slug', async () => {
const calls: Array<{ url: string; method: string; body?: unknown }> = [];
vi.stubGlobal('fetch', async (url: string, init: RequestInit) => {
const body = init.body ? JSON.parse(init.body as string) : undefined;
calls.push({ url, method: init.method ?? 'GET', body });
return new Response(JSON.stringify({}), { status: 200 });
});

const client = new BitbucketClient(new HttpClient(makeConfig()));
await client.updatePR({
project: 'PROJ',
repo: 'REPO',
id: 42,
version: 1,
reviewers: ['jsmith']
});

expect(calls).toHaveLength(1);
const body = calls[0].body as { reviewers: Array<{ user: Record<string, unknown> }> };
expect(body.reviewers).toEqual([{ user: { name: 'jsmith' } }]);
});
});

describe('BitbucketClient — needsWorkPR', () => {
beforeEach(() => { vi.unstubAllGlobals(); });
afterEach(() => { vi.unstubAllGlobals(); });
Expand Down
4 changes: 2 additions & 2 deletions src/services/bitbucket/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BitbucketClient {
project: { key: opts.project }
}
},
reviewers: (opts.reviewers ?? []).map(slug => ({ user: { slug } }))
reviewers: (opts.reviewers ?? []).map(name => ({ user: { name } }))
}
}
);
Expand All @@ -121,7 +121,7 @@ export class BitbucketClient {
const body: Record<string, unknown> = { version: opts.version };
if (opts.title) body.title = opts.title;
if (opts.description !== undefined) body.description = opts.description;
if (opts.reviewers) body.reviewers = opts.reviewers.map(slug => ({ user: { slug } }));
if (opts.reviewers) body.reviewers = opts.reviewers.map(name => ({ user: { name } }));

return this.http.bitbucket<BitbucketPR>(
`${API}/projects/${opts.project}/repos/${opts.repo}/pull-requests/${opts.id}`,
Expand Down
Loading