import { AxiosWebClientService } from './webclient.service';

describe('AxiosWebClientService 로그 마스킹', () => {
  it('옥토버 연결 세션 header를 요청·응답 본문에서 숨긴다', () => {
    const service = new AxiosWebClientService();
    expect(
      (service as any).redactPII({
        in: { connHeader: 'request-secret' },
        out: { header: 'response-secret' },
      }),
    ).toEqual({ in: { connHeader: '***' }, out: { header: '***' } });
  });

  it('알림톡 자격증명·수신자·메시지를 숨긴다', () => {
    const service = new AxiosWebClientService();
    expect(
      (service as any).redactPII({
        apikey: 'secret',
        senderkey: 'secret',
        receiver_1: '01012345678',
        message_1: '고객 메시지',
        button_1: '{"linkMo":"https://example.test/token"}',
        subject_1: '보험유니버스',
      }),
    ).toEqual({
      apikey: '***',
      senderkey: '***',
      receiver_1: '***',
      message_1: '***',
      button_1: '***',
      subject_1: '보험유니버스',
    });
  });

  it('알리고 문자 발송의 API 키·수신번호·본문을 숨긴다', () => {
    const service = new AxiosWebClientService();
    expect(
      (service as any).redactPII({
        key: 'secret',
        user_id: 'aligo-user',
        receiver: '01012345678',
        msg: '홍길동 고객님 https://example.test/alimtalk/redirect/a1',
        title: '보험유니버스 진료정보분석 안내',
      }),
    ).toEqual({
      key: '***',
      user_id: 'aligo-user',
      receiver: '***',
      msg: '***',
      title: '보험유니버스 진료정보분석 안내',
    });
  });

  it('업체마다 이름이 다른 문자 인증번호 칸을 숨긴다', () => {
    const service = new AxiosWebClientService();
    expect(
      (service as any).redactPII({
        sessionId: 'session',
        smsAuthNo: '123456',
        reqSMSAuthNo: '123456',
        loginInput: { certificationNum: '123456' },
        step_input: '123456',
        InputList: [{ Input: { 휴대폰_인증번호: '123456' } }],
      }),
    ).toEqual({
      sessionId: 'session',
      smsAuthNo: '***',
      reqSMSAuthNo: '***',
      loginInput: { certificationNum: '***' },
      step_input: '***',
      InputList: [{ Input: { 휴대폰_인증번호: '***' } }],
    });
  });
});
