test: githubActionsRuntimeToken

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-30 03:08:12 +01:00
parent 85ef93202e
commit 039779492c
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
3 changed files with 32 additions and 3 deletions

View file

@ -1,4 +1,6 @@
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import {GitHub, GitHubRepo} from '../src/github';
@ -45,6 +47,31 @@ describe('serverURL', () => {
});
});
describe('actionsRuntimeToken', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {
...originalEnv
};
});
afterEach(() => {
process.env = originalEnv;
});
it('empty', async () => {
process.env.ACTIONS_RUNTIME_TOKEN = '';
const github = new GitHub();
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;
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();