Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Sources/MeiliSearch/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Index, Swift.Error>) -> Void) {
// Indexes.getOrCreate(uid: uid, primaryKey: primaryKey, config: self.config, completion)
// }

/**
Get an index.

Expand Down
56 changes: 1 addition & 55 deletions Sources/MeiliSearch/Indexes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Index, Swift.Error>) -> 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`.

Expand Down Expand Up @@ -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.
Expand Down
53 changes: 0 additions & 53 deletions Tests/MeiliSearchIntegrationTests/IndexesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 0 additions & 70 deletions Tests/MeiliSearchUnitTests/IndexesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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