Skip to content

Commit 7e7b4d0

Browse files
rcourtmanclaude
andcommitted
test: improve test coverage for configLoader.js edge cases
- Add tests for placeholder detection with PROXMOX_TOKEN_ID edge cases - Test scenarios where TOKEN_ID needs to be added to placeholder list - Improve overall test coverage to ~90% 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 72f1316 commit 7e7b4d0

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

server/tests/config.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,61 @@ describe('Configuration Loading (loadConfiguration)', () => {
390390
dotenv.config.mockClear(); // Clear the mock for other tests
391391
});
392392

393+
// Test Case 11: Placeholder detection with PROXMOX_TOKEN_ID in env
394+
test('should insert PROXMOX_TOKEN_ID in correct position when placeholders detected', () => {
395+
setEnvVars({
396+
PROXMOX_HOST: 'your-proxmox-ip-or-hostname',
397+
PROXMOX_TOKEN_ID: 'user@pam!token',
398+
PROXMOX_TOKEN_SECRET: 'your-api-token-uuid',
399+
});
400+
401+
const config = loadConfiguration();
402+
403+
// Should detect placeholders - the actual implementation includes PROXMOX_TOKEN_ID when it's set
404+
expect(consoleWarnSpy).toHaveBeenCalledWith(
405+
expect.stringContaining('WARN: Primary Proxmox environment variables seem to contain placeholder values: PROXMOX_HOST, PROXMOX_TOKEN_ID')
406+
);
407+
expect(config.isConfigPlaceholder).toBe(true);
408+
});
409+
410+
// Test Case 12: Placeholder detection - TOKEN_ID not in list but exists
411+
test('should add PROXMOX_TOKEN_ID at end if not in placeholder list but exists', () => {
412+
// Only secret is a placeholder, but TOKEN_ID exists and should be added
413+
setEnvVars({
414+
PROXMOX_HOST: 'pve.example.com',
415+
PROXMOX_TOKEN_ID: 'user@pam!mytoken', // exists but not a placeholder
416+
PROXMOX_TOKEN_SECRET: 'your-api-token-uuid', // placeholder
417+
});
418+
419+
const config = loadConfiguration();
420+
421+
// Should detect the secret placeholder and add TOKEN_ID
422+
expect(consoleWarnSpy).toHaveBeenCalledWith(
423+
expect.stringContaining('your-api-token-uuid')
424+
);
425+
expect(config.isConfigPlaceholder).toBe(true);
426+
});
427+
428+
// Test Case 13: Test line 138 - Add TOKEN_ID when no PROXMOX_HOST in placeholderVars
429+
test('should push PROXMOX_TOKEN_ID when PROXMOX_HOST not in placeholder list', () => {
430+
// Only PROXMOX_PORT is placeholder (not PROXMOX_HOST)
431+
setEnvVars({
432+
PROXMOX_HOST: 'pve.example.com',
433+
PROXMOX_TOKEN_ID: 'user@pam!token',
434+
PROXMOX_TOKEN_SECRET: 'secret123',
435+
PROXMOX_PORT: 'your-port' // placeholder that's not HOST/TOKEN_ID/TOKEN_SECRET
436+
});
437+
438+
const config = loadConfiguration();
439+
440+
// Should detect port placeholder and add TOKEN_ID to end since HOST not in list
441+
expect(consoleWarnSpy).toHaveBeenCalledWith(
442+
expect.stringContaining('PROXMOX_PORT')
443+
);
444+
expect(consoleWarnSpy).toHaveBeenCalledWith(
445+
expect.stringContaining('PROXMOX_TOKEN_ID')
446+
);
447+
expect(config.isConfigPlaceholder).toBe(true);
448+
});
449+
393450
});

0 commit comments

Comments
 (0)