diff --git a/Sources/MeiliSearch/Client.swift b/Sources/MeiliSearch/Client.swift index e840184f..02fa5316 100755 --- a/Sources/MeiliSearch/Client.swift +++ b/Sources/MeiliSearch/Client.swift @@ -71,24 +71,6 @@ public struct MeiliSearch { Indexes.create(uid: uid, primaryKey: primaryKey, config: self.config, completion) } - /** - Get or create an index. - - - parameter uid: The unique identifier for the `Index` to be created. - - parameter primaryKey: the unique field of a document. - - parameter completion: The completion closure used to notify when the server - completes the write request, it returns a `Result` object that contains `Index` - value. If the request was sucessful or `Error` if a failure occured. - */ - - // TODO: remove in another PR - // public func getOrCreateIndex( - // uid: String, - // primaryKey: String? = nil, - // _ completion: @escaping (Result) -> Void) { - // Indexes.getOrCreate(uid: uid, primaryKey: primaryKey, config: self.config, completion) - // } - /** Get an index. diff --git a/Sources/MeiliSearch/Indexes.swift b/Sources/MeiliSearch/Indexes.swift index b06e2a02..e078b013 100755 --- a/Sources/MeiliSearch/Indexes.swift +++ b/Sources/MeiliSearch/Indexes.swift @@ -116,42 +116,6 @@ public struct Indexes { } } - // TODO: remove - /** - Get or create an index. - - - parameter uid: The unique identifier for the `Index` to be created. - - parameter primaryKey: the unique field of a document. - - parameter completion: The completion closure used to notify when the server - completes the write request, it returns a `Result` object that contains `Index` - value. If the request was sucessful or `Error` if a failure occured. - */ - // public static func getOrCreate( - // uid: String, - // primaryKey: String? = nil, - // config: Config, - // _ completion: @escaping (Result) -> Void) { - // Indexes.create(uid: uid, primaryKey: primaryKey, config: config) { result in - // switch result { - // case .success(let index): - // completion(.success(index)) - // case .failure(let error): - // switch error { - // case MeiliSearch.Error.meiliSearchApiError(_, let msErrorResponse, _, _): - // if let msErrorBody: MeiliSearch.MSErrorResponse = msErrorResponse { - // if msErrorBody.code == "index_already_exists" { - // Indexes(config: config, uid: uid).get(completion) - // } - // } else { - // completion(.failure(error)) - // } - // default: - // completion(.failure(error)) - // } - // } - // } - // } - /** Create a new Index for the given `uid`. @@ -259,25 +223,7 @@ public struct Indexes { } } - /** - Delete the index only if it exists. - - - parameter completion: The completion closure used to notify when the server - completes the delete request, it returns a `Bool` that is `true` - If the request sucessfully deleted an existent index or `false` if a failure occured or the index do not exist. - */ - public func deleteIfExists(_ completion: @escaping (Bool) -> Void) { - self.request.delete(api: "/indexes/\(self.uid)") { result in - switch result { - case .success: - completion(true) - default: - completion(false) - } - } - } - - // MARK: Document + // MARK: Document /** Add a list of documents or replace them if they already exist. diff --git a/Tests/MeiliSearchIntegrationTests/IndexesTests.swift b/Tests/MeiliSearchIntegrationTests/IndexesTests.swift index ac9af2bb..573ff3fb 100644 --- a/Tests/MeiliSearchIntegrationTests/IndexesTests.swift +++ b/Tests/MeiliSearchIntegrationTests/IndexesTests.swift @@ -275,58 +275,5 @@ class IndexesTests: XCTestCase { self.wait(for: [deleteException], timeout: 20.0) } - // TODO: remove - // func testGetOrCreateIndex() { - // let expectation = XCTestExpectation(description: "Get or create Movies index") - - // self.client.getOrCreateIndex(uid: self.uid) { result in - // switch result { - // case .success(let index): - // let stubIndex = self.client.index(self.uid) - // XCTAssertEqual(stubIndex.uid, index.uid) - // expectation.fulfill() - // case .failure(let error): -// dump(error) - // XCTFail("Failed to get or create Movies index") - // } - // } - - // self.wait(for: [expectation], timeout: 20.0) - // } - - // func testGetOrCreateIndexAlreadyExists() { - // let expectation = XCTestExpectation(description: "Get or create a non existing uid") - - // self.client.getOrCreateIndex(uid: self.uid) { result in - // switch result { - // case .success(let index): - // let stubIndex = self.client.index(self.uid) - // XCTAssertEqual(stubIndex.uid, index.uid) - // expectation.fulfill() - // case .failure(let error): - // XCTFail("Failed to get or create Movies index, error: \(error)") - // } - // } - - // self.wait(for: [expectation], timeout: 20.0) - - // sleep(2) - - // let secondExpectation = XCTestExpectation(description: "Get or create an existing index") - - // self.client.getOrCreateIndex(uid: self.uid) { result in - // switch result { - // case .success(let index): - // let stubIndex = self.client.index(self.uid) - // XCTAssertEqual(stubIndex.uid, index.uid) - // secondExpectation.fulfill() - // case .failure(let error): - // XCTFail("Failed to get or create an existing index, error: \(error)") - // } - // } - - // self.wait(for: [secondExpectation], timeout: 20.0) - // } - } // swiftlint:enable force_try diff --git a/Tests/MeiliSearchUnitTests/IndexesTests.swift b/Tests/MeiliSearchUnitTests/IndexesTests.swift index eed64b50..8543b7a6 100755 --- a/Tests/MeiliSearchUnitTests/IndexesTests.swift +++ b/Tests/MeiliSearchUnitTests/IndexesTests.swift @@ -44,35 +44,6 @@ class IndexesTests: XCTestCase { } self.wait(for: [expectation], timeout: 20.0) } -// TODO: remove - // func testGetOrCreateIndex() { - // let jsonString = """ - // { - // "name":"Movies", - // "uid":"movies_test", - // "createdAt":"2020-04-04T19:59:49.259572Z", - // "updatedAt":"2020-04-04T19:59:49.259579Z", - // "primaryKey":null - // } - // """ - // // Prepare the mock server - // session.pushData(jsonString) - - // // Start the test with the mocked server - // let expectation = XCTestExpectation(description: "Get or create Movies index") - - // self.client.getOrCreateIndex(uid: self.uid) { result in - // switch result { - // case .success(let index): - // XCTAssertEqual(self.uid, index.uid) - // case .failure(let error): - // XCTFail("Failed to get or create Movies index") - // } - // expectation.fulfill() - // } - - // self.wait(for: [expectation], timeout: 20.0) - // } func testGetIndexWithClient() { let jsonString = """ @@ -289,47 +260,6 @@ class IndexesTests: XCTestCase { self.wait(for: [expectation], timeout: 20.0) } - // TODO: remove - // func testDeleteIndexIfExists() { - // // Prepare the mock server - // session.pushEmpty(code: 204) - - // // Start the test with the mocked server - // let expectation = XCTestExpectation(description: "Delete Movies index") - - // self.index.deleteIfExists { result in - // if result { - // XCTAssertTrue(result) - // expectation.fulfill() - // } else { - // XCTFail("Failed to delete Movies index, it was not present on the server") - // } - // expectation.fulfill() - // } - - // self.wait(for: [expectation], timeout: 20.0) - // } - - // TODO: remove - // func testDeleteIndexIfExistsWhenIsnt() { - // // Prepare the mock server - // session.pushEmpty(code: 404) - - // // Start the test with the mocked server - // let expectation = XCTestExpectation(description: "Delete Movies index only if exists") - - // self.index.deleteIfExists { result in - // if !result { - // XCTAssertFalse(result) - // expectation.fulfill() - // } else { - // XCTFail("Deleting the index should have returned false as the index does not exist on the server") - // } - // expectation.fulfill() - // } - - // self.wait(for: [expectation], timeout: 20.0) - // } } // swiftlint:enable force_unwrapping // swiftlint:enable force_try