mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-04 19:43:43 +08:00
chore: 统一日报时间逻辑
This commit is contained in:
@@ -345,4 +345,14 @@ describe('summary date ranges', () => {
|
||||
endTime: now.getTime() / 1000
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps a scheduled 20:00 today report on the current local calendar day', () => {
|
||||
const now = new Date(2026, 7, 27, 20, 0, 0)
|
||||
const startOfToday = new Date(2026, 7, 27, 0, 0, 0)
|
||||
|
||||
expect(getSummaryDateRangeAt('today', now)).toEqual({
|
||||
startTime: startOfToday.getTime() / 1000,
|
||||
endTime: now.getTime() / 1000
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -41,7 +41,7 @@ const reportSnapshot = {
|
||||
const reportMetadata = {
|
||||
groupName: '测试群',
|
||||
reportDate: '2026-08-12',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 10,
|
||||
activeUsers: 3,
|
||||
timeSpan: '09:00–18:00',
|
||||
@@ -68,7 +68,7 @@ describe('generated report template history', () => {
|
||||
const saved = await saveGeneratedReport({
|
||||
contactId: 'group-md5',
|
||||
contactName: '测试群',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 10,
|
||||
generatedAt: '2026-08-12T10:00:00.000Z',
|
||||
reportDate: '2026-08-11',
|
||||
@@ -114,7 +114,7 @@ describe('generated report template history', () => {
|
||||
const saved = await saveGeneratedReport({
|
||||
contactId: 'legacy-group',
|
||||
contactName: '旧报告',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 5,
|
||||
generatedAt: '2026-08-12T11:00:00.000Z',
|
||||
generatedImage: `data:image/png;base64,${Buffer.from('legacy').toString('base64')}`,
|
||||
@@ -142,7 +142,7 @@ describe('generated report template history', () => {
|
||||
const saved = await saveGeneratedReport({
|
||||
contactId: 'legacy-snapshot-group',
|
||||
contactName: '旧报告快照',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 8,
|
||||
generatedAt: '2026-08-12T12:00:00.000Z',
|
||||
generatedImage: `data:image/png;base64,${Buffer.from('legacy-snapshot').toString('base64')}`,
|
||||
@@ -172,7 +172,7 @@ describe('generated report template history', () => {
|
||||
const saved = await saveGeneratedReport({
|
||||
contactId: 'classic-group',
|
||||
contactName: '经典日报群',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 6,
|
||||
generatedAt: '2026-08-12T13:00:00.000Z',
|
||||
generatedImage: `data:image/png;base64,${Buffer.from('classic').toString('base64')}`,
|
||||
|
||||
@@ -6,7 +6,7 @@ const structuredReport = {
|
||||
id: 'report-1',
|
||||
contactId: 'group-1',
|
||||
contactName: '测试群',
|
||||
dateRange: '今天',
|
||||
dateRange: '今日',
|
||||
messageCount: 10,
|
||||
generatedAt: '2026-08-12T10:00:00.000Z',
|
||||
reportDate: '2026-08-12',
|
||||
|
||||
@@ -254,6 +254,42 @@ describe('scheduled report scheduling', () => {
|
||||
).toContain('微信发送成功')
|
||||
})
|
||||
|
||||
it('passes a selected today range through a scheduled 20:00 execution', async () => {
|
||||
const storageDir = await mkdtemp(join(tmpdir(), 'tracememo-scheduled-report-today-'))
|
||||
let currentTime = new Date(2026, 7, 27, 19, 59, 0)
|
||||
const generateReport = vi.fn(async () => ({
|
||||
success: true,
|
||||
groupName: '研发群',
|
||||
pngPath: '/tmp/generated.png',
|
||||
messageCount: 1
|
||||
}))
|
||||
const service = new ScheduledReportService({
|
||||
storageDir,
|
||||
now: () => currentTime,
|
||||
getCapability: async () => capability,
|
||||
generateReport,
|
||||
saveGeneratedReport: async () => ({ success: true, record: reportRecord('/tmp/saved.png') }),
|
||||
send: async () => ({ success: true, status: capability.senderStatus }),
|
||||
isDatabaseReady: () => true
|
||||
})
|
||||
const created = await service.createTask({
|
||||
name: '今日日报',
|
||||
group: '研发群',
|
||||
target: '研发群@chatroom',
|
||||
scheduleTime: '20:00',
|
||||
reportRange: 'today'
|
||||
})
|
||||
expect(created.success).toBe(true)
|
||||
currentTime = new Date(2026, 7, 27, 20, 0, 0)
|
||||
|
||||
const execution = await runScheduled(service, created.data!.id)
|
||||
|
||||
expect(execution.status).toBe('success')
|
||||
expect(generateReport).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ group: '研发群', range: 'today' })
|
||||
)
|
||||
})
|
||||
|
||||
it('does not send a generated report when history persistence fails', async () => {
|
||||
const storageDir = await mkdtemp(join(tmpdir(), 'tracememo-scheduled-report-history-'))
|
||||
const generatedPath = join(storageDir, 'report.png')
|
||||
|
||||
Reference in New Issue
Block a user