mirror of
https://code.forgejo.org/docker/actions-toolkit.git
synced 2025-06-26 07:38:21 -04:00
move GitHub specific to its own class
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
bb369fa859
commit
85ef93202e
5 changed files with 107 additions and 92 deletions
53
__tests__/github.test.ts
Normal file
53
__tests__/github.test.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
|
||||
|
||||
import {GitHub, GitHubRepo} from '../src/github';
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
import * as repoFixture from './fixtures/repo.json';
|
||||
jest.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
|
||||
return <Promise<GitHubRepo>>(repoFixture as unknown);
|
||||
});
|
||||
|
||||
describe('context', () => {
|
||||
it('returns repository name from payload', async () => {
|
||||
const github = new GitHub();
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('serverURL', () => {
|
||||
const originalEnv = process.env;
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
GITHUB_SERVER_URL: 'https://foo.github.com'
|
||||
};
|
||||
});
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
it('returns default', async () => {
|
||||
process.env.GITHUB_SERVER_URL = '';
|
||||
const github = new GitHub();
|
||||
expect(github.serverURL).toEqual('https://github.com');
|
||||
});
|
||||
it('returns from env', async () => {
|
||||
const github = new GitHub();
|
||||
expect(github.serverURL).toEqual('https://foo.github.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoData', () => {
|
||||
it('returns GitHub repository', async () => {
|
||||
const github = new GitHub();
|
||||
expect((await github.repoData()).name).toEqual('Hello-World');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue