From 88565baeeca98a6fe60279d90949076a1a19d889 Mon Sep 17 00:00:00 2001 From: Pedro Paulo de Amorim Date: Wed, 19 May 2021 22:51:34 +0100 Subject: [PATCH 1/3] Fix all swiftlint errors and remove Tests from the linter --- .swiftlint.yml | 5 +- .../Sources/PerfectTemplate/main.swift | 4 +- Sources/MeiliSearch/Client.swift | 4 +- Sources/MeiliSearch/Config.swift | 8 ++-- Sources/MeiliSearch/Constants.swift | 8 ++-- Sources/MeiliSearch/Error.swift | 4 +- Sources/MeiliSearch/Indexes.swift | 15 ++++-- Sources/MeiliSearch/Model/Dump.swift | 10 ++-- Sources/MeiliSearch/Model/Key.swift | 4 +- Sources/MeiliSearch/Model/Setting.swift | 2 +- Sources/MeiliSearch/Model/Update.swift | 26 +++++----- Sources/MeiliSearch/Request.swift | 41 ++++++++++++---- Sources/MeiliSearch/Settings.swift | 41 +++++++--------- .../DocumentsTests.swift | 5 +- .../XCTestManifests.swift | 2 +- .../MeiliSearchUnitTests/DocumentsTests.swift | 16 +++---- Tests/MeiliSearchUnitTests/DumpsTests.swift | 4 +- Tests/MeiliSearchUnitTests/IndexesTests.swift | 14 +++--- Tests/MeiliSearchUnitTests/KeysTests.swift | 2 +- Tests/MeiliSearchUnitTests/SearchTests.swift | 4 +- .../MeiliSearchUnitTests/SettingsTests.swift | 48 +++++++++---------- Tests/MeiliSearchUnitTests/StatsTests.swift | 4 +- Tests/MeiliSearchUnitTests/SystemTests.swift | 12 ++--- Tests/MeiliSearchUnitTests/UpdatesTests.swift | 6 +-- .../XCTestManifests.swift | 2 +- 25 files changed, 156 insertions(+), 135 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 42c49572..cda54507 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -23,8 +23,9 @@ opt_in_rules: # some rules are only opt-in excluded: - Carthage - Pods - - VaporDemo/.build - - PerfectDemo/.build + - Demos/VaporDemo + - Demos/PerfectDemo + - Tests - .build force_cast: warning diff --git a/Demos/PerfectDemo/Sources/PerfectTemplate/main.swift b/Demos/PerfectDemo/Sources/PerfectTemplate/main.swift index ff2d77c2..a7b1acce 100644 --- a/Demos/PerfectDemo/Sources/PerfectTemplate/main.swift +++ b/Demos/PerfectDemo/Sources/PerfectTemplate/main.swift @@ -5,7 +5,7 @@ // Created by Kyle Jessup on 2015-11-05. // Copyright (C) 2015 PerfectlySoft, Inc. // -//===----------------------------------------------------------------------===// +// ===----------------------------------------------------------------------===// // // This source file is part of the Perfect.org open source project // @@ -14,7 +14,7 @@ // // See http://perfect.org/licensing.html for license information // -//===----------------------------------------------------------------------===// +// ===----------------------------------------------------------------------===// // import PerfectHTTP diff --git a/Sources/MeiliSearch/Client.swift b/Sources/MeiliSearch/Client.swift index baea41fa..10d85a2f 100755 --- a/Sources/MeiliSearch/Client.swift +++ b/Sources/MeiliSearch/Client.swift @@ -811,7 +811,7 @@ public struct MeiliSearch { If the request was sucessful or `false` if a failure occured. */ public func isHealthy(_ completion: @escaping (Bool) -> Void) { - self.health{ result in + self.health { result in switch result { case .success: completion(true) @@ -862,7 +862,7 @@ public struct MeiliSearch { public func getDumpStatus( UID: String, _ completion: @escaping (Result) -> Void) { - self.dumps.status(UID,completion) + self.dumps.status(UID, completion) } } diff --git a/Sources/MeiliSearch/Config.swift b/Sources/MeiliSearch/Config.swift index 5e59d907..72916780 100755 --- a/Sources/MeiliSearch/Config.swift +++ b/Sources/MeiliSearch/Config.swift @@ -11,8 +11,8 @@ public class Config { // MARK: Static - ///Deafault configuration for the default MeiliSearch host, do not use this in - ///production since it does not contains the apiKey. + /// Deafault configuration for the default MeiliSearch host, do not use this in + /// production since it does not contains the apiKey. public static let `default`: Config = Config(hostURL: localhost) /// Default config instance set up to use localhost and port 7700. @@ -84,12 +84,12 @@ public class Config { return self } - guard let _ = URL(string: hostURL) else { + guard URL(string: hostURL) != nil else { throw MeiliSearch.Error.hostNotValid } let success: Bool = autoreleasepool { - let semaphore = DispatchSemaphore(value: 0) + let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0) var success: Bool = false request.get(api: "") { result in switch result { diff --git a/Sources/MeiliSearch/Constants.swift b/Sources/MeiliSearch/Constants.swift index 0739a50d..e0a5d5ac 100644 --- a/Sources/MeiliSearch/Constants.swift +++ b/Sources/MeiliSearch/Constants.swift @@ -3,14 +3,14 @@ import Foundation struct Constants { static let customJSONDecoder: JSONDecoder = { - let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .formatted(Formatter.iso8601) + let decoder: JSONDecoder = JSONDecoder() + decoder.dateDecodingStrategy = JSONDecoder.DateDecodingStrategy.formatted(Formatter.iso8601) return decoder }() static let customJSONEecoder: JSONEncoder = { - let encoder = JSONEncoder() - encoder.dateEncodingStrategy = .formatted(Formatter.iso8601) + let encoder: JSONEncoder = JSONEncoder() + encoder.dateEncodingStrategy = JSONEncoder.DateEncodingStrategy.formatted(Formatter.iso8601) return encoder }() diff --git a/Sources/MeiliSearch/Error.swift b/Sources/MeiliSearch/Error.swift index 809001e8..bbd8463f 100644 --- a/Sources/MeiliSearch/Error.swift +++ b/Sources/MeiliSearch/Error.swift @@ -7,7 +7,7 @@ public extension MeiliSearch { // MARK: Error - ///Generic Error types for MeiliSearch, + /// Generic Error types for MeiliSearch, enum Error: Swift.Error { /// The client tried to contact the server but it was not found. @@ -25,5 +25,5 @@ public extension MeiliSearch { } -///Allow use of error comparasion for the MeiliSearch.Error type. +/// Allow use of error comparasion for the MeiliSearch.Error type. extension MeiliSearch.Error: Equatable {} diff --git a/Sources/MeiliSearch/Indexes.swift b/Sources/MeiliSearch/Indexes.swift index a0621eeb..78a3cca2 100755 --- a/Sources/MeiliSearch/Indexes.swift +++ b/Sources/MeiliSearch/Indexes.swift @@ -87,9 +87,8 @@ struct Indexes { _ UID: String, _ completion: @escaping (Result) -> Void) { - let payload = CreateIndexPayload(uid: UID) + let payload: CreateIndexPayload = CreateIndexPayload(uid: UID) let data: Data - do { data = try JSONEncoder().encode(payload) } catch { @@ -124,8 +123,14 @@ struct Indexes { _ primaryKey: String, _ completion: @escaping (Result) -> Void) { - let payload = UpdateIndexPayload(primaryKey: primaryKey) - let data: Data = try! JSONEncoder().encode(payload) + let payload: UpdateIndexPayload = UpdateIndexPayload(primaryKey: primaryKey) + let data: Data + do { + data = try JSONEncoder().encode(payload) + } catch { + completion(.failure(MeiliSearch.Error.invalidJSON)) + return + } self.request.put(api: "/indexes/\(UID)", data) { result in @@ -216,7 +221,7 @@ public enum CreateError: Swift.Error, Equatable { let underlyingError: NSError = error.underlying as NSError - if let data = error.data { + if let data: Data = error.data { let msErrorResponse: MSErrorResponse? do { diff --git a/Sources/MeiliSearch/Model/Dump.swift b/Sources/MeiliSearch/Model/Dump.swift index b6d94b03..9d49fb4c 100644 --- a/Sources/MeiliSearch/Model/Dump.swift +++ b/Sources/MeiliSearch/Model/Dump.swift @@ -29,15 +29,15 @@ public struct Dump: Codable, Equatable { } public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let rawStatus = try container.decode(String.self) + let container: SingleValueDecodingContainer = try decoder.singleValueContainer() + let rawStatus: String = try container.decode(String.self) switch rawStatus { case "in_progress": - self = .inProgress + self = Status.inProgress case "dump_process_failed": - self = .failed + self = Status.failed case "done": - self = .done + self = Status.done default: throw CodingError.unknownStatus } diff --git a/Sources/MeiliSearch/Model/Key.swift b/Sources/MeiliSearch/Model/Key.swift index ef6e48ad..b1de4df9 100644 --- a/Sources/MeiliSearch/Model/Key.swift +++ b/Sources/MeiliSearch/Model/Key.swift @@ -8,10 +8,10 @@ public struct Key: Codable, Equatable { // MARK: Properties - ///Private key used to access a determined set of API routes. + /// Private key used to access a determined set of API routes. public let `private`: String - ///Public key used to access a determined set of API routes. + /// Public key used to access a determined set of API routes. public let `public`: String } diff --git a/Sources/MeiliSearch/Model/Setting.swift b/Sources/MeiliSearch/Model/Setting.swift index b9b52017..a826bfa4 100644 --- a/Sources/MeiliSearch/Model/Setting.swift +++ b/Sources/MeiliSearch/Model/Setting.swift @@ -35,7 +35,7 @@ extension Setting { /// Tries to decode the JSON object to Setting object. public init(from decoder: Decoder) throws { - let values = try? decoder.container(keyedBy: CodingKeys.self) + let values: KeyedDecodingContainer? = try? decoder.container(keyedBy: CodingKeys.self) rankingRules = (try? values?.decodeIfPresent([String].self, forKey: .rankingRules)) ?? [] searchableAttributes = (try? values?.decodeIfPresent([String].self, forKey: .searchableAttributes)) ?? ["*"] displayedAttributes = (try? values?.decodeIfPresent([String].self, forKey: .displayedAttributes)) ?? ["*"] diff --git a/Sources/MeiliSearch/Model/Update.swift b/Sources/MeiliSearch/Model/Update.swift index cf1d78af..02196cbf 100644 --- a/Sources/MeiliSearch/Model/Update.swift +++ b/Sources/MeiliSearch/Model/Update.swift @@ -11,30 +11,30 @@ public struct Update: Codable, Equatable { /// The UID of the update. public let updateId: Int - ///Result type for the Update. + /// Result type for the Update. public struct Result: Codable, Equatable { // MARK: Properties - ///Returns if the update has been sucessful or not. + /// Returns if the update has been sucessful or not. public let status: Status - ///Unique ID for the current `Update`. + /// Unique ID for the current `Update`. public let updateId: Int - ///Type of update. + /// Type of update. public let type: UpdateType - ///Duration of the update process. + /// Duration of the update process. public let duration: TimeInterval? - ///Date when the update has been enqueued. + /// Date when the update has been enqueued. public let enqueuedAt: Date - ///Date when the update has been processed. + /// Date when the update has been processed. public let processedAt: Date? - ///Type of `Update`. + /// Type of `Update`. public struct UpdateType: Codable, Equatable { // MARK: Properties @@ -60,15 +60,15 @@ public struct Update: Codable, Equatable { } public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let rawStatus = try container.decode(String.self) + let container: SingleValueDecodingContainer = try decoder.singleValueContainer() + let rawStatus: String = try container.decode(String.self) switch rawStatus { case "enqueued": - self = .enqueued + self = Status.enqueued case "processed": - self = .processed + self = Status.processed case "failed": - self = .failed + self = Status.failed default: throw StatusError.unknown } diff --git a/Sources/MeiliSearch/Request.swift b/Sources/MeiliSearch/Request.swift index a3c807a9..c348cf65 100755 --- a/Sources/MeiliSearch/Request.swift +++ b/Sources/MeiliSearch/Request.swift @@ -8,7 +8,7 @@ public protocol URLSessionProtocol { /// Result for the `execute` function. typealias DataTaskResult = (Data?, URLResponse?, Error?) -> Void - ///Function that will trigger the HTTP request. + /// Function that will trigger the HTTP request. func execute( with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTaskProtocol @@ -17,10 +17,14 @@ public protocol URLSessionProtocol { /// URLSessionDataTaskProtocol handler. public protocol URLSessionDataTaskProtocol { - ///Trigger HTTP request. + /// Trigger HTTP request. func resume() } +public enum MSHTTPError: Swift.Error { + case invalidURL +} + struct MSError: Swift.Error { let data: Data? let underlying: Swift.Error @@ -56,7 +60,12 @@ final class Request { urlString += param } - var request: URLRequest = URLRequest(url: URL(string: urlString)!) + guard let url: URL = URL(string: urlString) else { + completion(.failure(MSHTTPError.invalidURL)) + return + } + + var request: URLRequest = URLRequest(url: url) request.httpMethod = "GET" headers.forEach { (key, value) in request.addValue(value, forHTTPHeaderField: key) @@ -97,8 +106,12 @@ final class Request { _ data: Data, _ completion: @escaping (Result) -> Void) { - let urlString: String = config.url(api: api) - var request: URLRequest = URLRequest(url: URL(string: urlString)!) + guard let url: URL = URL(string: config.url(api: api)) else { + completion(.failure(MSHTTPError.invalidURL)) + return + } + + var request: URLRequest = URLRequest(url: url) request.httpMethod = "POST" request.httpBody = data request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") @@ -111,7 +124,7 @@ final class Request { let task: URLSessionDataTaskProtocol = session.execute(with: request) { (data, response, error) in if let error: Swift.Error = error { - let msError = MSError(data: data, underlying: error) + let msError: MSError = MSError(data: data, underlying: error) completion(.failure(msError)) return } @@ -144,8 +157,12 @@ final class Request { _ data: Data, _ completion: @escaping (Result) -> Void) { - let urlString: String = config.url(api: api) - var request: URLRequest = URLRequest(url: URL(string: urlString)!) + guard let url: URL = URL(string: config.url(api: api)) else { + completion(.failure(MSHTTPError.invalidURL)) + return + } + + var request: URLRequest = URLRequest(url: url) request.httpMethod = "PUT" request.httpBody = data request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") @@ -184,8 +201,12 @@ final class Request { api: String, _ completion: @escaping (Result) -> Void) { - let urlString: String = config.url(api: api) - var request: URLRequest = URLRequest(url: URL(string: urlString)!) + guard let url: URL = URL(string: config.url(api: api)) else { + completion(.failure(MSHTTPError.invalidURL)) + return + } + + var request: URLRequest = URLRequest(url: url) request.httpMethod = "DELETE" request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Accept") diff --git a/Sources/MeiliSearch/Settings.swift b/Sources/MeiliSearch/Settings.swift index 9c38c9aa..ec76ba0e 100644 --- a/Sources/MeiliSearch/Settings.swift +++ b/Sources/MeiliSearch/Settings.swift @@ -125,8 +125,7 @@ struct Settings { } do { - let dictionary: [String: [String]] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String: [String]] + let dictionary: [String: [String]] = try Constants.customJSONDecoder.decode([String: [String]].self, from: data) completion(.success(dictionary)) } catch { completion(.failure(error)) @@ -219,9 +218,8 @@ struct Settings { } do { - let dictionary: [String] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String] - completion(.success(dictionary)) + let array: [String] = try Constants.customJSONDecoder.decode([String].self, from: data) + completion(.success(array)) } catch { completion(.failure(error)) } @@ -313,9 +311,8 @@ struct Settings { } do { - let dictionary: [String] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String] - completion(.success(dictionary)) + let array: [String] = try Constants.customJSONDecoder.decode([String].self, from: data) + completion(.success(array)) } catch { completion(.failure(error)) } @@ -413,10 +410,12 @@ struct Settings { return } - let distinctAttribute: String? = - try? Constants.customJSONDecoder.decode(String.self, from: data) - - completion(.success(distinctAttribute)) + do { + let value: String? = try Constants.customJSONDecoder.decode(String?.self, from: data) + completion(.success(value)) + } catch { + completion(.failure(error)) + } case .failure(let error): completion(.failure(error)) @@ -431,10 +430,9 @@ struct Settings { _ distinctAttribute: String, _ completion: @escaping (Result) -> Void) { - let encoder = JSONEncoder() let data: Data do { - data = try encoder.encode(DistinctAttributePayload(distinctAttribute: distinctAttribute)) + data = try Constants.customJSONEecoder.encode(DistinctAttributePayload(distinctAttribute: distinctAttribute)) } catch { completion(.failure(error)) return @@ -506,9 +504,8 @@ struct Settings { } do { - let dictionary: [String] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String] - completion(.success(dictionary)) + let array: [String] = try Constants.customJSONDecoder.decode([String].self, from: data) + completion(.success(array)) } catch { completion(.failure(error)) } @@ -600,9 +597,8 @@ struct Settings { } do { - let dictionary: [String] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String] - completion(.success(dictionary)) + let array: [String] = try Constants.customJSONDecoder.decode([String].self, from: data) + completion(.success(array)) } catch { completion(.failure(error)) } @@ -694,9 +690,8 @@ struct Settings { } do { - let dictionary: [String] = try JSONSerialization - .jsonObject(with: data, options: []) as! [String] - completion(.success(dictionary)) + let array: [String] = try Constants.customJSONDecoder.decode([String].self, from: data) + completion(.success(array)) } catch { completion(.failure(error)) } diff --git a/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift b/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift index b0c6ead7..2ae37659 100755 --- a/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift +++ b/Tests/MeiliSearchIntegrationTests/DocumentsTests.swift @@ -177,7 +177,7 @@ class DocumentsTests: XCTestCase { } self.wait(for: [getExpectation], timeout: 3.0) } - + func testAddAndGetOneDocumentWithIntIdentifierAndSucceed() { let movie: Movie = Movie(id: 10, title: "test", comment: "test movie") @@ -195,7 +195,6 @@ class DocumentsTests: XCTestCase { case .success(let update): - XCTAssertEqual(Update(updateId: 0), update) waitForPendingUpdate(self.client, self.uid, update) { @@ -429,7 +428,7 @@ class DocumentsTests: XCTestCase { } } - + case .failure: XCTFail("Failed to add or replace Movies document") expectation.fulfill() diff --git a/Tests/MeiliSearchIntegrationTests/XCTestManifests.swift b/Tests/MeiliSearchIntegrationTests/XCTestManifests.swift index 4a3f04c6..88e65bb7 100755 --- a/Tests/MeiliSearchIntegrationTests/XCTestManifests.swift +++ b/Tests/MeiliSearchIntegrationTests/XCTestManifests.swift @@ -10,7 +10,7 @@ import XCTest -#if !os(macOS) +#if !canImport(ObjectiveC) public func allTests() -> [XCTestCaseEntry] { [ testCase(IndexesTests.allTests), diff --git a/Tests/MeiliSearchUnitTests/DocumentsTests.swift b/Tests/MeiliSearchUnitTests/DocumentsTests.swift index 28002a6e..ba283771 100755 --- a/Tests/MeiliSearchUnitTests/DocumentsTests.swift +++ b/Tests/MeiliSearchUnitTests/DocumentsTests.swift @@ -31,7 +31,7 @@ class DocumentsTests: XCTestCase { func testAddDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -76,7 +76,7 @@ class DocumentsTests: XCTestCase { func testAddDataDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -129,7 +129,7 @@ class DocumentsTests: XCTestCase { func testUpdateDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -179,7 +179,7 @@ class DocumentsTests: XCTestCase { func testGetDocument() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -223,7 +223,7 @@ class DocumentsTests: XCTestCase { func testGetDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ [{ @@ -273,7 +273,7 @@ class DocumentsTests: XCTestCase { func testDeleteDocument() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -310,7 +310,7 @@ class DocumentsTests: XCTestCase { func testDeleteAllDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -345,7 +345,7 @@ class DocumentsTests: XCTestCase { func testDeleteBatchDocuments() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} diff --git a/Tests/MeiliSearchUnitTests/DumpsTests.swift b/Tests/MeiliSearchUnitTests/DumpsTests.swift index 50d983b0..86baf178 100644 --- a/Tests/MeiliSearchUnitTests/DumpsTests.swift +++ b/Tests/MeiliSearchUnitTests/DumpsTests.swift @@ -13,7 +13,7 @@ class DumpsTests: XCTestCase { func testCreateDump() { - //Prepare the mock server + // Prepare the mock server let json = """ { @@ -48,7 +48,7 @@ class DumpsTests: XCTestCase { func testGetDumpStatus() { - //Prepare the mock server + // Prepare the mock server let json = """ { diff --git a/Tests/MeiliSearchUnitTests/IndexesTests.swift b/Tests/MeiliSearchUnitTests/IndexesTests.swift index 11f02592..f1cca06a 100755 --- a/Tests/MeiliSearchUnitTests/IndexesTests.swift +++ b/Tests/MeiliSearchUnitTests/IndexesTests.swift @@ -13,7 +13,7 @@ class IndexesTests: XCTestCase { func testCreateIndex() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -53,7 +53,7 @@ class IndexesTests: XCTestCase { func testGetOrCreateIndex() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -93,7 +93,7 @@ class IndexesTests: XCTestCase { func testGetOrCreateIndexAlreadyExists() { - //Prepare the mock server + // Prepare the mock server let createJsonString = """ {"message":"Impossible to create index; index already exists","errorType":"invalid_request_error","errorCode":"index_already_exists"} @@ -139,7 +139,7 @@ class IndexesTests: XCTestCase { func testGetIndex() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -181,7 +181,7 @@ class IndexesTests: XCTestCase { func testGetIndexes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ [{ @@ -221,7 +221,7 @@ class IndexesTests: XCTestCase { func testUpdateIndex() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -261,7 +261,7 @@ class IndexesTests: XCTestCase { func testDeleteIndex() { - //Prepare the mock server + // Prepare the mock server session.pushEmpty(code: 204) diff --git a/Tests/MeiliSearchUnitTests/KeysTests.swift b/Tests/MeiliSearchUnitTests/KeysTests.swift index eb682133..ec6fa62c 100644 --- a/Tests/MeiliSearchUnitTests/KeysTests.swift +++ b/Tests/MeiliSearchUnitTests/KeysTests.swift @@ -17,7 +17,7 @@ class KeysTests: XCTestCase { func testKeys() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { diff --git a/Tests/MeiliSearchUnitTests/SearchTests.swift b/Tests/MeiliSearchUnitTests/SearchTests.swift index e218ffc0..203dc319 100644 --- a/Tests/MeiliSearchUnitTests/SearchTests.swift +++ b/Tests/MeiliSearchUnitTests/SearchTests.swift @@ -31,7 +31,7 @@ class SearchTests: XCTestCase { func testSearchForBotmanMovie() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -91,7 +91,7 @@ class SearchTests: XCTestCase { func testSearchForBotmanMovieFacets() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { diff --git a/Tests/MeiliSearchUnitTests/SettingsTests.swift b/Tests/MeiliSearchUnitTests/SettingsTests.swift index 0783abde..ebe5ecbf 100644 --- a/Tests/MeiliSearchUnitTests/SettingsTests.swift +++ b/Tests/MeiliSearchUnitTests/SettingsTests.swift @@ -52,7 +52,7 @@ class SettingsTests: XCTestCase { func testGetSetting() { - //Prepare the mock server + // Prepare the mock server let stubSetting: Setting = buildStubSetting(from: json) @@ -80,7 +80,7 @@ class SettingsTests: XCTestCase { func testUpdateSetting() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -115,7 +115,7 @@ class SettingsTests: XCTestCase { func testResetSetting() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -151,7 +151,7 @@ class SettingsTests: XCTestCase { func testGetSynonyms() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -189,7 +189,7 @@ class SettingsTests: XCTestCase { func testUpdateSynonyms() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -236,7 +236,7 @@ class SettingsTests: XCTestCase { func testResetSynonyms() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -273,7 +273,7 @@ class SettingsTests: XCTestCase { func testGetStopWords() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ ["of", "the", "to"] @@ -307,7 +307,7 @@ class SettingsTests: XCTestCase { func testUpdateStopWords() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -349,7 +349,7 @@ class SettingsTests: XCTestCase { func testResetStopWords() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -386,7 +386,7 @@ class SettingsTests: XCTestCase { func testGetRankingRules() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ [ @@ -428,7 +428,7 @@ class SettingsTests: XCTestCase { func testUpdateRankingRules() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -470,7 +470,7 @@ class SettingsTests: XCTestCase { func testResetRankingRules() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -507,7 +507,7 @@ class SettingsTests: XCTestCase { func testGetDistinctAttribute() { - //Prepare the mock server + // Prepare the mock server let stubDistinctAttribute: String = """ "movie_id" @@ -537,7 +537,7 @@ class SettingsTests: XCTestCase { func testUpdateDistinctAttribute() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -573,7 +573,7 @@ class SettingsTests: XCTestCase { func testResetDistinctAttribute() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -610,7 +610,7 @@ class SettingsTests: XCTestCase { func testGetSearchableAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ ["title", "description", "uid"] @@ -644,7 +644,7 @@ class SettingsTests: XCTestCase { func testUpdateSearchableAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -687,7 +687,7 @@ class SettingsTests: XCTestCase { func testResetSearchableAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -724,7 +724,7 @@ class SettingsTests: XCTestCase { func testGetDisplayedAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ ["title", "description", "release_date", "rank", "poster"] @@ -758,7 +758,7 @@ class SettingsTests: XCTestCase { func testUpdateDisplayedAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -801,7 +801,7 @@ class SettingsTests: XCTestCase { func testResetDisplayedAttributes() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -838,7 +838,7 @@ class SettingsTests: XCTestCase { func testGetAttributesForFaceting() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ ["genre", "director"] @@ -868,7 +868,7 @@ class SettingsTests: XCTestCase { func testUpdateAttributesForFaceting() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":0} @@ -904,7 +904,7 @@ class SettingsTests: XCTestCase { func testResetAttributesForFaceting() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ {"updateId":1} diff --git a/Tests/MeiliSearchUnitTests/StatsTests.swift b/Tests/MeiliSearchUnitTests/StatsTests.swift index fc3cda85..1f5e0b04 100755 --- a/Tests/MeiliSearchUnitTests/StatsTests.swift +++ b/Tests/MeiliSearchUnitTests/StatsTests.swift @@ -14,7 +14,7 @@ class StatsTests: XCTestCase { func testStats() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -58,7 +58,7 @@ class StatsTests: XCTestCase { func testAllStats() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { diff --git a/Tests/MeiliSearchUnitTests/SystemTests.swift b/Tests/MeiliSearchUnitTests/SystemTests.swift index 6bde1324..71fb3cc0 100755 --- a/Tests/MeiliSearchUnitTests/SystemTests.swift +++ b/Tests/MeiliSearchUnitTests/SystemTests.swift @@ -14,7 +14,7 @@ class SystemTests: XCTestCase { func testHealthStatusAvailable() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -48,7 +48,7 @@ class SystemTests: XCTestCase { func testIsHealthyTrue() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { @@ -63,7 +63,7 @@ class SystemTests: XCTestCase { let expectation = XCTestExpectation(description: "Check if is healthy is true") self.client.isHealthy { result in - if (result == true) { + if result == true { XCTAssertEqual(result, true) expectation.fulfill() } else { @@ -77,7 +77,7 @@ class SystemTests: XCTestCase { func testIsHealthyFalse() { - //Prepare the mock server + // Prepare the mock server session.pushData("", code: 400) @@ -86,7 +86,7 @@ class SystemTests: XCTestCase { let expectation = XCTestExpectation(description: "Check if is healthy is false") self.client.isHealthy { result in - if (result == false) { + if result == false { XCTAssertEqual(result, false) expectation.fulfill() } else { @@ -100,7 +100,7 @@ class SystemTests: XCTestCase { func testVersion() { - //Prepare the mock server + // Prepare the mock server let jsonString = """ { diff --git a/Tests/MeiliSearchUnitTests/UpdatesTests.swift b/Tests/MeiliSearchUnitTests/UpdatesTests.swift index e6887147..ffcd5879 100644 --- a/Tests/MeiliSearchUnitTests/UpdatesTests.swift +++ b/Tests/MeiliSearchUnitTests/UpdatesTests.swift @@ -13,7 +13,7 @@ class UpdatesTests: XCTestCase { func testGetUpdate() { - //Prepare the mock server + // Prepare the mock server let json = """ { @@ -59,7 +59,7 @@ class UpdatesTests: XCTestCase { func testGetUpdateInvalidStatus() { - //Prepare the mock server + // Prepare the mock server let badStatusUpdateJson = """ { @@ -100,7 +100,7 @@ class UpdatesTests: XCTestCase { func testGetAllUpdates() { - //Prepare the mock server + // Prepare the mock server let json = """ [ diff --git a/Tests/MeiliSearchUnitTests/XCTestManifests.swift b/Tests/MeiliSearchUnitTests/XCTestManifests.swift index 8cca0a35..e49c508b 100755 --- a/Tests/MeiliSearchUnitTests/XCTestManifests.swift +++ b/Tests/MeiliSearchUnitTests/XCTestManifests.swift @@ -10,7 +10,7 @@ import XCTest -#if !os(macOS) +#if !canImport(ObjectiveC) public func allTests() -> [XCTestCaseEntry] { [ testCase(IndexesTests.allTests), From 2e37079f9310be3b641a3bc9338a870994497940 Mon Sep 17 00:00:00 2001 From: Pedro Paulo de Amorim Date: Thu, 20 May 2021 00:05:53 +0100 Subject: [PATCH 2/3] Update Xcode version on tests.yml --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7fa18be1..9bee9ae8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: name: integration-tests runs-on: macos-latest env: - DEVELOPER_DIR: /Applications/Xcode_11.5.app/Contents/Developer + DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer steps: - uses: actions/checkout@v2 - name: Download and run MeiliSearch @@ -30,7 +30,7 @@ jobs: name: linter-check runs-on: macos-latest env: - DEVELOPER_DIR: /Applications/Xcode_11.5.app/Contents/Developer + DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer steps: - uses: actions/checkout@v2 - name: Run SwiftLint From 1224262902acb102f22438ec4376263fd05832cf Mon Sep 17 00:00:00 2001 From: Pedro Paulo Amorim Date: Mon, 31 May 2021 21:56:48 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- Sources/MeiliSearch/Config.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MeiliSearch/Config.swift b/Sources/MeiliSearch/Config.swift index 72916780..4bc12b7a 100755 --- a/Sources/MeiliSearch/Config.swift +++ b/Sources/MeiliSearch/Config.swift @@ -11,7 +11,7 @@ public class Config { // MARK: Static - /// Deafault configuration for the default MeiliSearch host, do not use this in + /// Default configuration for the default MeiliSearch host, do not use this in /// production since it does not contains the apiKey. public static let `default`: Config = Config(hostURL: localhost)