import { describe, expect, it } from 'vitest';

import {
  getVerifyButtonText,
  resolveModelVerificationFeedback,
} from '../model-verification';

describe('model verification helpers', () => {
  it('验证通过时只返回统一成功文案', () => {
    expect(
      resolveModelVerificationFeedback(
        {
          data: { status: 'PASSED' },
          errorCode: 0,
        },
        'chatModel',
      ),
    ).toEqual({
      dimension: undefined,
      message: '验证通过',
      status: 'success',
    });
  });

  it('旧版部分通过结果也收敛为统一成功文案', () => {
    const feedback = resolveModelVerificationFeedback(
      {
        data: {
          message: '连接成功，流式响应不可用，可关闭智能体的模型流式响应。',
          status: 'PARTIAL',
        },
        errorCode: 0,
      },
      'chatModel',
    );

    expect(feedback.status).toBe('success');
    expect(feedback.message).toBe('验证通过');
    expect(getVerifyButtonText('warning')).toBe('验证通过');
  });

  it('向量模型验证保留维度结果', () => {
    expect(
      resolveModelVerificationFeedback(
        { data: { dimension: 1024 }, errorCode: 0 },
        'embeddingModel',
      ),
    ).toEqual({
      dimension: 1024,
      message: '验证通过',
      status: 'success',
    });
  });

  it('接口失败时返回错误状态', () => {
    expect(
      resolveModelVerificationFeedback(
        { errorCode: 1, message: '密钥无效' },
        'chatModel',
      ),
    ).toEqual({ message: '密钥无效', status: 'error' });
  });
});
