mirror of
https://code.forgejo.org/docker/actions-toolkit.git
synced 2025-06-25 23:28:21 -04:00
commit
c617b15f70
2 changed files with 51 additions and 33 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue