-
Notifications
You must be signed in to change notification settings - Fork 26
Remove unused code in KeyTests & Add a cleanup step before KeyTests #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,69 +5,93 @@ import Foundation | |
| // swiftlint:disable force_try | ||
| class KeysTests: XCTestCase { | ||
| private var client: MeiliSearch! | ||
| private var key: String = "" | ||
| private var session: URLSessionProtocol! | ||
|
|
||
| // MARK: Setup | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
|
|
||
| session = URLSession(configuration: .ephemeral) | ||
| client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "masterKey", session: session) | ||
| let keyExpectation = XCTestExpectation(description: "Get all keys") | ||
|
|
||
| self.client.getKeys { result in | ||
| // remove all keys to keep a clean state | ||
| self.client.getKeys(params: KeysQuery(limit: 100, offset: 0)) { result in | ||
| switch result { | ||
| case .success(let keys): | ||
| if keys.results.count > 0 { | ||
| let key = keys.results.first | ||
| if let firstKey: Key = key { | ||
| self.key = firstKey.key | ||
| keys.results.forEach { | ||
| self.client.deleteKey(key: $0.uid) { result in | ||
| switch result { | ||
| case .success: | ||
| () | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we define a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if you are not interested in the success is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, but that's the point, this code is written inside of the setup(), so it's not meant to be a "test" so in other words, no expectation should be needed 😬 |
||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to delete key") | ||
| } | ||
| } | ||
| } else { | ||
| XCTFail("Failed to get keys") | ||
| } | ||
| keyExpectation.fulfill() | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to get keys") | ||
| keyExpectation.fulfill() | ||
| XCTFail("Failed to retrieve and delete all keys") | ||
| } | ||
| } | ||
bidoubiwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.wait(for: [keyExpectation], timeout: TESTS_TIME_OUT) | ||
| } | ||
|
|
||
| func testGetKeys() { | ||
| let keyExpectation = XCTestExpectation(description: "Get all keys") | ||
| let keyExpectation = XCTestExpectation(description: "Get a list of keys") | ||
|
|
||
| self.client.getKeys { result in | ||
| self.client.createKey(KeyParams(actions: ["*"], indexes: ["*"], expiresAt: nil)) { result in | ||
| switch result { | ||
| case .success(let keys): | ||
| XCTAssertNotEqual(keys.results.count, 0) | ||
| case .success: | ||
| self.client.getKeys { result in | ||
| switch result { | ||
| case .success(let keys): | ||
| XCTAssertNotEqual(keys.results.count, 0) | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to get all keys") | ||
| } | ||
| } | ||
|
|
||
| keyExpectation.fulfill() | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to get all keys") | ||
| XCTFail("Failed to create a key") | ||
| keyExpectation.fulfill() | ||
| } | ||
| } | ||
|
|
||
| self.wait(for: [keyExpectation], timeout: TESTS_TIME_OUT) | ||
| } | ||
|
|
||
| func testGetKey() { | ||
| let keyExpectation = XCTestExpectation(description: "Get one key") | ||
|
|
||
| self.client.getKey(key: self.key) { result in | ||
| self.client.createKey(KeyParams(actions: ["*"], indexes: ["*"], expiresAt: nil)) { result in | ||
| switch result { | ||
| case .success(let key): | ||
| XCTAssertNotNil(key.description) | ||
| case .success(let createdKey): | ||
| self.client.getKey(key: createdKey.uid) { result in | ||
bidoubiwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| switch result { | ||
| case .success(let fetchedKey): | ||
| XCTAssertEqual(fetchedKey.expiresAt, nil) | ||
| XCTAssertEqual(fetchedKey.description, createdKey.description) | ||
| XCTAssertEqual(fetchedKey.actions, createdKey.actions) | ||
| XCTAssertEqual(fetchedKey.indexes, createdKey.indexes) | ||
| XCTAssertEqual(fetchedKey.uid, createdKey.uid) | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to get key by uid \(createdKey.uid)") | ||
| } | ||
| } | ||
|
|
||
| keyExpectation.fulfill() | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to get a key") | ||
| XCTFail("Failed to create a key") | ||
| keyExpectation.fulfill() | ||
| } | ||
| } | ||
|
|
||
| self.wait(for: [keyExpectation], timeout: TESTS_TIME_OUT) | ||
| } | ||
|
|
||
|
|
@@ -93,6 +117,29 @@ class KeysTests: XCTestCase { | |
| self.wait(for: [keyExpectation], timeout: TESTS_TIME_OUT) | ||
| } | ||
|
|
||
| func testCreateKeyWithOptionalUid() { | ||
| let keyExpectation = XCTestExpectation(description: "Create a key") | ||
| let uid = "1f05fa47-cfa6-40f7-8b80-7bd17b39f105" | ||
| let keyParams = KeyParams(uid: uid, actions: ["*"], indexes: ["*"], expiresAt: nil) | ||
|
|
||
| self.client.createKey(keyParams) { result in | ||
| switch result { | ||
| case .success(let key): | ||
| XCTAssertEqual(key.expiresAt, nil) | ||
| XCTAssertEqual(key.uid, uid) | ||
| XCTAssertEqual(key.actions, keyParams.actions) | ||
| XCTAssertEqual(key.indexes, keyParams.indexes) | ||
| keyExpectation.fulfill() | ||
| case .failure(let error): | ||
| dump(error) | ||
| XCTFail("Failed to create a key") | ||
| keyExpectation.fulfill() | ||
| } | ||
| } | ||
|
|
||
| self.wait(for: [keyExpectation], timeout: TESTS_TIME_OUT) | ||
| } | ||
|
|
||
| func testCreateKeyWithExpire() { | ||
| let keyExpectation = XCTestExpectation(description: "Create a key with an expireAt value") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, why are some var and some let? We cant change
actions? Is this because ofupdateKey?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct!