Skip to content
Merged
35 changes: 34 additions & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
storeToken,
clearStoredToken,
getUIPrefs,
storeUIPrefs
storeUIPrefs,
getTokenSource
} from '../src/config';

// Mock fs and envPaths
Expand Down Expand Up @@ -324,4 +325,36 @@ describe('config', () => {
);
});
});

describe('getTokenSource', () => {
it('returns tokenSource from config when present', () => {
const mockConfig = {
token: 'token',
tokenSource: 'oauth'
};
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockConfig));

const source = getTokenSource();
expect(source).toBe('oauth');
});

it('returns "pat" as default when tokenSource not in config', () => {
const mockConfig = {
token: 'token'
};
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockConfig));

const source = getTokenSource();
expect(source).toBe('pat');
});

it('returns "pat" when config file does not exist', () => {
vi.mocked(fs.readFileSync).mockImplementation(() => {
throw new Error('File not found');
});

const source = getTokenSource();
expect(source).toBe('pat');
});
});
});
11 changes: 11 additions & 0 deletions tests/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';

// Mock the logger before importing modules that use it
vi.mock('../src/logger', () => ({
logger: {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
}
}));

import { makeClient, getViewerLogin, fetchViewerOrganizations } from '../src/github';

// Mock @octokit/graphql
Expand Down
Loading