为资产模块新增相册管理与片花上传
为 album_list 与 album_trailer 接入首页路由,在 Profile 中新增 DEBUG 首页菜单预览,并扩展 Assets 测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -126,6 +126,67 @@ final class AssetsAPITests: XCTestCase {
|
||||
XCTAssertEqual((body["media_list"] as? [[String: Any]])?.first?["oss_url"] as? String, "https://cdn/a.jpg")
|
||||
}
|
||||
|
||||
/// 测试相册接口使用旧工程路径、query 和请求体。
|
||||
func testAlbumRequestsUseExpectedPathQueryAndBodies() async throws {
|
||||
let session = AssetsRecordingURLSession(responses: [
|
||||
Self.albumFolderListResponse,
|
||||
Self.albumFolderInfoResponse,
|
||||
Self.albumFileListResponse,
|
||||
Self.emptyResponse,
|
||||
Self.emptyResponse,
|
||||
Self.emptyResponse,
|
||||
Self.emptyResponse
|
||||
])
|
||||
let api = AssetsAPI(client: APIClient(session: session))
|
||||
|
||||
let folders = try await api.albumFolderList(
|
||||
scenicId: 9,
|
||||
page: 0,
|
||||
pageSize: 0,
|
||||
name: "旅拍",
|
||||
startTime: "2026-06-01",
|
||||
endTime: "2026-06-24"
|
||||
)
|
||||
let info = try await api.albumFolderInfo(id: 3)
|
||||
let files = try await api.albumFileList(scenicId: 9, folderId: 3, fileType: 2, page: 0, pageSize: 0)
|
||||
try await api.addAlbumFolder(scenicId: 9, name: "新相册", remark: "备注")
|
||||
try await api.editAlbumFolder(folderId: 3, coverFileId: 11, name: "改名", remark: nil)
|
||||
try await api.deleteAlbumFiles(folderId: 3, idList: [11, 12])
|
||||
try await api.albumFileUploadURL(scenicId: 9, fileURL: "https://cdn/a.jpg", folderId: 3)
|
||||
|
||||
XCTAssertEqual(session.requests.map { $0.url?.path }, [
|
||||
"/api/yf-handset-app/photog/album/folder-list",
|
||||
"/api/yf-handset-app/photog/album/folder-info",
|
||||
"/api/yf-handset-app/photog/album/file-list",
|
||||
"/api/yf-handset-app/photog/album/folder-add",
|
||||
"/api/yf-handset-app/photog/album/folder-edit",
|
||||
"/api/yf-handset-app/photog/album/file-delete",
|
||||
"/api/yf-handset-app/photog/album/file-upload-url"
|
||||
])
|
||||
let folderQuery = assetsQueryItems(from: session.requests[0])
|
||||
XCTAssertEqual(folderQuery["scenic_id"], "9")
|
||||
XCTAssertEqual(folderQuery["page"], "1")
|
||||
XCTAssertEqual(folderQuery["page_size"], "1")
|
||||
XCTAssertEqual(folderQuery["cloud_folder_type"], "1")
|
||||
XCTAssertEqual(folderQuery["name"], "旅拍")
|
||||
XCTAssertEqual(folderQuery["start_time"], "2026-06-01")
|
||||
XCTAssertEqual(folderQuery["end_time"], "2026-06-24")
|
||||
XCTAssertEqual(folders.list.first?.countImage, 4)
|
||||
XCTAssertEqual(info.coverFile?.fileSize, 2048)
|
||||
XCTAssertTrue(files.list.first?.isImage == true)
|
||||
|
||||
let addBody = try bodyObject(from: session.requests[3])
|
||||
XCTAssertEqual(addBody["scenic_id"] as? String, "9")
|
||||
XCTAssertEqual(addBody["cloud_folder_type"] as? Int, 1)
|
||||
let editBody = try bodyObject(from: session.requests[4])
|
||||
XCTAssertEqual(editBody["cover_file_id"] as? Int, 11)
|
||||
let deleteBody = try bodyObject(from: session.requests[5])
|
||||
XCTAssertEqual(deleteBody["folder_id"] as? Int, 3)
|
||||
XCTAssertEqual(deleteBody["id_list"] as? [Int], [11, 12])
|
||||
let uploadQuery = assetsQueryItems(from: session.requests[6])
|
||||
XCTAssertEqual(uploadQuery["file_url"], "https://cdn/a.jpg")
|
||||
}
|
||||
|
||||
fileprivate static let emptyResponse = #"{"code":100000,"msg":"success","data":{}}"#.data(using: .utf8)!
|
||||
fileprivate static let permissionResponse = #"{"code":100000,"msg":"success","data":{"can_upload":"0","reason":"空间不足"}}"#.data(using: .utf8)!
|
||||
fileprivate static let cloudListResponse = """
|
||||
@ -144,6 +205,19 @@ 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 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":"备注"}
|
||||
]}}
|
||||
""".data(using: .utf8)!
|
||||
fileprivate static let albumFolderInfoResponse = """
|
||||
{"code":100000,"msg":"success","data":{"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":"备注"}}
|
||||
""".data(using: .utf8)!
|
||||
fileprivate static let albumFileListResponse = """
|
||||
{"code":100000,"msg":"success","data":{"total":"1","list":[
|
||||
{"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":""}
|
||||
]}}
|
||||
""".data(using: .utf8)!
|
||||
}
|
||||
|
||||
/// 资产 API 测试用 URLSession,记录请求并返回固定响应。
|
||||
|
||||
Reference in New Issue
Block a user