diff --git a/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts b/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts index 6d9ef739e..b67414aab 100644 --- a/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts +++ b/src/practices/LanguageIndependent/TimeToSolvePullRequestsPractice.spec.ts @@ -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 () => { @@ -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 () => { diff --git a/src/services/bitbucket/BitbucketService.spec.ts b/src/services/bitbucket/BitbucketService.spec.ts index e109919e3..05bcdb32e 100644 --- a/src/services/bitbucket/BitbucketService.spec.ts +++ b/src/services/bitbucket/BitbucketService.spec.ts @@ -25,15 +25,8 @@ 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); @@ -41,13 +34,7 @@ describe('Bitbucket Service', () => { it('returns all pull requests in own interface', async () => { const state = 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 } }); @@ -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); @@ -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); diff --git a/src/test/helpers/bitbucketNock.ts b/src/test/helpers/bitbucketNock.ts index bd25f90ce..3b42741b4 100644 --- a/src/test/helpers/bitbucketNock.ts +++ b/src/test/helpers/bitbucketNock.ts @@ -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);