Skip to content

Commit c4b6f08

Browse files
committed
Added tests
1 parent 7e21aaa commit c4b6f08

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/utils/__tests__/config.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
} from '../../types/Settings';
1414
import {
1515
getSettingsConfiguration,
16-
loadSettings
16+
loadSettings,
17+
saveSettings
1718
} from '../config';
1819

1920
vi.mock('os', () => ({ homedir: vi.fn().mockReturnValue('/some-home-dir') }));
@@ -90,4 +91,48 @@ describe('config', () => {
9091
expect(vi.mocked(fs.promises.writeFile)).toHaveBeenCalledWith(backupPath, 'invalid', 'utf-8');
9192
expect(settings.version).toBe(CURRENT_VERSION);
9293
});
94+
95+
it('should save settings to default location - global', async () => {
96+
setGlobalConfig();
97+
98+
const settings = await loadSettings();
99+
await saveSettings(settings);
100+
101+
expect(vi.mocked(fs.promises.writeFile)).toHaveBeenCalledWith(globalConfig, JSON.stringify(settings, null, 2), 'utf-8');
102+
});
103+
104+
it('should save settings to default location - project', async () => {
105+
setProjectConfig();
106+
107+
const settings = await loadSettings();
108+
await saveSettings(settings);
109+
110+
expect(vi.mocked(fs.promises.writeFile)).toHaveBeenCalledWith(projectConfig, JSON.stringify(settings, null, 2), 'utf-8');
111+
});
112+
113+
it('should save settings to specified location - global', async () => {
114+
setProjectConfig();
115+
116+
const config = getSettingsConfiguration();
117+
expect(config.type).toBe('project');
118+
119+
const settings = await loadSettings();
120+
121+
await saveSettings(settings, 'global');
122+
123+
expect(vi.mocked(fs.promises.writeFile)).toHaveBeenCalledWith(globalConfig, JSON.stringify(settings, null, 2), 'utf-8');
124+
});
125+
126+
it('should save settings to specified location - project', async () => {
127+
setGlobalConfig();
128+
129+
const config = getSettingsConfiguration();
130+
expect(config.type).toBe('global');
131+
132+
const settings = await loadSettings();
133+
134+
await saveSettings(settings, 'project');
135+
136+
expect(vi.mocked(fs.promises.writeFile)).toHaveBeenCalledWith(projectConfig, JSON.stringify(settings, null, 2), 'utf-8');
137+
});
93138
});

src/utils/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const writeFile = async (path: string, content: string) => fs.promises.wr
2222
export function getSettingsConfiguration(type?: 'global' | 'project') {
2323
const projectConfig = path.join(process.cwd(), '.claude', 'ccstatusline.json');
2424

25-
if (type === 'project' || fs.existsSync(projectConfig)) {
25+
if ((type === 'project') || (!type && fs.existsSync(projectConfig))) {
2626
return {
2727
configDir: path.dirname(projectConfig),
2828
path: projectConfig,

0 commit comments

Comments
 (0)