diff --git a/tests/languages/apple/Tests.swift b/tests/languages/apple/Tests.swift index d8aae3d63..9ac970e3b 100644 --- a/tests/languages/apple/Tests.swift +++ b/tests/languages/apple/Tests.swift @@ -25,12 +25,10 @@ class Tests: XCTestCase { .addHeader(key: "Origin", value: "http://localhost") .setSelfSigned() - var mock: Mock - // Ping pong test let ping = try await client.ping() - mock = Mock.from(json: ping)! - print(mock.result) + let pingResult = parse(from: ping)! + print(pingResult) // reset configs client.setProject("console") @@ -48,7 +46,9 @@ class Tests: XCTestCase { realtimeResponse = message.payload!["response"] as! String expectation.fulfill() } - + + var mock: Mock + // Foo Tests mock = try await foo.get(x: "string", y: 123, z: ["string in array"]) print(mock.result) @@ -206,4 +206,13 @@ class Tests: XCTestCase { mock = try await general.headers() print(mock.result) } + + func parse(from json: String) -> String? { + if let data = json.data(using: .utf8), + let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], + let result = jsonObject["result"] as? String { + return result + } + return nil + } } diff --git a/tests/languages/swift/Tests.swift b/tests/languages/swift/Tests.swift index d8054a6c6..7269011bd 100644 --- a/tests/languages/swift/Tests.swift +++ b/tests/languages/swift/Tests.swift @@ -25,12 +25,10 @@ class Tests: XCTestCase { .addHeader(key: "Origin", value: "http://localhost") .setSelfSigned() - var mock: Mock - // Ping pong test let ping = try await client.ping() - mock = Mock.from(json: ping)! - print(mock.result) + let pingResult = parse(from: ping)! + print(pingResult) // reset project client.setProject("console") @@ -39,6 +37,8 @@ class Tests: XCTestCase { let bar = Bar(client) let general = General(client) + var mock: Mock + // Foo Tests mock = try await foo.get(x: "string", y: 123, z: ["string in array"]) print(mock.result) @@ -197,4 +197,13 @@ class Tests: XCTestCase { print(error.localizedDescription) } } + + func parse(from json: String) -> String? { + if let data = json.data(using: .utf8), + let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], + let result = jsonObject["result"] as? String { + return result + } + return nil + } }