mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-09 14:16:07 +00:00
9b91f0f42e
Fold the standalone 3x-ui-docs project (Next.js 16 + Fumadocs, deployed to docs.sanaei.dev) into docs/ so the panel and its documentation share a single source of truth, the way sing-box keeps its docs in-tree. The old repo becomes redundant and can be retired. - Import the full site under docs/ (app, components, content, lib, public, scripts, config). The self-contained pnpm project sits alongside the existing engineering notes with no filename collisions. - Re-point "Edit on GitHub" links from MHSanaei/3x-ui-docs to this repo's docs/content/docs path (docs/lib/shared.ts, docs/app/.../page.tsx). - Add docs-ci.yml and docs-deploy.yml under .github/workflows/, scoped to docs/** and run with working-directory: docs, since GitHub only runs workflows from the repo-root .github/. deploy-static.yml's GitHub Pages publish (CNAME docs.sanaei.dev) carries over unchanged. Follow-up (outside this commit): attach the docs.sanaei.dev custom domain to this repository's Pages (or set the Vercel project's root directory to docs), confirm the site is live from the monorepo, then delete MHSanaei/3x-ui-docs.
100 lines
3.0 KiB
TypeScript
100 lines
3.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
validateBotToken,
|
|
parseAdminIds,
|
|
validateRunTime,
|
|
telegramApiBase,
|
|
renderMessageTemplate,
|
|
buildBotConfigSummary,
|
|
} from './telegram';
|
|
|
|
const VALID_TOKEN = '123456789:AAH-abcdefghijklmnopqrstuvwxyz0123456';
|
|
|
|
describe('validateBotToken', () => {
|
|
it('accepts a BotFather-format token and extracts the bot id', () => {
|
|
const r = validateBotToken(VALID_TOKEN);
|
|
expect(r.valid).toBe(true);
|
|
expect(r.botId).toBe('123456789');
|
|
});
|
|
|
|
it('rejects a token with no colon', () => {
|
|
expect(validateBotToken('123456789AAH').valid).toBe(false);
|
|
});
|
|
|
|
it('rejects a too-short secret', () => {
|
|
expect(validateBotToken('123:short').valid).toBe(false);
|
|
});
|
|
|
|
it('rejects an empty token', () => {
|
|
expect(validateBotToken(' ').valid).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('parseAdminIds', () => {
|
|
it('splits a comma list into integer ids', () => {
|
|
expect(parseAdminIds('111, 222')).toEqual({ ids: [111, 222], invalid: [] });
|
|
});
|
|
|
|
it('accepts negative group ids and captures invalid entries', () => {
|
|
expect(parseAdminIds('-1001234567, abc, 42')).toEqual({ ids: [-1001234567, 42], invalid: ['abc'] });
|
|
});
|
|
|
|
it('returns empty for blank input', () => {
|
|
expect(parseAdminIds(' ')).toEqual({ ids: [], invalid: [] });
|
|
});
|
|
});
|
|
|
|
describe('validateRunTime', () => {
|
|
it('accepts the @daily macro', () => {
|
|
expect(validateRunTime('@daily')).toMatchObject({ valid: true, kind: 'macro' });
|
|
});
|
|
|
|
it('accepts an @every duration', () => {
|
|
expect(validateRunTime('@every 8h')).toMatchObject({ valid: true, kind: 'every' });
|
|
});
|
|
|
|
it('accepts a 5-field cron', () => {
|
|
expect(validateRunTime('0 0 * * *')).toMatchObject({ valid: true, kind: 'cron' });
|
|
});
|
|
|
|
it('accepts a 6-field cron', () => {
|
|
expect(validateRunTime('*/30 * * * * *')).toMatchObject({ valid: true, kind: 'cron' });
|
|
});
|
|
|
|
it('rejects an unknown macro', () => {
|
|
expect(validateRunTime('@bogus').valid).toBe(false);
|
|
});
|
|
|
|
it('rejects a malformed @every duration', () => {
|
|
expect(validateRunTime('@every 8x').valid).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('telegramApiBase', () => {
|
|
it('builds the bot API base URL', () => {
|
|
expect(telegramApiBase(VALID_TOKEN)).toBe(`https://api.telegram.org/bot${VALID_TOKEN}`);
|
|
});
|
|
});
|
|
|
|
describe('renderMessageTemplate', () => {
|
|
it('substitutes known variables', () => {
|
|
expect(renderMessageTemplate('Host {{host}} up {{uptime}}', { host: 'srv', uptime: '3d' })).toBe(
|
|
'Host srv up 3d',
|
|
);
|
|
});
|
|
|
|
it('leaves unknown variables literal', () => {
|
|
expect(renderMessageTemplate('{{a}} {{b}}', { a: 'x' })).toBe('x {{b}}');
|
|
});
|
|
});
|
|
|
|
describe('buildBotConfigSummary', () => {
|
|
it('emits the panel settings keys with admin ids joined', () => {
|
|
const s = buildBotConfigSummary({ token: VALID_TOKEN, adminIds: '111, 222', runTime: '@daily' });
|
|
expect(s.tgBotEnable).toBe(true);
|
|
expect(s.tgBotToken).toBe(VALID_TOKEN);
|
|
expect(s.tgBotChatId).toBe('111,222');
|
|
expect(s.tgRunTime).toBe('@daily');
|
|
});
|
|
});
|