clawdie-ai/setup/operator-auth.test.ts
Operator & Codex 2ab3fa050a refactor(setup): unify operator auth entrypoints
---
Build: pass | Tests: pass — Tests  1991 passed (1991)
2026-04-27 08:13:36 +02:00

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { parseArgs, updateOperatorAuthEnvContent } from './operator-auth.js';
describe('operator-auth args', () => {
it('parses email and name flags', () => {
expect(
parseArgs(['--email', 'operator@example.com', '--name', 'Mevy']),
).toEqual({
email: 'operator@example.com',
name: 'Mevy',
});
});
it('ignores unrelated args', () => {
expect(parseArgs(['hello', '--email', 'operator@example.com'])).toEqual({
email: 'operator@example.com',
});
});
});
describe('operator-auth env updates', () => {
it('writes controlplane email and operator password when absent', () => {
const updated = updateOperatorAuthEnvContent(
'ASSISTANT_NAME=Clawdie\n',
'operator@example.com',
'secret-pass',
);
expect(updated).toContain('CONTROLPLANE_OPERATOR_EMAIL=operator@example.com');
expect(updated).toContain('OPERATOR_PASSWORD=secret-pass');
});
it('replaces existing controlplane email and operator password', () => {
const updated = updateOperatorAuthEnvContent(
'CONTROLPLANE_OPERATOR_EMAIL=old@example.com\nOPERATOR_PASSWORD=old\n',
'operator@example.com',
'secret-pass',
);
expect(updated).toContain('CONTROLPLANE_OPERATOR_EMAIL=operator@example.com');
expect(updated).toContain('OPERATOR_PASSWORD=secret-pass');
expect(updated).not.toContain('old@example.com');
});
});