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('warning');
    expect(feedback.message).toContain('流式响应不可用');
    expect(getVerifyButtonText('warning')).toBe('流式不可用');
  });

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

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