mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-12 09:05:28 +08:00
test(site): cover site resource dialog (#563)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { DownloaderConf, Site, SiteStatistic, SiteUserData } from '@/api/types'
|
||||
import type { DownloaderConf, Site, SiteCategory, SiteStatistic, SiteUserData, TorrentInfo } from '@/api/types'
|
||||
|
||||
let siteSeed = 0
|
||||
let torrentSeed = 0
|
||||
|
||||
export function createSite(overrides: Partial<Site> = {}): Site {
|
||||
siteSeed += 1
|
||||
@@ -49,3 +50,38 @@ export function createSiteDownloader(overrides: Partial<DownloaderConf> = {}): D
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
/** 构造站点资源分类测试记录。 */
|
||||
export function createSiteCategory(overrides: Partial<SiteCategory> = {}): SiteCategory {
|
||||
return {
|
||||
cat: 'movie',
|
||||
desc: '电影',
|
||||
id: 1,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
/** 构造满足资源列表展示与下载边界的种子记录。 */
|
||||
export function createTorrentInfo(overrides: Partial<TorrentInfo> = {}): TorrentInfo {
|
||||
torrentSeed += 1
|
||||
return {
|
||||
category: '电影',
|
||||
downloadvolumefactor: 1,
|
||||
freedate: '',
|
||||
freedate_diff: '',
|
||||
grabs: 10,
|
||||
hit_and_run: false,
|
||||
imdbid: '',
|
||||
labels: [],
|
||||
peers: 3,
|
||||
pri_order: 0,
|
||||
seeders: 12,
|
||||
site_order: 0,
|
||||
site_proxy: false,
|
||||
size: 1_073_741_824,
|
||||
title: `测试资源 ${torrentSeed}`,
|
||||
uploadvolumefactor: 1,
|
||||
volume_factor: '1x',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import type { ApiResponse, DownloaderConf, Site, SiteStatistic, SiteUserData } from '@/api/types'
|
||||
import type {
|
||||
ApiResponse,
|
||||
DownloaderConf,
|
||||
Site,
|
||||
SiteCategory,
|
||||
SiteStatistic,
|
||||
SiteUserData,
|
||||
TorrentInfo,
|
||||
} from '@/api/types'
|
||||
import { HttpResponse, http, type JsonBodyType } from 'msw'
|
||||
|
||||
const API_BASE_URL = 'http://localhost/api/v1/'
|
||||
@@ -10,6 +18,7 @@ interface SiteMutationResponse {
|
||||
}
|
||||
|
||||
export const siteApiUrls = {
|
||||
categories: (siteId: number) => new URL(`site/category/${siteId}`, API_BASE_URL).href,
|
||||
cookie: (id: number) => new URL(`site/cookie/${id}`, API_BASE_URL).href,
|
||||
delete: (id: number) => new URL(`site/${id}`, API_BASE_URL).href,
|
||||
details: (id: number) => new URL(`site/${id}`, API_BASE_URL).href,
|
||||
@@ -17,6 +26,7 @@ export const siteApiUrls = {
|
||||
icon: (id: number) => new URL(`site/icon/${id}`, API_BASE_URL).href,
|
||||
list: new URL('site/', API_BASE_URL).href,
|
||||
priorities: new URL('site/priorities', API_BASE_URL).href,
|
||||
resources: (siteId: number) => new URL(`site/resource/${siteId}`, API_BASE_URL).href,
|
||||
statistic: (domain: string) => new URL(`site/statistic/${domain}`, API_BASE_URL).href,
|
||||
statistics: new URL('site/statistic', API_BASE_URL).href,
|
||||
test: (id: number) => new URL(`site/test/${id}`, API_BASE_URL).href,
|
||||
@@ -180,3 +190,27 @@ export function updateSiteCookieHandler(
|
||||
return HttpResponse.json(response, { status })
|
||||
})
|
||||
}
|
||||
|
||||
export function siteCategoriesHandler(
|
||||
siteId: number,
|
||||
response: SiteCategory[],
|
||||
status = 200,
|
||||
onRequest: (url: URL) => void = () => {},
|
||||
) {
|
||||
return http.get(siteApiUrls.categories(siteId), ({ request }) => {
|
||||
onRequest(new URL(request.url))
|
||||
return HttpResponse.json(response, { status })
|
||||
})
|
||||
}
|
||||
|
||||
export function siteResourcesHandler(
|
||||
siteId: number,
|
||||
response: TorrentInfo[],
|
||||
status = 200,
|
||||
onRequest: (url: URL) => void = () => {},
|
||||
) {
|
||||
return http.get(siteApiUrls.resources(siteId), ({ request }) => {
|
||||
onRequest(new URL(request.url))
|
||||
return HttpResponse.json(response, { status })
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user