fix(test): correct TypeScript types in frontend test mocks

- Use RSS type instead of non-existent RSSItem/RSSResponse
- Add expire field to mockLoginSuccess
- Replace offset with episode_offset/season_offset in mockBangumiAPI
- Add needs_review_reason field to mockBangumiAPI
- Add missing RSS fields (connection_status, last_checked_at, last_error)
- Fix generic types in test utilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
EstrellaXD
2026-01-26 16:24:31 +01:00
parent a137b54b85
commit f22f5c657f
4 changed files with 866 additions and 864 deletions

1700
backend/uv.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,7 @@ import {
describe('Bangumi API Logic', () => {
describe('getAll transformation (string to array)', () => {
// This transformation happens when receiving data from API
const transformApiResponse = (item: { filter: string; rss_link: string }) => ({
const transformApiResponse = <T extends { filter: string; rss_link: string }>(item: T) => ({
...item,
filter: item.filter.split(','),
rss_link: item.rss_link.split(','),

View File

@@ -14,20 +14,21 @@ interface Options<T = unknown> {
onFinally?: () => void;
}
type AnyAsyncFunction<TData = unknown> = (...args: unknown[]) => Promise<TData>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyAsyncFunction = (...args: any[]) => Promise<any>;
function createUseApi<TApi extends AnyAsyncFunction>(
api: TApi,
options: Options = {}
options: Options<Awaited<ReturnType<TApi>>> = {}
) {
let data: Awaited<ReturnType<TApi>> | undefined;
let isLoading = false;
const execute = async (...params: Parameters<TApi>) => {
const execute = async (...params: Parameters<TApi>): Promise<void> => {
options.onBeforeExecute?.();
isLoading = true;
try {
const res = await api(...params);
const res: Awaited<ReturnType<TApi>> = await api(...params);
data = res;
options.onSuccess?.(res);
} catch (err) {

View File

@@ -3,7 +3,7 @@
*/
import type { BangumiAPI, BangumiRule } from '#/bangumi';
import type { RSSItem, RSSResponse } from '#/rss';
import type { RSS } from '#/rss';
import type { ApiSuccess } from '#/api';
import type { LoginSuccess } from '#/auth';
@@ -14,6 +14,7 @@ import type { LoginSuccess } from '#/auth';
export const mockLoginSuccess: LoginSuccess = {
access_token: 'mock_access_token_123',
token_type: 'bearer',
expire: Date.now() + 86400000, // 24 hours from now
};
export const mockApiSuccess: ApiSuccess = {
@@ -37,7 +38,8 @@ export const mockBangumiAPI: BangumiAPI = {
source: 'Web',
subtitle: 'CHT',
eps_collect: false,
offset: 0,
episode_offset: 0,
season_offset: 0,
filter: '720',
rss_link: 'https://mikanani.me/RSS/test',
poster_link: '/posters/test.jpg',
@@ -48,13 +50,13 @@ export const mockBangumiAPI: BangumiAPI = {
archived: false,
air_weekday: 3,
needs_review: false,
needs_review_reason: null,
};
export const mockBangumiRule: BangumiRule = {
...mockBangumiAPI,
filter: ['720'],
rss_link: ['https://mikanani.me/RSS/test'],
air_weekday: 3,
};
export const mockBangumiList: BangumiAPI[] = [
@@ -81,16 +83,19 @@ export const mockBangumiList: BangumiAPI[] = [
// RSS Mocks
// ============================================================================
export const mockRSSItem: RSSItem = {
export const mockRSSItem: RSS = {
id: 1,
name: 'Test RSS Feed',
url: 'https://mikanani.me/RSS/MyBangumi?token=test',
aggregate: true,
parser: 'mikan',
enabled: true,
connection_status: null,
last_checked_at: null,
last_error: null,
};
export const mockRSSList: RSSItem[] = [
export const mockRSSList: RSS[] = [
mockRSSItem,
{
...mockRSSItem,
@@ -100,10 +105,6 @@ export const mockRSSList: RSSItem[] = [
},
];
export const mockRSSResponse: RSSResponse = {
items: mockRSSList,
};
// ============================================================================
// Config Mocks
// ============================================================================