25 lines
1.6 KiB
TypeScript
25 lines
1.6 KiB
TypeScript
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 }) }
|
||
})
|