forked from actions/checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-api-helper.test.ts
37 lines (31 loc) · 1005 Bytes
/
github-api-helper.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as github from '@actions/github'
import * as githubApiHelper from '../lib/github-api-helper'
jest.mock('@actions/github')
describe('github-api-helper tests', () => {
describe('github enterprise compatibility', () => {
beforeEach(() => {
process.env.GITHUB_SERVER_URL = 'https://enterprise.git.com'
})
afterEach(() => {
delete process.env.GITHUB_SERVER_URL
})
it('getDefaultBranch should use GITHUB_SERVER_URL to set the baseUrl', async () => {
;(github.getOctokit as jest.Mock).mockImplementation(() => {
return {
rest: {
repos: {
get: jest.fn(() => ({data: {default_branch: 'default-branch'}}))
}
}
}
})
await githubApiHelper.getDefaultBranch('token', 'owner', 'repo')
expect(github.getOctokit).toHaveBeenCalledWith(
'token',
expect.objectContaining({
baseUrl: 'https://enterprise.git.com/api/v3'
})
)
})
})
})