|
1 | | -import { expect } from 'chai' |
2 | | -import nock from 'nock' |
3 | | -import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js' |
4 | | -import { BitbucketRawPullRequests } from './bitbucket-pull-request.service.js' |
| 1 | +import { testAuth } from '../test-helpers.js' |
| 2 | +import { |
| 3 | + BitbucketRawPullRequests, |
| 4 | + BitbucketNonRawPullRequests, |
| 5 | +} from './bitbucket-pull-request.service.js' |
5 | 6 |
|
6 | | -describe('BitbucketPullRequest', function () { |
7 | | - cleanUpNockAfterEach() |
| 7 | +const serverConfigOverride = { |
| 8 | + public: { |
| 9 | + services: { |
| 10 | + bitbucketServer: { |
| 11 | + authorizedOrigins: ['https://bitbucket.mydomain.net'], |
| 12 | + }, |
| 13 | + bitbucket: { |
| 14 | + authorizedOrigins: ['https://bitbucket.org'], |
| 15 | + }, |
| 16 | + }, |
| 17 | + }, |
| 18 | + private: { |
| 19 | + bitbucket_username: 'must-be-set-for-class-constructor', |
| 20 | + bitbucket_password: 'must-be-set-for-class-constructor', |
| 21 | + }, |
| 22 | +} |
8 | 23 |
|
9 | | - const user = 'admin' |
10 | | - const pass = 'password' |
| 24 | +const cloudConfigOverride = { |
| 25 | + public: { |
| 26 | + services: { |
| 27 | + bitbucket: { |
| 28 | + authorizedOrigins: ['https://bitbucket.org'], |
| 29 | + }, |
| 30 | + bitbucketServer: { |
| 31 | + authorizedOrigins: [], |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | +} |
11 | 36 |
|
12 | | - it('Sends auth headers to Bitbucket as configured', async function () { |
13 | | - const scope = nock('https://bitbucket.org/api/2.0/repositories/') |
14 | | - .get(/.*/) |
15 | | - .basicAuth({ user, pass }) |
16 | | - .reply(200, { size: 42 }) |
17 | | - |
18 | | - expect( |
19 | | - await BitbucketRawPullRequests.invoke( |
20 | | - defaultContext, |
| 37 | +describe('BitbucketRawPullRequests', function () { |
| 38 | + describe('auth', function () { |
| 39 | + it('sends the auth information to Bitbucket cloud as configured', async function () { |
| 40 | + return testAuth( |
| 41 | + BitbucketRawPullRequests, |
| 42 | + 'BasicAuth', |
| 43 | + { size: 42 }, |
21 | 44 | { |
22 | | - public: { |
23 | | - services: { |
24 | | - bitbucketServer: { |
25 | | - authorizedOrigins: [], |
26 | | - }, |
27 | | - }, |
28 | | - }, |
29 | | - private: { bitbucket_username: user, bitbucket_password: pass }, |
| 45 | + exampleOverride: { server: undefined }, |
| 46 | + configOverride: cloudConfigOverride, |
30 | 47 | }, |
31 | | - { user: 'shields-io', repo: 'test-repo' }, |
32 | | - ), |
33 | | - ).to.deep.equal({ |
34 | | - message: '42', |
35 | | - color: 'yellow', |
| 48 | + ) |
36 | 49 | }) |
37 | 50 |
|
38 | | - scope.done() |
| 51 | + it('sends the auth information to Bitbucket instence as configured', async function () { |
| 52 | + return testAuth( |
| 53 | + BitbucketRawPullRequests, |
| 54 | + 'BasicAuth', |
| 55 | + { size: 42 }, |
| 56 | + { |
| 57 | + authOverride: BitbucketRawPullRequests.authServer, |
| 58 | + configOverride: serverConfigOverride, |
| 59 | + }, |
| 60 | + ) |
| 61 | + }) |
39 | 62 | }) |
| 63 | +}) |
40 | 64 |
|
41 | | - it('Sends auth headers to Bitbucket Server as configured', async function () { |
42 | | - const scope = nock('https://bitbucket.example.test/rest/api/1.0/projects') |
43 | | - .get(/.*/) |
44 | | - .basicAuth({ user, pass }) |
45 | | - .reply(200, { size: 42 }) |
46 | | - |
47 | | - expect( |
48 | | - await BitbucketRawPullRequests.invoke( |
49 | | - defaultContext, |
| 65 | +describe('BitbucketNonRawPullRequests', function () { |
| 66 | + describe('auth', function () { |
| 67 | + it('sends the auth information to Bitbucket cloud as configured', async function () { |
| 68 | + return testAuth( |
| 69 | + BitbucketNonRawPullRequests, |
| 70 | + 'BasicAuth', |
| 71 | + { size: 42 }, |
50 | 72 | { |
51 | | - public: { |
52 | | - services: { |
53 | | - bitbucketServer: { |
54 | | - authorizedOrigins: ['https://bitbucket.example.test'], |
55 | | - }, |
56 | | - }, |
57 | | - }, |
58 | | - private: { |
59 | | - bitbucket_server_username: user, |
60 | | - bitbucket_server_password: pass, |
61 | | - }, |
| 73 | + exampleOverride: { server: undefined }, |
| 74 | + configOverride: cloudConfigOverride, |
62 | 75 | }, |
63 | | - { user: 'project', repo: 'repo' }, |
64 | | - { server: 'https://bitbucket.example.test' }, |
65 | | - ), |
66 | | - ).to.deep.equal({ |
67 | | - message: '42', |
68 | | - color: 'yellow', |
| 76 | + ) |
69 | 77 | }) |
70 | 78 |
|
71 | | - scope.done() |
| 79 | + it('sends the auth information to Bitbucket instence as configured', async function () { |
| 80 | + return testAuth( |
| 81 | + BitbucketNonRawPullRequests, |
| 82 | + 'BasicAuth', |
| 83 | + { size: 42 }, |
| 84 | + { |
| 85 | + authOverride: BitbucketNonRawPullRequests.authServer, |
| 86 | + configOverride: serverConfigOverride, |
| 87 | + }, |
| 88 | + ) |
| 89 | + }) |
72 | 90 | }) |
73 | 91 | }) |
0 commit comments