Merge pull request #12 from crazy-max/github-apiurl

github: apiUrl
This commit is contained in:
CrazyMax 2023-02-01 01:46:12 +01:00 committed by GitHub
commit c617b15f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 33 deletions

View file

@ -29,14 +29,19 @@ jest.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRe
return <Promise<GitHubRepo>>(repoFixture as unknown);
});
describe('repoData', () => {
it('returns GitHub repository', async () => {
const github = new GitHub();
expect((await github.repoData()).name).toEqual('Hello-World');
});
});
describe('context', () => {
it('returns repository name from payload', async () => {
const github = new GitHub();
expect(github.context.payload.repository?.name).toEqual('test-docker-action');
expect(GitHub.context.payload.repository?.name).toEqual('test-docker-action');
});
it('is repository private', async () => {
const github = new GitHub();
expect(github.context.payload.repository?.private).toEqual(true);
expect(GitHub.context.payload.repository?.private).toEqual(true);
});
});
@ -54,12 +59,31 @@ describe('serverURL', () => {
});
it('returns default', async () => {
process.env.GITHUB_SERVER_URL = '';
const github = new GitHub();
expect(github.serverURL).toEqual('https://github.com');
expect(GitHub.serverURL).toEqual('https://github.com');
});
it('returns from env', async () => {
const github = new GitHub();
expect(github.serverURL).toEqual('https://foo.github.com');
expect(GitHub.serverURL).toEqual('https://foo.github.com');
});
});
describe('apiURL', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {
...originalEnv,
GITHUB_API_URL: 'https://bar.github.com'
};
});
afterEach(() => {
process.env = originalEnv;
});
it('returns default', async () => {
process.env.GITHUB_API_URL = '';
expect(GitHub.apiURL).toEqual('https://api.github.com');
});
it('returns from env', async () => {
expect(GitHub.apiURL).toEqual('https://bar.github.com');
});
});
@ -76,21 +100,12 @@ describe('actionsRuntimeToken', () => {
});
it('empty', async () => {
process.env.ACTIONS_RUNTIME_TOKEN = '';
const github = new GitHub();
expect(github.actionsRuntimeToken).toEqual({});
expect(GitHub.actionsRuntimeToken).toEqual({});
});
it('fixture', async () => {
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(__dirname, 'fixtures', 'runtimeToken.txt')).toString().trim();
const github = new GitHub();
const runtimeToken = github.actionsRuntimeToken;
const runtimeToken = GitHub.actionsRuntimeToken;
expect(runtimeToken.ac).toEqual('[{"Scope":"refs/heads/master","Permission":3}]');
expect(runtimeToken.iss).toEqual('vstoken.actions.githubusercontent.com');
});
});
describe('repoData', () => {
it('returns GitHub repository', async () => {
const github = new GitHub();
expect((await github.repoData()).name).toEqual('Hello-World');
});
});