Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 1 addition & 41 deletions tests/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock('node:child_process', () => ({
}),
}));

import { readConfig, writeConfig, deleteConfig, configExists, getConfigValue, setConfigValue } from '../../src/lib/config';
import { readConfig, writeConfig, deleteConfig, setConfigValue } from '../../src/lib/config';

const CONFIG_DIR = path.join('/tmp/test-home', '.dealmachine');
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
Expand Down Expand Up @@ -85,20 +85,6 @@ describe('CLI config', () => {
expect(writtenConfig.credentialStore).toBe('encrypted-file');
expect(writtenConfig.credentialFile).toBe(CREDENTIAL_FILE);
});

it('skips mkdir when directory exists', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
writeConfig(sampleConfig);
expect(fs.mkdirSync).not.toHaveBeenCalled();
});

it('falls back when the OS credential store is unavailable', () => {
vi.mocked(fs.existsSync).mockImplementation((file) => file === CONFIG_DIR);

writeConfig(sampleConfig);

expect(getWrittenConfig().credentialStore).toBe('encrypted-file');
});
});

describe('deleteConfig', () => {
Expand All @@ -114,32 +100,6 @@ describe('CLI config', () => {
});
});

describe('configExists', () => {
it('returns true when file exists', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
expect(configExists()).toBe(true);
});

it('returns false when file does not exist', () => {
vi.mocked(fs.existsSync).mockReturnValue(false);
expect(configExists()).toBe(false);
});
});

describe('getConfigValue', () => {
it('returns specific config value', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(sampleConfig));
expect(getConfigValue('apiKey')).toBe('dm_sk_live_test123');
expect(getConfigValue('organizationId')).toBe(7);
});

it('returns null when no config', () => {
vi.mocked(fs.existsSync).mockReturnValue(false);
expect(getConfigValue('apiKey')).toBeNull();
});
});

describe('setConfigValue', () => {
it('updates a single config value', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
Expand Down
15 changes: 1 addition & 14 deletions tests/lib/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vi.mock('chalk', () => {
return { default: new Proxy({}, handler) };
});

import { truncate, printTable, printJson, printKeyValue } from '../../src/lib/output';
import { truncate, printTable, printJson } from '../../src/lib/output';

describe('output helpers', () => {
beforeEach(() => {
Expand Down Expand Up @@ -45,24 +45,11 @@ describe('output helpers', () => {
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('no results'));
});

it('prints header and rows', () => {
printTable([{ name: 'Alice', age: 30 }], ['name', 'age']);
// At least header + separator + 1 row = 3 calls
expect(vi.mocked(console.log).mock.calls.length).toBeGreaterThanOrEqual(3);
});

it('auto-detects columns from first row', () => {
printTable([{ x: 1, y: 2 }]);
const allOutput = vi.mocked(console.log).mock.calls.map(c => c[0]).join('\n');
expect(allOutput).toContain('x');
expect(allOutput).toContain('y');
});
});

describe('printKeyValue', () => {
it('prints key-value pairs', () => {
printKeyValue({ name: 'Test', count: 42 });
expect(vi.mocked(console.log).mock.calls.length).toBe(2);
});
});
});
Loading