+ [misc] Add unit tests for aiappModel::getHistoryMessages() 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 55d4257847
commit 75ec54884c
3 changed files with 78 additions and 0 deletions
@@ -91,4 +91,20 @@ class aiappTest
return true;
}
/**
* Test getHistoryMessages method.
*
* @param string $appID
* @param int $limit
* @access public
* @return mixed
*/
public function getHistoryMessagesTest($appID, $limit = 20)
{
$result = $this->objectModel->getHistoryMessages($appID, $limit);
if(dao::isError()) return dao::getError();
return $result;
}
}
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env php
<?php
/**
title=测试 aiappModel::getHistoryMessages();
timeout=0
cid=0
- 步骤1:查询不存在消息的应用ID @0
- 先插入测试数据 @1
- 再插入一条 @1
- 步骤2:查询存在消息的应用ID @2
- 步骤3:测试限制数量参数功能 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/aiapp.unittest.class.php';
zenData('ai_message')->gen(0);
su('admin');
$aiappTest = new aiappTest();
r(count($aiappTest->getHistoryMessagesTest(1, 20))) && p() && e('0'); // 步骤1:查询不存在消息的应用ID
r($aiappTest->saveMiniProgramMessageTest('1', 'req', 'test message 1')) && p() && e('1'); // 先插入测试数据
r($aiappTest->saveMiniProgramMessageTest('1', 'res', 'test response 1')) && p() && e('1'); // 再插入一条
r(count($aiappTest->getHistoryMessagesTest(1, 20))) && p() && e('2'); // 步骤2:查询存在消息的应用ID
r(count($aiappTest->getHistoryMessagesTest(1, 1))) && p() && e('1'); // 步骤3:测试限制数量参数功能
@@ -0,0 +1,31 @@
---
title: AI消息表测试数据 - getHistoryMessages方法
desc: 用于测试getHistoryMessages方法的AI消息数据
author: Claude
version: 1.0
fields:
- field: id
note: 消息ID
range: 1-30
- field: appID
note: 应用ID
range: 1{10}, 2{5}, 3{8}, 999{2}, 1000{5}
- field: user
note: 用户ID
range: 1{15}, 2{10}, 3{5}
- field: type
note: 消息类型
range: req{10}, res{15}, ntf{5}
- field: content
note: 消息内容
range: "测试消息内容{5}", "用户请求消息{8}", "系统响应消息{10}", "通知消息{7}"
- field: createdDate
note: 创建时间
range: (-7D)-(-1D):1D
format: "YYYY-MM-DD hh:mm:ss"