feat(api, web): тест Telegram из формы, подсказки ошибок API и UX настроек
Docker / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Тест отправки использует значения формы без предварительного сохранения; пустой токен при сохранении не затирает сохранённый. Добавлены подсказки по частым ошибкам Telegram API и колонка ошибок в журнале уведомлений. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { settingsRepository } from './settings.js'
|
||||
import { resetTestDb } from '../test-setup.js'
|
||||
|
||||
describe('settingsRepository', () => {
|
||||
beforeEach(() => {
|
||||
resetTestDb()
|
||||
})
|
||||
|
||||
it('preserves telegram token on update when token empty', () => {
|
||||
settingsRepository.upsert('settings-main', {
|
||||
telegramBotToken: 'secret-token',
|
||||
telegramChatId: '-100123',
|
||||
})
|
||||
const updated = settingsRepository.upsert('settings-main', {
|
||||
telegramBotToken: '',
|
||||
syncIntervalMinutes: 30,
|
||||
})
|
||||
expect(updated.telegramBotTokenSet).toBe(true)
|
||||
expect(settingsRepository.getRow('settings-main')?.telegramBotToken).toBe('secret-token')
|
||||
expect(updated.syncIntervalMinutes).toBe(30)
|
||||
})
|
||||
|
||||
it('replaces telegram token when new value provided', () => {
|
||||
settingsRepository.upsert('settings-main', {
|
||||
telegramBotToken: 'old-token',
|
||||
})
|
||||
settingsRepository.upsert('settings-main', {
|
||||
telegramBotToken: 'new-token',
|
||||
})
|
||||
expect(settingsRepository.getRow('settings-main')?.telegramBotToken).toBe('new-token')
|
||||
})
|
||||
})
|
||||
@@ -95,7 +95,9 @@ function buildValues(id: string, existing: Row | undefined, r: SettingsInput) {
|
||||
? Math.max(60, Number(r.syncTariffsIntervalMinutes) || 1440)
|
||||
: existing?.syncTariffsIntervalMinutes ?? 1440,
|
||||
telegramBotToken:
|
||||
r.telegramBotToken !== undefined ? r.telegramBotToken || '' : existing?.telegramBotToken ?? '',
|
||||
r.telegramBotToken !== undefined && String(r.telegramBotToken || '').trim() !== ''
|
||||
? r.telegramBotToken
|
||||
: existing?.telegramBotToken ?? '',
|
||||
telegramChatId:
|
||||
r.telegramChatId !== undefined ? r.telegramChatId || '' : existing?.telegramChatId ?? '',
|
||||
telegramMessageThreadId:
|
||||
|
||||
@@ -26,3 +26,11 @@ export const settingsSchema = z.object({
|
||||
})
|
||||
|
||||
export type Settings = z.infer<typeof settingsSchema>
|
||||
|
||||
export const telegramTestBodySchema = z.object({
|
||||
telegramBotToken: z.string().optional(),
|
||||
telegramChatId: z.string().optional(),
|
||||
telegramMessageThreadId: z.string().optional(),
|
||||
})
|
||||
|
||||
export type TelegramTestBody = z.infer<typeof telegramTestBodySchema>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Command as CommandPrimitive } from "cmdk"
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user