aero-mail/tests/mail-agent-baseline.test.ts

29 lines
1.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { captureFolderBaselines, getFolderBaselineKey, isExistingMessage } from '../src/main/services/mail-agent-baseline.ts'
import type { Folder } from '../src/shared/types/folder.ts'
import type { SpecialFolderRole } from '../src/shared/types/folder.ts'
function createFolder(nextUid: number, validity: string): Folder {
return { id: 'INBOX', name: 'Входящие', role: 'inbox' as SpecialFolderRole, parentId: null, totalCount: 0, unreadCount: 0, children: [], uidNext: nextUid, uidValidity: validity }
}
test('сохраняет первую границу и не сдвигает её при следующих проверках', (): void => {
const key: string = getFolderBaselineKey('account', 'INBOX')
const first = captureFolderBaselines('account', [createFolder(101, '1')], {})
const next = captureFolderBaselines('account', [createFolder(110, '1')], first)
assert.deepEqual(next[key], { accountId: 'account', folderId: 'INBOX', nextUid: 101, uidValidity: '1' })
assert.equal(isExistingMessage('100', next[key]), true)
assert.equal(isExistingMessage('101', next[key]), false)
})
test('новая папка с пустым ящиком не пропускает первое поступившее письмо', (): void => {
const baseline = captureFolderBaselines('account', [createFolder(1, '1')], {})
assert.equal(isExistingMessage('1', baseline[getFolderBaselineKey('account', 'INBOX')]), false)
})
test('пересозданная папка получает новую границу при изменении UIDVALIDITY', (): void => {
const old = captureFolderBaselines('account', [createFolder(101, '1')], {})
const next = captureFolderBaselines('account', [createFolder(4, '2')], old)
assert.deepEqual(next[getFolderBaselineKey('account', 'INBOX')], { accountId: 'account', folderId: 'INBOX', nextUid: 4, uidValidity: '2' })
})