为资产模块新增样片管理与上传流程
扩展媒体库以支持样片类型及项目选择,为样片入口接入首页路由,并扩展 Assets 测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -76,7 +76,7 @@ final class AssetsAPITests: XCTestCase {
|
||||
let api = AssetsAPI(client: APIClient(session: session))
|
||||
|
||||
let list = try await api.mediaAlbumList(kind: .material, keyword: "航拍", status: 1, page: 0, pageSize: 0)
|
||||
let detail = try await api.mediaAlbumDetail(id: 7)
|
||||
let detail = try await api.mediaAlbumDetail(id: 7, kind: .material)
|
||||
|
||||
XCTAssertEqual(session.requests.first?.url?.path, "/api/app/media-album/list")
|
||||
let query = assetsQueryItems(from: try XCTUnwrap(session.requests.first))
|
||||
@ -87,6 +87,7 @@ final class AssetsAPITests: XCTestCase {
|
||||
XCTAssertEqual(list.order?.totalNum, 12)
|
||||
XCTAssertEqual(list.list.first?.likesCount, 3)
|
||||
XCTAssertEqual(session.requests.last?.url?.path, "/api/app/media-album/detail")
|
||||
XCTAssertEqual(assetsQueryItems(from: try XCTUnwrap(session.requests.last))["type"], "1")
|
||||
XCTAssertEqual(detail.mediaList.first?.size, 4096)
|
||||
XCTAssertTrue(detail.mediaList.first?.isVideo == true)
|
||||
}
|
||||
@ -108,8 +109,8 @@ final class AssetsAPITests: XCTestCase {
|
||||
projectId: 0
|
||||
)
|
||||
|
||||
try await api.mediaAlbumOperation(MediaAlbumOperationRequest(id: 1, listingStatus: 1))
|
||||
try await api.mediaAlbumDelete(MediaAlbumDeleteRequest(id: 1))
|
||||
try await api.mediaAlbumOperation(MediaAlbumOperationRequest(id: 1, type: 1, listingStatus: 1))
|
||||
try await api.mediaAlbumDelete(MediaAlbumDeleteRequest(id: 1, type: 1))
|
||||
try await api.mediaAlbumAddTag(MediaAlbumAddTagRequest(name: "航拍"))
|
||||
try await api.mediaAlbumUpload(upload)
|
||||
try await api.mediaAlbumEdit(MediaAlbumEditRequest(id: 2, name: "素材", type: 1, mediaType: 2, mediaList: upload.mediaList, coverUrl: upload.coverUrl, coverSize: upload.coverSize, scenicSpotId: 6, description: "描述", materialTag: "航拍"))
|
||||
@ -126,6 +127,52 @@ final class AssetsAPITests: XCTestCase {
|
||||
XCTAssertEqual((body["media_list"] as? [[String: Any]])?.first?["oss_url"] as? String, "https://cdn/a.jpg")
|
||||
}
|
||||
|
||||
/// 测试样片请求携带 type=2,项目列表接口和项目字段宽松解码正确。
|
||||
func testSampleRequestsAndProjectListUseExpectedTypeAndQuery() async throws {
|
||||
let session = AssetsRecordingURLSession(responses: [
|
||||
Self.mediaListResponse,
|
||||
Self.mediaDetailResponse,
|
||||
Self.emptyResponse,
|
||||
Self.emptyResponse,
|
||||
Self.projectListResponse,
|
||||
Self.emptyResponse
|
||||
])
|
||||
let api = AssetsAPI(client: APIClient(session: session))
|
||||
let upload = MediaAlbumUploadRequest(
|
||||
name: "亲子样片",
|
||||
type: 2,
|
||||
mediaType: 2,
|
||||
mediaList: [MediaAlbumUploadItem(originalName: "sample.jpg", ossUrl: "https://cdn/sample.jpg", size: 10, fileWidthSize: MediaAlbumFileSize(width: 100, height: 80))],
|
||||
coverUrl: "https://cdn/cover.jpg",
|
||||
coverSize: MediaAlbumFileSize(width: 100, height: 80),
|
||||
scenicSpotId: 6,
|
||||
description: "描述",
|
||||
materialTag: "",
|
||||
projectId: 88
|
||||
)
|
||||
|
||||
_ = try await api.mediaAlbumList(kind: .sample, keyword: "样片", status: nil, page: 1, pageSize: 10)
|
||||
_ = try await api.mediaAlbumDetail(id: 7, kind: .sample)
|
||||
try await api.mediaAlbumOperation(MediaAlbumOperationRequest(id: 7, type: 2, listingStatus: 1))
|
||||
try await api.mediaAlbumDelete(MediaAlbumDeleteRequest(id: 7, type: 2))
|
||||
let projects = try await api.projectList(scenicId: 9, name: "亲子", page: 0, pageSize: 0)
|
||||
try await api.mediaAlbumUpload(upload)
|
||||
|
||||
XCTAssertEqual(assetsQueryItems(from: session.requests[0])["type"], "2")
|
||||
XCTAssertEqual(assetsQueryItems(from: session.requests[1])["type"], "2")
|
||||
XCTAssertEqual((try bodyObject(from: session.requests[2]))["type"] as? Int, 2)
|
||||
XCTAssertEqual((try bodyObject(from: session.requests[3]))["type"] as? Int, 2)
|
||||
XCTAssertEqual(session.requests[4].url?.path, "/api/yf-handset-app/photog/project/list")
|
||||
let projectQuery = assetsQueryItems(from: session.requests[4])
|
||||
XCTAssertEqual(projectQuery["scenic_id"], "9")
|
||||
XCTAssertEqual(projectQuery["name"], "亲子")
|
||||
XCTAssertEqual(projectQuery["page"], "1")
|
||||
XCTAssertEqual(projectQuery["page_size"], "1")
|
||||
XCTAssertEqual(projects.list.first?.id, 88)
|
||||
XCTAssertEqual(projects.list.first?.name, "亲子旅拍")
|
||||
XCTAssertEqual((try bodyObject(from: session.requests[5]))["project_id"] as? Int, 88)
|
||||
}
|
||||
|
||||
/// 测试相册接口使用旧工程路径、query 和请求体。
|
||||
func testAlbumRequestsUseExpectedPathQueryAndBodies() async throws {
|
||||
let session = AssetsRecordingURLSession(responses: [
|
||||
@ -205,6 +252,11 @@ final class AssetsAPITests: XCTestCase {
|
||||
{"id":"9","original_name":"v.mp4","oss_url":"https://cdn/v.mp4","thumbnail_url":"","type":"1","size":"4096","show_url":"https://cdn/v.mp4"}
|
||||
]}}
|
||||
""".data(using: .utf8)!
|
||||
fileprivate static let projectListResponse = """
|
||||
{"code":100000,"msg":"success","data":{"total":"1","list":[
|
||||
{"id":"88","type":"19","type_name":"多点旅拍","status":"1","status_name":"上架","name":"亲子旅拍","cover_project":"https://cdn/p.jpg","cover_video":"","price":"299","ot_price":"399","price_deposit":"99"}
|
||||
]}}
|
||||
""".data(using: .utf8)!
|
||||
fileprivate static let albumFolderListResponse = """
|
||||
{"code":100000,"msg":"success","data":{"total":"1","list":[
|
||||
{"id":"3","name":"旅拍","cover_file_id":"11","count_video":"2","count_image":"4","cover":{"id":"11","file_name":"a.jpg","file_type":"2","file_url":"https://cdn/a.jpg","cover_url":"","file_size":"2048","file_size_human":"2KB","remark":""},"created_at":"2026","remark":"备注"}
|
||||
|
||||
Reference in New Issue
Block a user