Skip to content

Commit

Permalink
Refactor: use testAuth for BitbucketPullRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Feb 22, 2024
1 parent 4d57607 commit 1dca6ff
Showing 1 changed file with 31 additions and 65 deletions.
96 changes: 31 additions & 65 deletions services/bitbucket/bitbucket-pull-request.spec.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,39 @@
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { BitbucketRawPullRequests } from './bitbucket-pull-request.service.js'

describe('BitbucketPullRequest', function () {
cleanUpNockAfterEach()

const user = 'admin'
const pass = 'password'

it('Sends auth headers to Bitbucket as configured', async function () {
const scope = nock('https://bitbucket.org/api/2.0/repositories/')
.get(/.*/)
.basicAuth({ user, pass })
.reply(200, { size: 42 })

expect(
await BitbucketRawPullRequests.invoke(
defaultContext,
{
public: {
services: {
bitbucketServer: {
authorizedOrigins: [],
},
},
},
private: { bitbucket_username: user, bitbucket_password: pass },
},
{ user: 'shields-io', repo: 'test-repo' },
),
).to.deep.equal({
message: '42',
color: 'yellow',
import { testAuth } from '../test-helpers.js'
import {
BitbucketRawPullRequests,
BitbucketNonRawPullRequests,
} from './bitbucket-pull-request.service.js'

describe('BitbucketRawPullRequests', function () {
describe('auth', function () {
it('sends the auth information to Bitbucket cloud as configured', async function () {
return testAuth(
BitbucketRawPullRequests,
'BasicAuth',
{ size: 42 },
{ exampleOverride: { server: undefined } },
)
})

scope.done()
it('sends the auth information to Bitbucket instence as configured', async function () {
return testAuth(BitbucketRawPullRequests, 'BasicAuth', { size: 42 })
})
})
})

it('Sends auth headers to Bitbucket Server as configured', async function () {
const scope = nock('https://bitbucket.example.test/rest/api/1.0/projects')
.get(/.*/)
.basicAuth({ user, pass })
.reply(200, { size: 42 })

expect(
await BitbucketRawPullRequests.invoke(
defaultContext,
{
public: {
services: {
bitbucketServer: {
authorizedOrigins: ['https://bitbucket.example.test'],
},
},
},
private: {
bitbucket_server_username: user,
bitbucket_server_password: pass,
},
},
{ user: 'project', repo: 'repo' },
{ server: 'https://bitbucket.example.test' },
),
).to.deep.equal({
message: '42',
color: 'yellow',
describe('BitbucketNonRawPullRequests', function () {
describe('auth', function () {
it('sends the auth information to Bitbucket cloud as configured', async function () {
return testAuth(
BitbucketNonRawPullRequests,
'BasicAuth',
{ size: 42 },
{ exampleOverride: { server: undefined } },
)
})

scope.done()
it('sends the auth information to Bitbucket instence as configured', async function () {
return testAuth(BitbucketNonRawPullRequests, 'BasicAuth', { size: 42 })
})
})
})

0 comments on commit 1dca6ff

Please sign in to comment.