// bot/src/__tests__/bot.test.ts
// Testa redactSecrets — S-04
//
// commands/bot.ts importa create.ts que usa execa (ESM puro).
// Mockamos os módulos com dependências ESM para isolar a função testada.

jest.mock('../commands/create', () => ({}))
jest.mock('../commands/update', () => ({}))
jest.mock('../commands/aproved', () => ({}))
jest.mock('../commands/list', () => ({}))
jest.mock('../commands/view', () => ({}))
jest.mock('../commands/help', () => ({}))

import { redactSecrets } from '../commands/bot'

describe('redactSecrets', () => {
  test('redact de token xoxb (S-04)', () => {
    expect(redactSecrets('token: xoxb-123-abc')).toContain('[REDACTED]')
    expect(redactSecrets('token: xoxb-123-abc')).not.toContain('xoxb-123-abc')
  })

  test('redact de token xapp (S-04)', () => {
    expect(redactSecrets('xapp-1-ABC-123')).toContain('[REDACTED]')
    expect(redactSecrets('xapp-1-ABC-123')).not.toContain('xapp-1-ABC-123')
  })

  test('string sem secrets passa intacta (S-04)', () => {
    expect(redactSecrets('sem segredos')).toBe('sem segredos')
  })

  test('redact de Basic auth header (S-04)', () => {
    expect(redactSecrets('Authorization: Basic dXNlcjpwYXNz')).toContain('[REDACTED]')
  })

  test('redact de token ATATT (S-04)', () => {
    const input = 'token: ATATTxyz123abc.def-456'
    const result = redactSecrets(input)
    expect(result).toContain('[REDACTED]')
    expect(result).not.toContain('ATATTxyz123abc')
  })

  test('redact de Bearer token (S-04)', () => {
    const input = 'Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.payload'
    const result = redactSecrets(input)
    expect(result).toContain('Bearer [REDACTED]')
    expect(result).not.toContain('eyJhbGciOiJSUzI1NiJ9')
  })

  test('redact de URL com credencial (S-04)', () => {
    const input = 'Conectando em https://user:s3cr3t@host.example.com/path'
    const result = redactSecrets(input)
    expect(result).toContain('https://[REDACTED]@host.example.com/path')
    expect(result).not.toContain('s3cr3t')
  })
})
