Skip to content

Commit 0f57219

Browse files
committed
fix: unit tests
1 parent 6adf9d2 commit 0f57219

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

Sources/Networking/Core/Upload/UploadAPIManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ extension UploadAPIManager: URLSessionTaskDelegate {
150150

151151
// MARK: - UploadAPIManaging
152152
@available(iOS 15.0, *)
153-
extension UploadAPIManager {
154-
public func upload(_ type: UploadType, to endpoint: Requestable) async throws -> UploadTask {
153+
public extension UploadAPIManager {
154+
func upload(_ type: UploadType, to endpoint: Requestable) async throws -> UploadTask {
155155
let endpointRequest = EndpointRequest(endpoint, sessionId: sessionId)
156156

157157
switch type {
@@ -188,15 +188,15 @@ extension UploadAPIManager {
188188
}
189189
}
190190

191-
public func invalidateSession(shouldFinishTasks: Bool) {
191+
func invalidateSession(shouldFinishTasks: Bool) {
192192
if shouldFinishTasks {
193193
urlSession.finishTasksAndInvalidate()
194194
} else {
195195
urlSession.invalidateAndCancel()
196196
}
197197
}
198198

199-
public func retry(taskId: String) async throws {
199+
func retry(taskId: String) async throws {
200200
// Get stored upload task to invoke the request with the same arguments
201201
guard let existingUploadTask = uploadTasks[taskId] else {
202202
throw NetworkError.unknown
@@ -212,7 +212,7 @@ extension UploadAPIManager {
212212
)
213213
}
214214

215-
public func stateStream(for uploadTaskId: UploadTask.ID) -> StateStream {
215+
func stateStream(for uploadTaskId: UploadTask.ID) -> StateStream {
216216
let uploadTask = uploadTasks.values.first { $0.id == uploadTaskId }
217217

218218
return uploadTask?.stateStream ?? AsyncStream.makeStream(of: UploadTask.State.self).stream

Sources/Networking/Modifiers/Processors/EndpointRequestStorageProcessor/EndpointRequestStorageProcessor.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,15 @@ open class EndpointRequestStorageProcessor: ResponseProcessing, ErrorProcessing
6060
config: .init(
6161
multiPeerSharing: .init(shareHistory: true),
6262
storedSessionsLimit: 5
63-
),
64-
deviceName: UUID().uuidString
63+
)
6564
)
6665

6766
public init(
6867
fileManager: FileManager = .default,
6968
fileDataWriter: FileDataWriting = FileDataWriter(),
7069
jsonEncoder: JSONEncoder? = nil,
7170
config: Config = .default,
72-
deviceName: String
71+
deviceName: String = UUID().uuidString
7372
) {
7473
self.fileManager = fileManager
7574
self.fileDataWriter = fileDataWriter

Tests/NetworkingTests/EndpointRequestStorageProcessorTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ final class EndpointRequestStorageProcessorTests: XCTestCase {
8888
let mockURLResponse: URLResponse = HTTPURLResponse(url: MockRouter.testStoringGet.baseURL, statusCode: 200, httpVersion: nil, headerFields: nil)!
8989
let mockResponse = (Data(), mockURLResponse)
9090

91-
let response = try await EndpointRequestStorageProcessor().process(mockResponse, with: mockURLRequest, for: mockEndpointRequest)
91+
let response = try await EndpointRequestStorageProcessor()
92+
.process(mockResponse, with: mockURLRequest, for: mockEndpointRequest)
9293

9394
// test storing data processor doesn't effect response in anyway
9495
XCTAssertEqual(response.data, mockResponse.0)
@@ -134,7 +135,7 @@ final class EndpointRequestStorageProcessorTests: XCTestCase {
134135
httpVersion: nil,
135136
headerFields: ["mockResponseHeader": "mock"]
136137
)!
137-
let mockResponseData = "Mock data".data(using: .utf8)!
138+
let mockResponseData = Data("Mock data".utf8)
138139
let mockResponse = (mockResponseData, mockURLResponse)
139140
let expectation = expectation(description: "Data was written")
140141

@@ -236,7 +237,7 @@ final class EndpointRequestStorageProcessorTests: XCTestCase {
236237
httpVersion: nil,
237238
headerFields: ["mockResponseHeader": "mock"]
238239
)!
239-
let mockResponseData = "Not found".data(using: .utf8)!
240+
let mockResponseData = Data("Not found".utf8)
240241
let mockResponse = (mockResponseData, mockURLResponse)
241242
let mockError = NetworkError.unacceptableStatusCode(
242243
statusCode: 404,
@@ -291,7 +292,7 @@ final class EndpointRequestStorageProcessorTests: XCTestCase {
291292
httpVersion: nil,
292293
headerFields: ["mockResponseHeader": "mock"]
293294
)!
294-
let mockResponseData = "Mock data".data(using: .utf8)!
295+
let mockResponseData = Data("Mock data".utf8)
295296
let mockResponse = (mockResponseData, mockURLResponse)
296297

297298
let expectation = expectation(description: "Data was written")

Tests/NetworkingTests/Mocks/MockFileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import XCTest
1010

1111
/// A subclass of `FileManager` where the file existence is based on a dictionary whose key is the file path.
12-
final class MockFileManager: FileManager {
12+
final class MockFileManager: FileManager, @unchecked Sendable {
1313
enum Function: Equatable {
1414
case fileExists(path: String)
1515
case createDirectory(path: String)

Tests/NetworkingTests/URLParametersTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private let baseURLString = "https://requestable.tests"
1212

1313
final class URLParametersTests: XCTestCase {
1414
enum Router: Requestable {
15-
case urlParameters([String: Any])
15+
case urlParameters([String: any Sendable])
1616

1717
var baseURL: URL {
1818
// swiftlint:disable:next force_unwrapping

Tests/NetworkingTests/UploadAPIManagerTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import XCTest
1010

1111
@NetworkingActor
12+
@available(iOS 15.0, *)
1213
final class UploadAPIManagerTests: XCTestCase {
1314
enum UploadRouter: Requestable {
1415
case mock
@@ -41,7 +42,10 @@ final class UploadAPIManagerTests: XCTestCase {
4142
try await withThrowingTaskGroup(of: Void.self) { group in
4243
for _ in 0..<15 {
4344
group.addTask {
44-
_ = try await apiManager.upload(data: data, to: UploadRouter.mock)
45+
_ = try await apiManager.upload(
46+
.data(data, contentType: "text"),
47+
to: UploadRouter.mock
48+
)
4549
}
4650
}
4751

0 commit comments

Comments
 (0)