Files
simplex-chat/apps/simplex-support-bot/test/__mocks__/simplex-chat.js
T
sh fefdea8ed0 support bot, bots: paginate chat scan (#6935)
* bots: document APIGetChats command and CRApiChats response

* bots: regenerate API docs and TypeScript types

* simplex-chat-nodejs: add apiGetChats

* support bot: avoid OOM on large databases

apiListGroups / apiListContacts return every record in one response and
overflow V8's string allocation on large DBs. Replace list-then-find-by-id
patterns with apiGetChat(type, id, 0) lookups, and the one genuine scan
(refreshAllCards) with paginated apiGetChats, count=1000.

* support bot: update test assertions to match current message text

* bots: simplify PaginationByTime, expose only PTLast

* simplex-chat-nodejs: bump types and nodejs versions
2026-05-06 08:54:36 +01:00

37 lines
967 B
JavaScript

// Mock for simplex-chat — prevents native addon from loading
function ciContentText(chatItem) {
const c = chatItem.content
if (c.type === "sndMsgContent" || c.type === "rcvMsgContent") return c.msgContent.text
return undefined
}
function ciBotCommand(chatItem) {
const text = ciContentText(chatItem)?.trim()
if (text) {
const r = text.match(/\/([^\s]+)(.*)/)
if (r && r.length >= 3) return {keyword: r[1], params: r[2].trim()}
}
return undefined
}
function contactAddressStr(link) {
return link.connShortLink || link.connFullLink
}
// Mirrors core.ChatAPIError so isChatNotFound's instanceof check passes when
// MockChatApi throws. Tests should construct these directly.
class ChatAPIError extends Error {
constructor(message, chatError) {
super(message)
this.chatError = chatError
}
}
module.exports = {
api: {ChatApi: {}},
bot: {},
core: {ChatAPIError},
util: {ciContentText, ciBotCommand, contactAddressStr},
}