feat(travel-album): 按当前景区创建相册及筛选订单
This commit is contained in:
@@ -23,15 +23,16 @@ final class TravelAlbumAPITests: XCTestCase {
|
||||
XCTAssertEqual(query.first { $0.name == "page_size" }?.value, "30")
|
||||
}
|
||||
|
||||
func testCreateEncodesBody() async throws {
|
||||
func testCreatePreShootEncodesScenicIdAndPricing() async throws {
|
||||
let data = envelopeJSON(#"{"id":8}"#)
|
||||
let session = MockURLSession(responses: [data])
|
||||
let api = TravelAlbumAPI(client: APIClient(environment: .testing, session: session))
|
||||
|
||||
_ = try await api.create(
|
||||
let response = try await api.create(
|
||||
TravelAlbumCreateRequest(
|
||||
name: "2026-07-07-001",
|
||||
type: 1,
|
||||
scenicId: 101,
|
||||
orderNumber: nil,
|
||||
materialNum: 2,
|
||||
materialPrice: 10.5,
|
||||
@@ -44,12 +45,15 @@ final class TravelAlbumAPITests: XCTestCase {
|
||||
)
|
||||
)
|
||||
|
||||
XCTAssertEqual(response.id, 8)
|
||||
let request = try XCTUnwrap(session.requests.first)
|
||||
XCTAssertEqual(request.httpMethod, "POST")
|
||||
XCTAssertEqual(request.url?.path, "/api/yf-handset-app/photog/travel-album/create")
|
||||
let body = try JSONSerialization.jsonObject(with: try XCTUnwrap(request.httpBody)) as? [String: Any]
|
||||
XCTAssertEqual(body?["name"] as? String, "2026-07-07-001")
|
||||
XCTAssertEqual(body?["type"] as? Int, 1)
|
||||
XCTAssertEqual(body?["scenic_id"] as? Int, 101)
|
||||
XCTAssertNil(body?["order_number"])
|
||||
XCTAssertEqual(body?["material_num"] as? Int, 2)
|
||||
XCTAssertEqual(body?["material_price"] as? Double, 10.5)
|
||||
let retouchConfiguration = body?["auto_retouch_config"] as? [String: Any]
|
||||
@@ -59,6 +63,85 @@ final class TravelAlbumAPITests: XCTestCase {
|
||||
XCTAssertNil(retouchConfiguration?["updated_at"])
|
||||
}
|
||||
|
||||
func testCreatePreOrderEncodesNumericScenicIdAndStringOrderNumber() async throws {
|
||||
let session = MockURLSession(responses: [envelopeJSON(#"{"id":9}"#)])
|
||||
let api = TravelAlbumAPI(client: APIClient(environment: .testing, session: session))
|
||||
|
||||
let response = try await api.create(
|
||||
TravelAlbumCreateRequest(
|
||||
name: "跟拍相册",
|
||||
type: 2,
|
||||
scenicId: 202,
|
||||
orderNumber: "000202611180001",
|
||||
materialNum: nil,
|
||||
materialPrice: nil,
|
||||
materialPackagePrice: nil,
|
||||
photoPrice: nil
|
||||
)
|
||||
)
|
||||
|
||||
let request = try XCTUnwrap(session.requests.first)
|
||||
let body = try JSONSerialization.jsonObject(with: try XCTUnwrap(request.httpBody)) as? [String: Any]
|
||||
XCTAssertEqual(response.id, 9)
|
||||
XCTAssertEqual(body?["type"] as? Int, 2)
|
||||
XCTAssertEqual(body?["scenic_id"] as? Int, 202)
|
||||
XCTAssertEqual(body?["order_number"] as? String, "000202611180001")
|
||||
XCTAssertNil(body?["material_num"])
|
||||
XCTAssertNil(body?["material_price"])
|
||||
}
|
||||
|
||||
func testAvailableOrdersAlwaysQueriesScenicAndDecodesEmptyList() async throws {
|
||||
let data = envelopeJSON(
|
||||
#"[{"project_name":"跟拍","order_number":"0001","user_phone":"","user_id":1}]"#
|
||||
)
|
||||
let session = MockURLSession(responses: [data, envelopeJSON("[]")])
|
||||
let api = TravelAlbumAPI(client: APIClient(environment: .testing, session: session))
|
||||
|
||||
let orders = try await api.availableOrders(scenicId: 101)
|
||||
let emptyOrders = try await api.availableOrders(scenicId: 202)
|
||||
|
||||
XCTAssertEqual(orders.map(\.orderNumber), ["0001"])
|
||||
XCTAssertTrue(emptyOrders.isEmpty)
|
||||
XCTAssertEqual(session.requests.map { $0.url?.path }, Array(repeating: "/api/yf-handset-app/photog/travel-album/available-order", count: 2))
|
||||
XCTAssertEqual(session.requests.map { $0.url?.query }, ["scenic_id=101", "scenic_id=202"])
|
||||
}
|
||||
|
||||
func testScenicBusinessErrorsAreAvailableEvenWhenHTTPIsNotSuccessful() async throws {
|
||||
let session = MockURLSession(
|
||||
responses: [
|
||||
try TestJSON.errorEnvelope(code: 100099, msg: "景区无权限"),
|
||||
try TestJSON.errorEnvelope(code: 100001, msg: "订单不属于当前景区"),
|
||||
],
|
||||
statusCode: 403
|
||||
)
|
||||
let api = TravelAlbumAPI(client: APIClient(environment: .testing, session: session))
|
||||
|
||||
do {
|
||||
_ = try await api.availableOrders(scenicId: 101)
|
||||
XCTFail("Expected invalid scenic business error")
|
||||
} catch APIError.serverCode(let code, let message) {
|
||||
XCTAssertEqual(code, 100099)
|
||||
XCTAssertEqual(message, "景区无权限")
|
||||
}
|
||||
|
||||
do {
|
||||
_ = try await api.create(TravelAlbumCreateRequest(
|
||||
name: "跟拍相册",
|
||||
type: 2,
|
||||
scenicId: 101,
|
||||
orderNumber: "0001",
|
||||
materialNum: nil,
|
||||
materialPrice: nil,
|
||||
materialPackagePrice: nil,
|
||||
photoPrice: nil
|
||||
))
|
||||
XCTFail("Expected mismatched order business error")
|
||||
} catch APIError.serverCode(let code, let message) {
|
||||
XCTAssertEqual(code, 100001)
|
||||
XCTAssertEqual(message, "订单不属于当前景区")
|
||||
}
|
||||
}
|
||||
|
||||
func testInfoDecodesNewConfigurationAndDefaultsOldAlbumToDisabled() async throws {
|
||||
let configuredAlbum = envelopeJSON(
|
||||
#"{"id":8,"store_user_id":1,"name":"配置相册","type":1,"order_number":"","material_num":1,"material_price":10,"material_package_price":0,"photo_price":0,"cover_url":"","user_id":2,"status":1,"created_at":"","updated_at":"","auto_retouch_config":{"enabled":true,"refined_template_id":12}}"#
|
||||
|
||||
Reference in New Issue
Block a user