import { describe, expect, it } from 'vitest'
import { maskEmail, maskName, maskPhone, maskPostcode, presentAddress, redactArgs } from './pii.js'

describe('PII masking', () => {
  it('masks contact details', () => {
    expect(maskEmail('jane.smith@example.com')).toBe('j***@example.com')
    expect(maskName('jane', 'Smith')).toBe('J. S.')
    expect(maskPhone('+44 7700 900123')).toBe('***123')
    expect(maskPostcode('sw1a 1aa')).toBe('SW1A ***')
    expect(maskPostcode('10115')).toBe('10***')
  })

  it('drops street and email from masked addresses but keeps city/country', () => {
    const a = presentAddress({ firstname: 'Jane', lastname: 'Smith', street: ['1 High St'], city: 'Leeds', postcode: 'LS1 4AP', country_id: 'GB', email: 'j@x.com', telephone: '0113 496 0000' }, false)
    expect(a).toEqual({ name: 'J. S.', city: 'Leeds', region: null, postcode: 'LS1 ***', country: 'GB', telephone: '***000' })
  })

  it('redacts email-like arguments for the audit log', () => {
    expect(redactArgs({ customer_email: 'jane@example.com', limit: 5 })).toEqual({ customer_email: 'j***@example.com', limit: 5 })
  })
})
