From 75ec54884c4caffcf66a4122334e38c8511c32fe Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 7 Sep 2025 00:04:31 +0800 Subject: [PATCH] + [misc] Add unit tests for aiappModel::getHistoryMessages() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../aiapp/test/lib/aiapp.unittest.class.php | 16 ++++++++++ .../aiapp/test/model/gethistorymessages.php | 31 +++++++++++++++++++ .../yaml/ai_message_gethistorymessages.yaml | 31 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100755 module/aiapp/test/model/gethistorymessages.php create mode 100644 module/aiapp/test/model/yaml/ai_message_gethistorymessages.yaml diff --git a/module/aiapp/test/lib/aiapp.unittest.class.php b/module/aiapp/test/lib/aiapp.unittest.class.php index 1d2a0edc85..01f25fb284 100644 --- a/module/aiapp/test/lib/aiapp.unittest.class.php +++ b/module/aiapp/test/lib/aiapp.unittest.class.php @@ -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; + } } \ No newline at end of file diff --git a/module/aiapp/test/model/gethistorymessages.php b/module/aiapp/test/model/gethistorymessages.php new file mode 100755 index 0000000000..3ec9f2aaf5 --- /dev/null +++ b/module/aiapp/test/model/gethistorymessages.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +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:测试限制数量参数功能 \ No newline at end of file diff --git a/module/aiapp/test/model/yaml/ai_message_gethistorymessages.yaml b/module/aiapp/test/model/yaml/ai_message_gethistorymessages.yaml new file mode 100644 index 0000000000..4d5e684750 --- /dev/null +++ b/module/aiapp/test/model/yaml/ai_message_gethistorymessages.yaml @@ -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" \ No newline at end of file