fix(frontend): clean test validation output
This commit is contained in:
1 parent
1c255fc00c
commit
1f846c3cb2
9 files changed
+64
-13
No files matched your search
@@ -4,7 +4,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { HttpUtil, Msg } from '@/utils';
|
||||
import { parseMsg } from '@/utils/zodValidate';
|
||||
import { AllSetting } from '@/models/setting';
|
||||
import { AllSettingSchema, type AllSettingInput } from '@/schemas/setting';
|
||||
import { AllSettingResponseSchema, AllSettingSchema, type AllSettingInput } from '@/schemas/setting';
|
||||
import { keys } from '@/api/queryKeys';
|
||||
import { useServerDraft } from '@/hooks/useServerDraft';
|
||||
|
||||
@@ -17,7 +17,7 @@ type SettingSaveResult = {
|
||||
async function fetchAllSetting(): Promise<AllSettingInput | null> {
|
||||
const msg = await HttpUtil.post('/panel/api/setting/all', undefined, { silent: true });
|
||||
if (!msg?.success) throw new Error(msg?.msg || 'Failed to fetch settings');
|
||||
const validated = parseMsg(msg, AllSettingSchema, 'setting/all');
|
||||
const validated = parseMsg(msg, AllSettingResponseSchema, 'setting/all');
|
||||
return validated.obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,15 @@ export const AllSettingSchema = z.object({
|
||||
|
||||
export type AllSettingInput = z.infer<typeof AllSettingSchema>;
|
||||
|
||||
// Existing installations can contain regex values saved before the backend
|
||||
// enforced its 2,048-character limit. Accept those values when reading so the
|
||||
// settings page can display and let users correct them, while keeping the
|
||||
// stricter schema above for outgoing updates.
|
||||
export const AllSettingResponseSchema = AllSettingSchema.extend({
|
||||
subJsonUserAgentRegex: z.string().optional(),
|
||||
subClashUserAgentRegex: z.string().optional(),
|
||||
});
|
||||
|
||||
export const FactoryDefaultsSchema = z.record(z.string(), z.string());
|
||||
|
||||
export type FactoryDefaults = z.infer<typeof FactoryDefaultsSchema>;
|
||||
@@ -99,7 +99,11 @@ describe('useClients query gating', () => {
|
||||
});
|
||||
|
||||
it('reports settingsReady even when the settings request fails, so the page can still render', async () => {
|
||||
vi.spyOn(HttpUtil, 'get').mockResolvedValue(new Msg(true, '', emptyPage));
|
||||
vi.spyOn(HttpUtil, 'get').mockImplementation(async (url: string) => new Msg(
|
||||
true,
|
||||
'',
|
||||
url.includes('/inbounds/options') ? [] : emptyPage,
|
||||
));
|
||||
vi.spyOn(HttpUtil, 'post').mockResolvedValue(new Msg(false, 'boom', null));
|
||||
const { result } = renderHook(() => useClients(), { wrapper: wrapperFor() });
|
||||
|
||||
|
||||
Loaded 3 of 9 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user