44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { updateOperatorAuthEnvContent } from '../src/operator-auth-reset.js';
|
|
import { parseArgs } 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 when absent', () => {
|
|
const updated = updateOperatorAuthEnvContent(
|
|
'ASSISTANT_NAME=Clawdie\n',
|
|
'operator@example.com',
|
|
);
|
|
|
|
expect(updated).toContain('CONTROLPLANE_OPERATOR_EMAIL=operator@example.com');
|
|
expect(updated).not.toContain('OPERATOR_PASSWORD=');
|
|
});
|
|
|
|
it('replaces existing controlplane email and removes operator password', () => {
|
|
const updated = updateOperatorAuthEnvContent(
|
|
'CONTROLPLANE_OPERATOR_EMAIL=old@example.com\nOPERATOR_PASSWORD=old\n',
|
|
'operator@example.com',
|
|
);
|
|
|
|
expect(updated).toContain('CONTROLPLANE_OPERATOR_EMAIL=operator@example.com');
|
|
expect(updated).not.toContain('OPERATOR_PASSWORD=');
|
|
expect(updated).not.toContain('old@example.com');
|
|
});
|
|
});
|