11@testable import MeiliSearch
22import XCTest
33
4- // swiftlint:disable force_unwrapping
5- 
64class SystemTests: XCTestCase {
75  private var client: MeiliSearch!
86
@@ -13,118 +11,64 @@ class SystemTests: XCTestCase {
1311    client = try MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session)
1412  }
1513
16-   func testHealthStatusAvailable() throws {
14+   func testHealthStatusAvailable() async  throws {
1715    // Prepare the mock server
18- 
1916    let jsonString = """
20-       {
21-         "status": "available"
22-       }
23-       """
24- 
25-     let jsonData = jsonString.data(using: .utf8)!
26- 
27-     let expectedHealthBody: Health = try Constants.customJSONDecoder.decode(Health.self, from: jsonData)
17+     {
18+       "status": "available"
19+     }
20+     """
2821
22+     let expectedHealthBody: Health = try decodeJSON(from: jsonString)
2923    session.pushData(jsonString, code: 200)
3024
3125    // Start the test with the mocked server
32- 
33-     let expectation = XCTestExpectation(description: "Check body of health server on health method")
34- 
35-     self.client.health { result in
36-       switch result {
37-       case .success(let body):
38-         XCTAssertEqual(expectedHealthBody, body)
39-         expectation.fulfill()
40-       case .failure:
41-         XCTFail("Failed on available status check on health method")
42-       }
43-     }
44- 
45-     self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
26+     let body = try await self.client.health()
27+     XCTAssertEqual(expectedHealthBody, body)
4628  }
4729
48-   func testIsHealthyTrue() {
30+   func testIsHealthyTrue() async throws  {
4931    // Prepare the mock server
50- 
5132    let jsonString = """
52-        {
53-          "status": "available"
54-        }
55-        """
33+     {
34+       "status": "available"
35+     }
36+     """
5637
5738    session.pushData(jsonString, code: 200)
5839
5940    // Start the test with the mocked server
6041
6142    let expectation = XCTestExpectation(description: "Check if is healthy is true")
6243
63-     self.client.isHealthy { result in
64-       if result == true {
65-         XCTAssertEqual(result, true)
66-         expectation.fulfill()
67-       } else {
68-         XCTFail("Failed on isHealthy should be true")
69-       }
70-     }
71- 
72-     self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
44+     let result = await self.client.isHealthy()
45+     XCTAssertTrue(result)
7346  }
7447
75-   func testIsHealthyFalse() {
48+   func testIsHealthyFalse() async throws  {
7649    // Prepare the mock server
77- 
7850    session.pushData("", code: 400)
7951
8052    // Start the test with the mocked server
81- 
82-     let expectation = XCTestExpectation(description: "Check if is healthy is false")
83- 
84-     self.client.isHealthy { result in
85-       if result == false {
86-         XCTAssertEqual(result, false)
87-         expectation.fulfill()
88-       } else {
89-         XCTFail("Failed on isHealthy should be false")
90-       }
91-     }
92- 
93-     self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
53+     let result = await self.client.isHealthy()
54+     XCTAssertFalse(result)
9455  }
9556
96-   func testVersion() throws {
57+   func testVersion() async  throws {
9758    // Prepare the mock server
98- 
9959    let jsonString = """
100-       {
101-         "commitSha": "b46889b5f0f2f8b91438a08a358ba8f05fc09fc1",
102-         "commitDate": "2019-11-15T09:51:54.278247+00:00",
103-         "pkgVersion": "0.1.1"
104-       }
105-       """
106- 
107-     let jsonData = jsonString.data(using: .utf8)!
108- 
109-     let stubVersion: Version = try Constants.customJSONDecoder.decode(Version.self, from: jsonData)
60+     {
61+       "commitSha": "b46889b5f0f2f8b91438a08a358ba8f05fc09fc1",
62+       "commitDate": "2019-11-15T09:51:54.278247+00:00",
63+       "pkgVersion": "0.1.1"
64+     }
65+     """
11066
67+     let stubVersion: Version = try decodeJSON(from: jsonString)
11168    session.pushData(jsonString)
11269
11370    // Start the test with the mocked server
114- 
115-     let expectation = XCTestExpectation(description: "Load server version")
116- 
117-     self.client.version { result in
118-       switch result {
119-       case .success(let version):
120-         XCTAssertEqual(stubVersion, version)
121-         expectation.fulfill()
122-       case .failure:
123-         XCTFail("Failed to load server version")
124-       }
125-     }
126- 
127-     self.wait(for: [expectation], timeout: TESTS_TIME_OUT)
71+     let version = try await client.version()
72+     XCTAssertEqual(stubVersion, version)
12873  }
12974}
130- // swiftlint:enable force_unwrapping
0 commit comments