@@ -7,7 +7,7 @@ import AsyncHTTPClient
77import NIOHTTP1
88import NIOFoundationCompat
99
10- public class AppStoreServerAPIClient {
10+ public actor AppStoreServerAPIClient : Sendable {
1111
1212 public enum ConfigurationError : Error , Hashable , Sendable {
1313 /// Xcode is not a supported environment for an AppStoreServerAPIClient
@@ -26,6 +26,9 @@ public class AppStoreServerAPIClient {
2626 private let bundleId : String
2727 private let url : String
2828 private let client : HTTPClient
29+ // For testing purposes
30+ private var executeRequestOverride : ( @Sendable ( HTTPClientRequest, Data? ) async throws -> HTTPClientResponse ) ?
31+
2932 ///Create an App Store Server API client
3033 ///
3134 ///- Parameter signingKey: Your private key downloaded from App Store Connect
@@ -37,6 +40,7 @@ public class AppStoreServerAPIClient {
3740 self . keyId = keyId
3841 self . issuerId = issuerId
3942 self . bundleId = bundleId
43+ self . executeRequestOverride = nil
4044 switch ( environment) {
4145 case . xcode:
4246 throw ConfigurationError . invalidEnvironment
@@ -56,6 +60,11 @@ public class AppStoreServerAPIClient {
5660 deinit {
5761 try ? self . client. syncShutdown ( )
5862 }
63+
64+ // Test helper method to set request override
65+ internal func setExecuteRequestOverride( _ override: @escaping @Sendable ( HTTPClientRequest, Data? ) async throws -> HTTPClientResponse ) {
66+ self . executeRequestOverride = override
67+ }
5968
6069 private enum RequestBody {
6170 case encodable( any Encodable )
@@ -138,6 +147,9 @@ public class AppStoreServerAPIClient {
138147
139148 // requestBody passed for testing purposes
140149 internal func executeRequest( _ urlRequest: HTTPClientRequest , _ requestBody: Data ? ) async throws -> HTTPClientResponse {
150+ if let override = executeRequestOverride {
151+ return try await override ( urlRequest, requestBody)
152+ }
141153 return try await self . client. execute ( urlRequest, timeout: . seconds( 30 ) )
142154 }
143155
0 commit comments