test: move github repoData api test to integration

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-02-27 02:53:48 +01:00
parent 3692a3c56f
commit cb8840fbce
2 changed files with 50 additions and 27 deletions

View File

@@ -26,6 +26,14 @@ import repoFixture from '../.fixtures/github-repo.json' with {type: 'json'};
const fixturesDir = path.join(__dirname, '..', '.fixtures');
vi.mock('@actions/core', async () => {
const actual = await vi.importActual<typeof import('@actions/core')>('@actions/core');
return {
...actual,
info: vi.fn()
};
});
describe('repoData', () => {
it('returns GitHub repo data', async () => {
vi.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
@@ -36,32 +44,6 @@ describe('repoData', () => {
});
});
describe('repoData (api)', () => {
it('returns docker/actions-toolkit', async () => {
if (!process.env.GITHUB_TOKEN) {
return;
}
const originalEnv = process.env;
process.env = {
...originalEnv,
GITHUB_REPOSITORY: 'docker/actions-toolkit'
};
try {
vi.resetModules();
vi.unmock('@actions/github');
const {GitHub} = await import('../../src/github/github.js');
const github = new GitHub({token: process.env.GITHUB_TOKEN});
const repo = await github.repoData();
const fullName = repo.full_name ?? `${repo.owner?.login}/${repo.name}`;
expect(fullName).toEqual('docker/actions-toolkit');
} finally {
process.env = originalEnv;
}
});
});
describe('context', () => {
it('returns repository name from payload', async () => {
expect(GitHub.context.payload.repository?.name).toEqual('test-docker-action');
@@ -201,7 +183,7 @@ describe('printActionsRuntimeTokenACs', () => {
await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrow(new Error('Cannot parse GitHub Actions Runtime Token: Invalid token specified: missing part #2'));
});
it('refs/heads/master', async () => {
const infoSpy = vi.spyOn(core, 'info');
const infoSpy = vi.mocked(core.info);
process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(fixturesDir, 'runtimeToken.txt')).toString().trim();
await GitHub.printActionsRuntimeTokenACs();
expect(infoSpy).toHaveBeenCalledTimes(1);