Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swift): remaining helpers (#2758)
- Loading branch information
Showing
6 changed files
with
592 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// | ||
// MockSearchClient.swift | ||
// | ||
// | ||
// Created by Algolia on 21/02/2024. | ||
// | ||
|
||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
@testable import Core | ||
@testable import Search | ||
|
||
public class MockSearchClient<T>: SearchClient { | ||
var loop = 0 | ||
var responses: [T] = [] | ||
|
||
public func setResponses(_ elements: [T]) { | ||
self.responses = elements | ||
} | ||
|
||
override public func setSettings( | ||
indexName _: String, | ||
indexSettings _: IndexSettings, | ||
forwardToReplicas _: Bool? = nil, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> UpdatedAtResponse { | ||
UpdatedAtResponse( | ||
taskID: 12345, | ||
updatedAt: "2024-02-20T10:10:00Z" | ||
) | ||
} | ||
|
||
override public func addApiKey( | ||
apiKey _: ApiKey, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> AddApiKeyResponse { | ||
AddApiKeyResponse( | ||
key: "created-api-key", | ||
createdAt: "2024-02-20T10:10:00Z" | ||
) | ||
} | ||
|
||
override public func deleteApiKey( | ||
key _: String, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> DeleteApiKeyResponse { | ||
DeleteApiKeyResponse(deletedAt: "2024-02-20T10:10:00Z") | ||
} | ||
|
||
override public func updateApiKey( | ||
key: String, | ||
apiKey _: ApiKey, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> UpdateApiKeyResponse { | ||
UpdateApiKeyResponse(key: key, updatedAt: "2024-02-20T10:10:00Z") | ||
} | ||
|
||
override public func getTask( | ||
indexName _: String, | ||
taskID _: Int64, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> GetTaskResponse { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! GetTaskResponse | ||
} | ||
|
||
override public func getApiKeyWithHTTPInfo( | ||
key _: String, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> Response<GetApiKeyResponse> { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! Response<GetApiKeyResponse> | ||
} | ||
|
||
override public func browse( | ||
indexName _: String, | ||
browseParams _: BrowseParams? = nil, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> BrowseResponse { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! BrowseResponse | ||
} | ||
|
||
override public func searchRules( | ||
indexName _: String, | ||
searchRulesParams _: SearchRulesParams? = nil, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> SearchRulesResponse { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! SearchRulesResponse | ||
} | ||
|
||
override public func searchSynonyms( | ||
indexName _: String, | ||
searchSynonymsParams _: SearchSynonymsParams? = nil, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> SearchSynonymsResponse { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! SearchSynonymsResponse | ||
} | ||
|
||
override public func search( | ||
searchMethodParams _: SearchMethodParams, | ||
requestOptions _: RequestOptions? = nil | ||
) async throws -> SearchResponses { | ||
defer { | ||
loop += 1 | ||
} | ||
return self.responses[self.loop] as! SearchResponses | ||
} | ||
} |
Oops, something went wrong.