mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-09-15 01:03:08 +00:00
fix(support): не склеивать t.me со ссылкой на внешний хелпдеск
SUPPORT_USERNAME на бэке принимает и @username, и произвольный URL. Кабинет же во всех трёх ветках клеил `https://t.me/${support_username}`, из-за чего внешний хелпдеск превращался в https://t.me/https://help.example.com и не открывался. Бэк теперь отдаёт контакт разрезолвленным (support_url + contact_is_telegram) — клеить на клиенте нечего. Логика вынесена в resolveSupportContact: три копии склейки (profile, fallback и карточка режима both) заменены одним вызовом. Старый бэк не шлёт support_url, для него сохранено прежнее поведение — новый фронт не ломается на неподнятом бэкенде. Заодно ушли три non-null assertion на support_username.
This commit is contained in:
69
src/utils/supportContact.test.ts
Normal file
69
src/utils/supportContact.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { SupportConfig } from '../types';
|
||||
import { resolveSupportContact } from './supportContact';
|
||||
|
||||
/**
|
||||
* Кабинет склеивал `https://t.me/${support_username}` и ломал внешний хелпдеск:
|
||||
* SUPPORT_USERNAME принимает и `@user`, и произвольный URL, поэтому из
|
||||
* `https://help.example.com` получалось `https://t.me/https://help.example.com`.
|
||||
* Бэк отдаёт контакт уже разрезолвленным — клеить на клиенте больше нечего.
|
||||
*/
|
||||
|
||||
const config = (overrides: Partial<SupportConfig>): SupportConfig => ({
|
||||
tickets_enabled: true,
|
||||
support_type: 'both',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
describe('resolveSupportContact', () => {
|
||||
it('внешний хелпдеск открывается как обычная ссылка, без t.me', () => {
|
||||
const target = resolveSupportContact(
|
||||
config({
|
||||
support_url: 'https://help.example.com',
|
||||
support_username: 'https://help.example.com',
|
||||
contact_is_telegram: false,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(target).toEqual({ kind: 'external', url: 'https://help.example.com' });
|
||||
expect(target.url).not.toContain('t.me');
|
||||
});
|
||||
|
||||
it('телеграм-контакт открывается через telegram-ссылку', () => {
|
||||
const target = resolveSupportContact(
|
||||
config({
|
||||
support_url: 'https://t.me/help',
|
||||
support_username: '@help',
|
||||
contact_is_telegram: true,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(target).toEqual({ kind: 'telegram', url: 'https://t.me/help' });
|
||||
});
|
||||
|
||||
describe('старый бэк без support_url — прежнее поведение', () => {
|
||||
it.each([
|
||||
['@help', 'https://t.me/help'],
|
||||
['help', 'https://t.me/help'],
|
||||
])('%s -> %s', (username, expected) => {
|
||||
const target = resolveSupportContact(config({ support_username: username }));
|
||||
|
||||
expect(target).toEqual({ kind: 'telegram', url: expected });
|
||||
});
|
||||
|
||||
it('контакт вообще не задан — дефолтный @support', () => {
|
||||
expect(resolveSupportContact(config({}))).toEqual({
|
||||
kind: 'telegram',
|
||||
url: 'https://t.me/support',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('support_url без contact_is_telegram трактуется как телеграм', () => {
|
||||
// Комбинация недостижима с текущим бэком, но деградировать надо в старое
|
||||
// поведение, а не в переход по внешней ссылке.
|
||||
const target = resolveSupportContact(config({ support_url: 'https://t.me/help' }));
|
||||
|
||||
expect(target.kind).toBe('telegram');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user