Skip to content

Commit 493994c

Browse files
committed
Migrate APITestBase.swift to use new MockURLProtocol
1 parent 0344c3a commit 493994c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

FirebaseRemoteConfig/Tests/Swift/SwiftAPI/APITestBase.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,24 @@ class APITestBase: XCTestCase {
8888
config.configRealtime = RealtimeMocks.mockRealtime(config.configRealtime)
8989
}
9090
fakeConsole = FakeConsole()
91-
config.configFetch.fetchSession = URLSessionMock(with: fakeConsole)
91+
let configuration = URLSessionConfiguration.default
92+
configuration.protocolClasses = [MockURLProtocol.self]
93+
config.configFetch.fetchSession = URLSession(configuration: configuration)
94+
95+
var etag = ""
96+
MockURLProtocol.requestHandler = { request in
97+
let consoleValues = self.fakeConsole.get()
98+
if etag == "" || consoleValues["state"] as! String == RCNFetchResponseKeyStateUpdate {
99+
// Time string in microseconds to insure a different string from previous change.
100+
etag = String(NSDate().timeIntervalSince1970)
101+
}
102+
let jsonData = try! JSONSerialization.data(withJSONObject: consoleValues)
103+
let response = HTTPURLResponse(url: URL(fileURLWithPath: "fakeURL"),
104+
statusCode: 200,
105+
httpVersion: nil,
106+
headerFields: ["etag": etag])
107+
return (jsonData, response!)
108+
}
92109

93110
fakeConsole.config = [Constants.key1: Constants.value1,
94111
Constants.jsonKey: jsonValue,

0 commit comments

Comments
 (0)