Skip to content

Commit 98cc154

Browse files
committed
refactor: ensure logRequestByItSelf is preserved in map functions and update test assertions for request listener calls
1 parent 481ba49 commit 98cc154

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Sources/SwiftAPIClient/APIClientCaller.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ public struct APIClientCaller<Response, Value, Result> {
6565
/// try await client.call(.http, as: .decodable)
6666
/// ```
6767
public func map<T>(_ mapper: @escaping (Result) throws -> T) -> APIClientCaller<Response, Value, T> {
68-
APIClientCaller<Response, Value, T> {
68+
var result = APIClientCaller<Response, Value, T> {
6969
try mapper(_call($0, $1, $2, $3))
7070
} mockResult: {
7171
try mapper(_mockResult($0))
7272
}
73+
result.logRequestByItSelf = logRequestByItSelf
74+
return result
7375
}
7476

7577
/// Maps the response to another type using the provided mapper.
@@ -81,13 +83,15 @@ public struct APIClientCaller<Response, Value, Result> {
8183
/// try await client.call(.http, as: .decodable)
8284
/// ```
8385
public func mapResponse<T>(_ mapper: @escaping (Response) throws -> T) -> APIClientCaller<T, Value, Result> {
84-
APIClientCaller<T, Value, Result> { id, request, configs, serialize in
86+
var result = APIClientCaller<T, Value, Result> { id, request, configs, serialize in
8587
try _call(id, request, configs) { response, validate in
8688
try serialize(mapper(response), validate)
8789
}
8890
} mockResult: {
8991
try _mockResult($0)
9092
}
93+
result.logRequestByItSelf = logRequestByItSelf
94+
return result
9195
}
9296
}
9397

Tests/SwiftAPIClientTests/Modifiers/LoggingAndListenerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ final class LoggingAndListenerTests: XCTestCase {
350350

351351
XCTAssertEqual(result, mockData)
352352

353-
// Verify HTTP client listener calls (HTTP client may have multiple internal request stages)
354-
XCTAssertGreaterThan(mockListener.requestStartedCalls.count, 0, "Expected at least 1 request started call")
353+
// Verify HTTP client listener calls
354+
XCTAssertEqual(mockListener.requestStartedCalls.count, 1, "Expected exactly 1 request started call")
355355
XCTAssertEqual(mockListener.responseReceivedCalls.count, 1, "Expected 1 response received call")
356356
XCTAssertEqual(mockListener.responseSerializedCalls.count, 1, "Expected 1 response serialized call")
357357
XCTAssertEqual(mockListener.errorCalls.count, 0, "Expected no error calls")

0 commit comments

Comments
 (0)