+ [misc] Add unit tests for aiModel::checkAssistantDuplicate() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:09 +08:00
co-authored by Claude
parent 5e678db17b
commit e4f1e10e7d
3 changed files with 99 additions and 0 deletions
+16
View File
@@ -1472,4 +1472,20 @@ class aiTest
return $result;
}
/**
* Test checkAssistantDuplicate method.
*
* @param string $assistantName
* @param int $modelId
* @access public
* @return mixed
*/
public function checkAssistantDuplicateTest($assistantName = null, $modelId = null)
{
$result = $this->objectModel->checkAssistantDuplicate($assistantName, $modelId);
if(dao::isError()) return dao::getError();
return $result;
}
}
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env php
<?php
/**
title=测试 aiModel::checkAssistantDuplicate();
timeout=0
cid=0
- 执行aiTest模块的checkAssistantDuplicateTest方法,参数是'Assistant1', 1
- 属性name @Assistant1
- 属性modelId @1
- 执行aiTest模块的checkAssistantDuplicateTest方法,参数是'NonExistentAssistant', 1 @0
- 执行aiTest模块的checkAssistantDuplicateTest方法,参数是'Assistant1', 99 @0
- 执行aiTest模块的checkAssistantDuplicateTest方法,参数是'', 1 @0
- 执行aiTest模块的checkAssistantDuplicateTest方法,参数是'DeletedAssistant', 1 @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/ai.unittest.class.php';
$table = zenData('ai_assistant');
$table->id->range('1-5');
$table->name->range('Assistant1{2},Assistant2,Assistant3,DeletedAssistant');
$table->modelId->range('1{3},2{2}');
$table->desc->range('Test assistant description');
$table->systemMessage->range('You are a helpful assistant');
$table->greetings->range('Hello! How can I help you today?');
$table->icon->range('coding-1');
$table->enabled->range('1');
$table->createdDate->range('`2024-01-01 10:00:00`');
$table->publishedDate->range('`2024-01-01 10:00:00`');
$table->deleted->range('0{4},1');
$table->gen(5);
su('admin');
$aiTest = new aiTest();
r($aiTest->checkAssistantDuplicateTest('Assistant1', 1)) && p('name,modelId') && e('Assistant1,1');
r($aiTest->checkAssistantDuplicateTest('NonExistentAssistant', 1)) && p() && e('0');
r($aiTest->checkAssistantDuplicateTest('Assistant1', 99)) && p() && e('0');
r($aiTest->checkAssistantDuplicateTest('', 1)) && p() && e('0');
r($aiTest->checkAssistantDuplicateTest('DeletedAssistant', 1)) && p() && e('0');
@@ -0,0 +1,38 @@
---
title: AI助手重复检查测试数据
desc: 用于测试checkAssistantDuplicate方法的测试数据
fields:
- field: id
note: 助手ID
range: 1-5
- field: name
note: 助手名称
range: Assistant1{2},Assistant2,Assistant3,DeletedAssistant
- field: modelId
note: 模型ID
range: 1{3},2{2}
- field: desc
note: 助手描述
range: Test assistant description{5}
- field: systemMessage
note: 系统消息
range: You are a helpful assistant{5}
- field: greetings
note: 问候语
range: Hello! How can I help you today?{5}
- field: icon
note: 图标
range: coding-1{5}
- field: enabled
note: 是否启用
range: '1'{5}
- field: createdDate
note: 创建时间
range: '2024-01-01 10:00:00'{5}
- field: publishedDate
note: 发布时间
range: '2024-01-01 10:00:00'{5}
- field: deleted
note: 是否删除
range: '0'{4},'1'