feat(api, web): тест Telegram из формы, подсказки ошибок API и UX настроек
Docker / build (push) Has been cancelled

Тест отправки использует значения формы без предварительного сохранения; пустой токен при сохранении не затирает сохранённый. Добавлены подсказки по частым ошибкам Telegram API и колонка ошибок в журнале уведомлений.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-06-29 00:54:51 +07:00
co-authored by Cursor
parent 7f91bc3624
commit 05e7bf829e
13 changed files with 319 additions and 72 deletions
+47 -2
View File
@@ -10,8 +10,9 @@ describe('settings telegram test', () => {
beforeEach(async () => {
resetTestDb()
settingsRepository.upsert('settings-main', {
telegramBotToken: 'token',
telegramBotToken: 'db-token',
telegramChatId: '123',
telegramMessageThreadId: '99',
})
app = await buildApp()
})
@@ -22,7 +23,7 @@ describe('settings telegram test', () => {
closeDb()
})
it('returns telegram API error', async () => {
it('returns telegram API error with hint', async () => {
vi.stubGlobal(
'fetch',
vi.fn(async () =>
@@ -34,5 +35,49 @@ describe('settings telegram test', () => {
const body = res.json() as { ok: boolean; error?: string }
expect(body.ok).toBe(false)
expect(body.error).toContain('chat not found')
expect(body.error).toContain('Chat ID')
})
it('uses body overrides and falls back to db token', async () => {
const fetchMock = vi.fn(async () => Response.json({ ok: true }))
vi.stubGlobal('fetch', fetchMock)
const res = await app.inject({
method: 'POST',
url: '/api/settings/telegram/test',
payload: {
telegramChatId: '-100999',
telegramMessageThreadId: '42',
},
})
expect(res.statusCode).toBe(200)
const body = res.json() as { ok: boolean }
expect(body.ok).toBe(true)
const call = fetchMock.mock.calls[0] as [string, RequestInit] | undefined
expect(call).toBeDefined()
const sent = JSON.parse(String(call![1].body)) as {
chat_id: string
message_thread_id: number
}
expect(sent.chat_id).toBe('-100999')
expect(sent.message_thread_id).toBe(42)
})
it('uses body token when provided', async () => {
const fetchMock = vi.fn(async () => Response.json({ ok: true }))
vi.stubGlobal('fetch', fetchMock)
await app.inject({
method: 'POST',
url: '/api/settings/telegram/test',
payload: {
telegramBotToken: 'override-token',
telegramChatId: '-1001',
},
})
const url = String((fetchMock.mock.calls[0] as [string])[0])
expect(url).toContain('botoverride-token/')
})
})