Skip to content

Commit 722aae0

Browse files
first test for server pull requests
1 parent 7ecc8da commit 722aae0

File tree

3 files changed

+210
-2
lines changed

3 files changed

+210
-2
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import { ServerPullRequestApi } from './pullRequests';
2+
import { BitbucketSite } from '../model';
3+
import { IHTTPClient } from '../httpClient';
4+
5+
describe('ServerPullRequestApi', () => {
6+
let api: ServerPullRequestApi;
7+
let mockClient: jest.Mocked<IHTTPClient>;
8+
let site: BitbucketSite;
9+
10+
beforeEach(() => {
11+
mockClient = {
12+
get: jest.fn(),
13+
post: jest.fn(),
14+
put: jest.fn(),
15+
delete: jest.fn(),
16+
getRaw: jest.fn(),
17+
} as unknown as jest.Mocked<IHTTPClient>;
18+
19+
api = new ServerPullRequestApi(mockClient);
20+
site = { ownerSlug: 'owner', repoSlug: 'repo', details: { userId: 'user' } } as BitbucketSite;
21+
});
22+
23+
it('should get with a v8 if no 404s', async () => {
24+
mockClient.get.mockImplementation((url) => {
25+
if (
26+
url.includes('/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true')
27+
) {
28+
return Promise.resolve(getTaskCountDataV8);
29+
}
30+
if (url.includes('/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1')) {
31+
return Promise.resolve({ data: getPullRequestData });
32+
}
33+
34+
return Promise.reject(new Error('Not Found'));
35+
});
36+
37+
await api.get(site, 'PR-1');
38+
39+
expect(mockClient.get).lastCalledWith(
40+
'/rest/api/1.0/projects/owner/repos/repo/pull-requests/PR-1/blocker-comments?count=true',
41+
);
42+
});
43+
});
44+
45+
const getTaskCountDataV8 = {
46+
data: {
47+
OPEN: 5,
48+
},
49+
headers: {},
50+
};
51+
52+
const getPullRequestData = {
53+
id: 1,
54+
version: 4,
55+
title: 'a change',
56+
description: 'some words\\\n\\\nI can change the description\\\n\\\nChange me',
57+
state: 'OPEN',
58+
open: true,
59+
closed: false,
60+
draft: false,
61+
createdDate: 1739222096918,
62+
updatedDate: 1739329991386,
63+
fromRef: {
64+
id: 'refs/heads/testing-3',
65+
displayId: 'testing-3',
66+
latestCommit: 'b70a6199c92a978bf9a4862e1b96c9301400cbfa',
67+
type: 'BRANCH',
68+
repository: {
69+
slug: 'testing-axon',
70+
id: 1,
71+
name: 'testing-axon',
72+
hierarchyId: '451f980d695b670538b0',
73+
scmId: 'git',
74+
state: 'AVAILABLE',
75+
statusMessage: 'Available',
76+
forkable: true,
77+
project: {
78+
key: 'AX',
79+
id: 1,
80+
name: 'axon-test',
81+
public: false,
82+
type: 'NORMAL',
83+
links: {
84+
self: [
85+
{
86+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/projects/AX',
87+
},
88+
],
89+
},
90+
avatarUrl: '/projects/AX/avatar.png?s=64&v=1735870958971',
91+
},
92+
public: false,
93+
archived: false,
94+
links: {
95+
clone: [
96+
{
97+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/scm/ax/testing-axon.git',
98+
name: 'http',
99+
},
100+
{
101+
href: 'ssh://git@instenv-452647-24mv-alt-3a61ca65736a0f8b.elb.us-east-1.amazonaws.com:7999/ax/testing-axon.git',
102+
name: 'ssh',
103+
},
104+
],
105+
self: [
106+
{
107+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/projects/AX/repos/testing-axon/browse',
108+
},
109+
],
110+
},
111+
},
112+
},
113+
toRef: {
114+
id: 'refs/heads/main',
115+
displayId: 'main',
116+
latestCommit: 'de320695ae3092a489bcb31da5a8c8bb75d833a1',
117+
type: 'BRANCH',
118+
repository: {
119+
slug: 'testing-axon',
120+
id: 1,
121+
name: 'testing-axon',
122+
hierarchyId: '451f980d695b670538b0',
123+
scmId: 'git',
124+
state: 'AVAILABLE',
125+
statusMessage: 'Available',
126+
forkable: true,
127+
project: {
128+
key: 'AX',
129+
id: 1,
130+
name: 'axon-test',
131+
public: false,
132+
type: 'NORMAL',
133+
links: {
134+
self: [
135+
{
136+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/projects/AX',
137+
},
138+
],
139+
},
140+
avatarUrl: '/projects/AX/avatar.png?s=64&v=1735870958971',
141+
},
142+
public: false,
143+
archived: false,
144+
links: {
145+
clone: [
146+
{
147+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/scm/ax/testing-axon.git',
148+
name: 'http',
149+
},
150+
{
151+
href: 'ssh://git@instenv-452647-24mv-alt-3a61ca65736a0f8b.elb.us-east-1.amazonaws.com:7999/ax/testing-axon.git',
152+
name: 'ssh',
153+
},
154+
],
155+
self: [
156+
{
157+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/projects/AX/repos/testing-axon/browse',
158+
},
159+
],
160+
},
161+
},
162+
},
163+
locked: false,
164+
author: {
165+
user: {
166+
name: 'admin',
167+
emailAddress: '[email protected]',
168+
active: true,
169+
displayName: 'Ansible Admin',
170+
id: 2,
171+
slug: 'admin',
172+
type: 'NORMAL',
173+
links: {
174+
self: [
175+
{
176+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/users/admin',
177+
},
178+
],
179+
},
180+
avatarUrl: 'https://secure.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028.jpg?s=64&d=mm',
181+
},
182+
role: 'AUTHOR',
183+
approved: false,
184+
status: 'UNAPPROVED',
185+
},
186+
reviewers: [],
187+
participants: [],
188+
links: {
189+
self: [
190+
{
191+
href: 'https://instenv-452647-24mv.instenv.internal.atlassian.com/projects/AX/repos/testing-axon/pull-requests/1',
192+
},
193+
],
194+
},
195+
descriptionAsHtml: '<p>some words<br />\n<br />\nI can change the description<br />\n<br />\nChange me</p>\n',
196+
};

src/bitbucket/bitbucket-server/pullRequests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CacheMap } from '../../util/cachemap';
66
import { Time } from '../../util/time';
77
import { getFileNameFromPaths } from '../../views/pullrequest/diffViewHelper';
88
import { clientForSite } from '../bbUtils';
9-
import { HTTPClient } from '../httpClient';
9+
import { IHTTPClient } from '../httpClient';
1010
import {
1111
ApprovalStatus,
1212
BitbucketSite,
@@ -32,7 +32,7 @@ export class ServerPullRequestApi implements PullRequestApi {
3232
private defaultReviewersCache: CacheMap = new CacheMap();
3333
private fileContentCache: CacheMap = new CacheMap();
3434

35-
constructor(private client: HTTPClient) {}
35+
constructor(private client: IHTTPClient) {}
3636

3737
async getList(workspaceRepo: WorkspaceRepo, queryParams?: any): Promise<PaginatedPullRequests> {
3838
const site = workspaceRepo.mainSiteRemote.site;

src/bitbucket/httpClient.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export interface RequestRange {
1111
end: number;
1212
}
1313

14+
export interface IHTTPClient {
15+
getUrl(url: string, cancelToken?: CancelToken): Promise<any>;
16+
get(urlSlug: string, queryParams?: any, cancelToken?: CancelToken): Promise<any>;
17+
getRaw(urlSlug: string, queryParams?: any): Promise<any>;
18+
getArrayBuffer(urlSlug: string, queryParams?: any): Promise<any>;
19+
getOctetStream(urlSlug: string, range?: RequestRange, queryParams?: any): Promise<any>;
20+
post(urlSlug: string, body: any, queryParams?: any): Promise<any>;
21+
put(urlSlug: string, body: any, queryParams?: any): Promise<any>;
22+
delete(urlSlug: string, body: any, queryParams?: any): Promise<any>;
23+
generateUrl(urlSlug: string, queryParams?: any): string;
24+
}
25+
1426
export class HTTPClient {
1527
private transport: AxiosInstance;
1628

0 commit comments

Comments
 (0)