53 lines
2.4 KiB
TypeScript
53 lines
2.4 KiB
TypeScript
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { MailAgentNotifications } from '../src/main/services/mail-agent-notifications.ts'
|
||
import type { IncomingMail } from '../src/main/services/mail-agent-notifications.ts'
|
||
|
||
function createMail(id: string): IncomingMail {
|
||
return {
|
||
accountId: 'account', folderId: 'INBOX',
|
||
envelope: {
|
||
id, folderId: 'INBOX', subject: 'Вопрос', date: '2026-11-16',
|
||
from: { name: 'Коллега', email: 'other@example.org' }, to: [], cc: [],
|
||
flags: { seen: false, flagged: false, answered: false, deleted: false },
|
||
hasAttachments: false, snippet: ''
|
||
}
|
||
}
|
||
}
|
||
|
||
test('при доступной модели письмо ожидает решения ИИ', (): void => {
|
||
const notifications: MailAgentNotifications = new MailAgentNotifications()
|
||
const mail: IncomingMail = createMail('1')
|
||
assert.equal(notifications.filter(mail), true)
|
||
assert.equal(notifications.complete(mail), true)
|
||
assert.deepEqual(notifications.fail(), [])
|
||
})
|
||
|
||
test('при ошибке возвращает все ожидавшие письма для обычных уведомлений', (): void => {
|
||
const notifications: MailAgentNotifications = new MailAgentNotifications()
|
||
const first: IncomingMail = createMail('1')
|
||
const second: IncomingMail = createMail('2')
|
||
notifications.filter(first)
|
||
notifications.filter(second)
|
||
assert.deepEqual(notifications.fail(), [first, second])
|
||
assert.deepEqual(notifications.fail(), [])
|
||
assert.equal(notifications.filter(createMail('3')), false)
|
||
})
|
||
|
||
test('после восстановления исключает повтор уже показанного уведомления', (): void => {
|
||
const notifications: MailAgentNotifications = new MailAgentNotifications()
|
||
const first: IncomingMail = createMail('1')
|
||
notifications.filter(first)
|
||
notifications.fail()
|
||
const second: IncomingMail = createMail('2')
|
||
assert.equal(notifications.filter(second), false)
|
||
assert.equal(notifications.complete(first), false)
|
||
assert.equal(notifications.filter(createMail('3')), true)
|
||
assert.equal(notifications.complete(second), false)
|
||
})
|
||
|
||
test('ошибка модели не создаёт уведомлений об архивных письмах', (): void => {
|
||
const notifications: MailAgentNotifications = new MailAgentNotifications()
|
||
assert.deepEqual(notifications.fail(), [])
|
||
assert.equal(notifications.complete(createMail('old')), true)
|
||
})
|