test(setup): add unit tests for setup_completed flag detection

- Add 3 test cases for setup_completed flag:
  - Detect flag when present and true
  - Treat missing flag as first-time eligible
  - Treat false flag as first-time eligible
- Update JSDoc to document detection priority order

Addresses code review feedback on PR #372.
This commit is contained in:
kaitranntt committed 2026-01-25 21:26:23 -05:00
1 parent 85e41a56e9
commit 596a9c6843
2 files changed
+52 -5

No files matched your search

+45
View File
@@ -115,6 +115,51 @@ cliproxy_server:
});
});
describe('setup_completed flag detection', () => {
it('should detect setup_completed flag in unified config', () => {
createConfigYaml(`
version: 8
setup_completed: true
profiles: {}
accounts: {}
`);
const content = fs.readFileSync(path.join(testDir, 'config.yaml'), 'utf8');
const hasSetupCompleted = content.includes('setup_completed: true');
expect(hasSetupCompleted).toBe(true);
});
it('should treat missing setup_completed as first-time eligible', () => {
createConfigYaml(`
version: 8
profiles: {}
accounts: {}
`);
const content = fs.readFileSync(path.join(testDir, 'config.yaml'), 'utf8');
const hasSetupCompleted = content.includes('setup_completed: true');
expect(hasSetupCompleted).toBe(false);
});
it('should treat setup_completed: false as first-time eligible', () => {
createConfigYaml(`
version: 8
setup_completed: false
profiles: {}
accounts: {}
`);
const content = fs.readFileSync(path.join(testDir, 'config.yaml'), 'utf8');
const hasSetupCompletedTrue = content.includes('setup_completed: true');
const hasSetupCompletedFalse = content.includes('setup_completed: false');
expect(hasSetupCompletedTrue).toBe(false);
expect(hasSetupCompletedFalse).toBe(true);
});
});
describe('corrupted config handling', () => {
it('should handle corrupted config.json gracefully', () => {
fs.writeFileSync(path.join(testDir, 'config.json'), 'not valid json{{{', 'utf8');