Skip to content

Commit

Permalink
fix: implement getOwnerId() in bitbucketNock
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Dec 9, 2019
1 parent 2b83d63 commit 81daee8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ describe('TimeToSolvePullRequestsPractice', () => {
});

it('returns practicing if there are open pullrequests updated or created less than 30 days from now', async () => {
nock(bitbucketNock.url)
.get('/users/pypy')
.reply(200);
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open);
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(10, 'days').asMilliseconds() };
mockCollaborationInspector.getPullRequests = async () => {
Expand All @@ -52,9 +50,7 @@ describe('TimeToSolvePullRequestsPractice', () => {
});

it('returns practicing if there are open pullrequests updated or created more than 30 days from now', async () => {
nock(bitbucketNock.url)
.get('/users/pypy')
.reply(200);
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open);
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(100, 'days').asMilliseconds() };
mockCollaborationInspector.getPullRequests = async () => {
Expand Down
37 changes: 4 additions & 33 deletions src/services/bitbucket/BitbucketService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,16 @@ describe('Bitbucket Service', () => {
});

it('returns open pull requests in own interface', async () => {
nock(bitbucketNock.url)
.get('/users/pypy')
.replyWithError('is a team account');

nock(bitbucketNock.url)
.get('/teams/pypy')
.reply(200, { uuid: '{f122f6a4-9111-4431-9f88-884d8cedd194}' });
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests');

const response = await service.getPullRequests('pypy', 'pypy');
const getOpenPullRequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({ states: BitbucketPullRequestState.open });
expect(response).toMatchObject(getOpenPullRequestsResponse);
});

it('returns all pull requests in own interface', async () => {
const state = <BitbucketPullRequestState>VCSServicesUtils.getPRState(PullRequestState.all, VCSService.bitbucket);
nock(bitbucketNock.url)
.get('/users/pypy')
.replyWithError('is a team account');

nock(bitbucketNock.url)
.get('/teams/pypy')
.reply(200, { uuid: '{f122f6a4-9111-4431-9f88-884d8cedd194}' });
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, state);

const response = await service.getPullRequests('pypy', 'pypy', { filter: { state: PullRequestState.all } });
Expand All @@ -57,13 +44,7 @@ describe('Bitbucket Service', () => {
});

it('returns specific pull request in own interface', async () => {
nock(bitbucketNock.url)
.get('/users/pypy')
.replyWithError('is a team account');

nock(bitbucketNock.url)
.get('/teams/pypy')
.reply(200, { uuid: '{f122f6a4-9111-4431-9f88-884d8cedd194}' });
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', 1);

const response = await service.getPullRequest('pypy', 'pypy', 1);
Expand Down Expand Up @@ -105,17 +86,7 @@ describe('Bitbucket Service', () => {
},
};

nock(bitbucketNock.url)
.get('/users/pypy')
.replyWithError('is a team account');

nock(bitbucketNock.url)
.get('/teams/pypy')
.reply(200, { uuid: '{f122f6a4-9111-4431-9f88-884d8cedd194}' });

nock(bitbucketNock.url)
.get('/users/pypy')
.reply(200);
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.closed);

const response = await service.getPullRequests('pypy', 'pypy', state);
Expand Down
8 changes: 8 additions & 0 deletions src/test/helpers/bitbucketNock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export class BitbucketNock {
return BitbucketNock.get(url, params, persist).reply(200, response);
}

getOwnerId() {
const url = `${this.url}/repositories/${this.user}/${this.repoName}`;
const params = {};
const persist = true;
const response = { owner: { uuid: '{f122f6a4-9111-4431-9f88-884d8cedd194}' } };
return BitbucketNock.get(url, params, persist).reply(200, response);
}

private static get(url: string, params: nock.DataMatcherMap, persist = true): nock.Interceptor {
const urlObj = new URL(url);

Expand Down

0 comments on commit 81daee8

Please sign in to comment.