feat(history): establish Telegram SaaS platform foundation

This commit is contained in:
wmq
2026-07-27 23:03:00 +08:00
parent cf0eed46c3
commit cd06d049fe
92 changed files with 5608 additions and 3749 deletions
+44
View File
@@ -0,0 +1,44 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { countBy, dateKey, percent, telegramAttachment } from '../src/business.js'
test('Telegram 图片、文档、语音和贴纸映射为可下载文件', () => {
assert.deepEqual(
telegramAttachment({
'@type': 'messagePhoto',
photo: { sizes: [{ photo: { id: 11, size: 2048 } }] },
}),
{
telegramFileId: 11,
attachmentName: 'telegram-photo-11.jpg',
attachmentMimeType: 'image/jpeg',
attachmentSize: 2048,
},
)
assert.equal(telegramAttachment({
'@type': 'messageDocument',
document: { file_name: 'quote.pdf', mime_type: 'application/pdf', document: { id: 12, size: 4096 } },
}).attachmentMimeType, 'application/pdf')
assert.equal(telegramAttachment({
'@type': 'messageVoiceNote',
voice_note: { duration: 8, voice: { id: 13, expected_size: 1024 } },
}).duration, 8)
assert.equal(telegramAttachment({
'@type': 'messageSticker',
sticker: { emoji: '👍', format: { '@type': 'stickerFormatWebp' }, sticker: { id: 14, size: 512 } },
}).attachmentMimeType, 'image/webp')
})
test('业务指标工具处理百分比、分组和无效日期', () => {
assert.equal(percent(3, 8), 37.5)
assert.equal(percent(1, 0), 0)
assert.equal(dateKey('invalid'), '')
assert.equal(dateKey('2026-07-27T12:30:00Z'), '2026-07-27')
assert.deepEqual(
Object.fromEntries(countBy([{ stage: 'new' }, { stage: 'new' }, { stage: 'won' }], 'stage')),
{ new: 2, won: 1 },
)
})