49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { runOperatorPasswordReset } from './password-reset'
|
|
|
|
const environment = {
|
|
SESSION_SECRET: 's'.repeat(32),
|
|
PUBLIC_BASE_URL: 'https://runbook.example.test',
|
|
}
|
|
|
|
describe('operator password reset command', () => {
|
|
it('accepts only an email and emits exactly one reset URL line', async () => {
|
|
const output = vi.fn()
|
|
const issue = vi.fn(async () => ({
|
|
resetUrl:
|
|
'https://runbook.example.test/reset-password#token=secret-token',
|
|
expiresAt: new Date('2026-07-27T12:30:00Z'),
|
|
}))
|
|
|
|
await runOperatorPasswordReset(
|
|
['owner@example.test'],
|
|
environment,
|
|
output,
|
|
issue,
|
|
)
|
|
|
|
expect(issue).toHaveBeenCalledWith({
|
|
email: 'owner@example.test',
|
|
publicBaseUrl: 'https://runbook.example.test',
|
|
})
|
|
expect(output).toHaveBeenCalledOnce()
|
|
expect(output).toHaveBeenCalledWith(
|
|
'https://runbook.example.test/reset-password#token=secret-token',
|
|
)
|
|
})
|
|
|
|
it('rejects a second argument instead of accepting a new password', async () => {
|
|
const issue = vi.fn()
|
|
await expect(
|
|
runOperatorPasswordReset(
|
|
['owner@example.test', 'new-password'],
|
|
environment,
|
|
vi.fn(),
|
|
issue,
|
|
),
|
|
).rejects.toThrow('Usage:')
|
|
expect(issue).not.toHaveBeenCalled()
|
|
})
|
|
})
|