aero-mail/tests/compose-settings.test.ts
2026-11-17 16:36:25 +07:00

25 lines
1.6 KiB
TypeScript
Raw 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 { mkdtemp, rm } from 'node:fs/promises'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import Conf from 'conf'
import { loadAgentTestModule } from './helpers/agent-module.ts'
import type { ComposeSettings } from '../src/shared/types/compose.ts'
import type { ComposeSettingsService } from '../src/main/services/compose-settings-service.ts'
test('подпись сохраняется между экземплярами сервиса и отключается пустым текстом', async (): Promise<void> => {
const directory: string = await mkdtemp(join(tmpdir(), 'aero-signature-'))
const environment = await loadAgentTestModule()
try {
const module = await environment.server.ssrLoadModule('/src/main/services/compose-settings-service.ts') as { ComposeSettingsService: typeof ComposeSettingsService }
const createStore = (): Conf<ComposeSettings> => new Conf<ComposeSettings>({ cwd: directory, configName: 'compose-settings', defaults: { signature: '' } })
const first = new module.ComposeSettingsService(createStore())
first.save({ signature: 'С уважением,\nИван' })
const reopened = new module.ComposeSettingsService(createStore())
assert.equal(reopened.get().signature, 'С уважением,\nИван')
reopened.save({ signature: '' })
assert.equal(new module.ComposeSettingsService(createStore()).get().signature, '')
assert.throws(() => reopened.save({ signature: 'x'.repeat(10_001) }), /до 10 000/)
} finally { await environment.server.close(); await rm(directory, { recursive: true, force: true }) }
})