From 197d1989aafac645d1a72c334ae228dd20f46e0d Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 27 Jun 2024 16:05:12 +0200 Subject: [PATCH] feat(swift): generate tests for helpers (#3248) Co-authored-by: Thomas Raffray --- .../Search/Extra/SearchClientExtension.swift | 9 +- .../SecuredApiKeyRestrictionExtension.swift | 1 + .../codegen/AlgoliaCSharpGenerator.java | 2 + .../algolia/codegen/AlgoliaJavaGenerator.java | 2 + .../codegen/AlgoliaSwiftGenerator.java | 16 +--- .../cts/manager/CTSManagerFactory.java | 2 +- .../codegen/cts/manager/GoCTSManager.java | 8 ++ .../cts/tests/ParametersWithDataType.java | 4 - scripts/cts/runCts.ts | 2 +- specs/query-suggestions/common/parameters.yml | 2 +- ...Response.yml => ConfigurationResponse.yml} | 4 +- ...onsConfiguration.yml => Configuration.yml} | 8 +- ...SuggestionsIndexName.yml => IndexName.yml} | 0 .../paths/getConfigurationStatus.yml | 2 +- specs/query-suggestions/paths/qsConfig.yml | 4 +- specs/query-suggestions/paths/qsConfigs.yml | 4 +- templates/go/client.mustache | 8 +- templates/go/configuration.mustache | 4 +- .../go/tests/client/createClient.mustache | 2 +- templates/go/tests/client/suite.mustache | 4 +- templates/go/tests/requests/requests.mustache | 2 +- templates/swift/api.mustache | 6 +- templates/swift/tests/client/method.mustache | 5 +- templates/swift/tests/client/suite.mustache | 26 ++--- .../swift/tests/requests/requests.mustache | 2 +- .../query-suggestions/updateConfig.json | 2 +- .../csharp/src/ClientExtensionsTests.cs | 2 +- tests/output/swift/Tests/Utils/Utils.swift | 7 +- .../swift/Tests/handwritten/E2ESearch.swift | 95 ------------------- .../handwritten/SecuredApiKeyHelpers.swift | 18 ---- 30 files changed, 71 insertions(+), 182 deletions(-) rename specs/query-suggestions/common/responses/{QuerySuggestionsConfigurationResponse.yml => ConfigurationResponse.yml} (75%) rename specs/query-suggestions/common/schemas/{QuerySuggestionsConfiguration.yml => Configuration.yml} (96%) rename specs/query-suggestions/common/schemas/{QuerySuggestionsIndexName.yml => IndexName.yml} (100%) delete mode 100644 tests/output/swift/Tests/handwritten/E2ESearch.swift diff --git a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift index 8601a33d48..1ebeeb3d0d 100644 --- a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift +++ b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift @@ -525,18 +525,19 @@ public extension SearchClient { /// /// See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation /// details. - /// - parameter objects: The new objects /// - parameter indexName: The name of the index where to replace the objects + /// - parameter objects: The new objects + /// - parameter batchSize: The maximum number of objects to include in a batch /// - parameter requestOptions: The request options /// - returns: ReplaceAllObjectsResponse @discardableResult func replaceAllObjects( - with objects: [some Encodable], - in indexName: String, + indexName: String, + objects: [some Encodable], batchSize: Int = 1000, requestOptions: RequestOptions? = nil ) async throws -> ReplaceAllObjectsResponse { - let tmpIndexName = try "\(indexName)_tmp_\(randomString())" + let tmpIndexName = try "\(indexName)_tmp_\(Int.random(in: 1_000_000 ..< 10_000_000))" var copyOperationResponse = try await operationIndex( indexName: indexName, diff --git a/clients/algoliasearch-client-swift/Sources/Search/Extra/SecuredApiKeyRestrictionExtension.swift b/clients/algoliasearch-client-swift/Sources/Search/Extra/SecuredApiKeyRestrictionExtension.swift index db687864d0..375910dc19 100644 --- a/clients/algoliasearch-client-swift/Sources/Search/Extra/SecuredApiKeyRestrictionExtension.swift +++ b/clients/algoliasearch-client-swift/Sources/Search/Extra/SecuredApiKeyRestrictionExtension.swift @@ -36,6 +36,7 @@ public extension SecuredApiKeyRestrictions { } return (APIHelper.mapValuesToQueryItems(queryDictionary) ?? []) + .sorted { $0.name < $1.name } .map { "\($0.name)=\($0.value ?? "null")" } .joined(separator: "&") } diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java index 15672ee230..984b27e82e 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java @@ -123,6 +123,8 @@ public void processOpts() { supportingFiles.add(new SupportingFile("netcore_project.mustache", "Algolia.Search.csproj")); supportingFiles.add(new SupportingFile("Configuration.mustache", "Clients", packageName + "Configuration.cs")); supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE")); + + reservedWords.removeIf(word -> word.equals("Configuration")); } /** Escape <> in generic with {} */ diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 029bc1d48d..becdb89dd5 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -57,6 +57,8 @@ public void processOpts() { additionalProperties.put("isSearchClient", client.equals("search")); supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE")); + reservedWords.removeIf(word -> word.equals("configuration")); + try { additionalProperties.put("packageVersion", Helpers.getClientConfigField("java", "packageVersion")); } catch (GeneratorException e) { diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index 648e0bffbc..c357ac098c 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -78,6 +78,7 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "promote", "promoteobjectid", "promoteobjectids", + "querysuggestionsconfiguration", "querytype", "rankinginfo", "redirect", @@ -135,21 +136,6 @@ public static String prefixReservedModelName(String name, String client) { return name; } - public static String removeReservedModelNamePrefix(String name, String client) { - if (name == null || name.isEmpty()) { - return name; - } - - var camelizedName = camelize(name, LOWERCASE_FIRST_LETTER); - var clientName = camelize(INSTANCE.getClientName(client), LOWERCASE_FIRST_LETTER); - var trimmedName = camelize(camelizedName.replaceFirst(clientName, ""), LOWERCASE_FIRST_LETTER); - if (isReservedModelName(trimmedName)) { - return trimmedName; - } - - return name; - } - private String CLIENT; @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/CTSManagerFactory.java b/generators/src/main/java/com/algolia/codegen/cts/manager/CTSManagerFactory.java index f54febfbd2..5e4a397317 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/CTSManagerFactory.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/CTSManagerFactory.java @@ -12,7 +12,7 @@ public static CTSManager getManager(String language, String client) { case "java" -> new JavaCTSManager(client); case "php" -> new PhpCTSManager(); case "kotlin" -> new KotlinCTSManager(client); - case "go" -> new GoCTSManager(); + case "go" -> new GoCTSManager(client); case "dart" -> new DartCTSManager(client); case "ruby" -> new RubyCTSManager(client); case "scala" -> new ScalaCTSManager(client); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java index 3962f728e5..8eb9a2a5ae 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java @@ -1,13 +1,21 @@ package com.algolia.codegen.cts.manager; import com.algolia.codegen.exceptions.GeneratorException; +import com.algolia.codegen.utils.*; import java.util.*; public class GoCTSManager implements CTSManager { + private final String client; + + public GoCTSManager(String client) { + this.client = client; + } + @Override public void addDataToBundle(Map bundle) throws GeneratorException { Object clientPrefix = bundle.get("clientPrefix"); + bundle.put("clientName", Helpers.toPascalCase(this.client)); if (clientPrefix.equals("query-suggestions")) { bundle.put("clientPrefix", "suggestions"); diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java index 7a7a05477b..bfe13afc5e 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java @@ -195,8 +195,6 @@ private String getFinalParamName(String paramName) { return paramName.startsWith("_") ? paramName.substring(1) : paramName; case "go": return paramName.equals("type") ? "type_" : paramName; - case "swift": - return AlgoliaSwiftGenerator.removeReservedModelNamePrefix(paramName, client); } return paramName; @@ -296,8 +294,6 @@ private void handleModel( CodegenModel model = (CodegenModel) spec; IJsonSchemaValidationProperties match = findMatchingOneOf(param, model); - paramName = getTransformedParamName(paramName); - testOutput.putAll(traverseParams(paramName, param, match, parent, suffix, isParentFreeFormObject)); Map oneOfModel = new HashMap<>(); diff --git a/scripts/cts/runCts.ts b/scripts/cts/runCts.ts index 0c0119fe32..107fdd69cc 100644 --- a/scripts/cts/runCts.ts +++ b/scripts/cts/runCts.ts @@ -60,7 +60,7 @@ async function runCtsOne(language: string): Promise { await run('sbt test', { cwd, language }); break; case 'swift': - await run('rm -rf .build && swift test -Xswiftc -suppress-warnings -q --parallel', { + await run('swift test -Xswiftc -suppress-warnings -q --parallel', { cwd, language, }); diff --git a/specs/query-suggestions/common/parameters.yml b/specs/query-suggestions/common/parameters.yml index 0632fa6b3c..2bb3b6854b 100644 --- a/specs/query-suggestions/common/parameters.yml +++ b/specs/query-suggestions/common/parameters.yml @@ -4,4 +4,4 @@ IndexName: required: true description: Query Suggestions index name. schema: - $ref: './schemas/QuerySuggestionsIndexName.yml' + $ref: './schemas/IndexName.yml' diff --git a/specs/query-suggestions/common/responses/QuerySuggestionsConfigurationResponse.yml b/specs/query-suggestions/common/responses/ConfigurationResponse.yml similarity index 75% rename from specs/query-suggestions/common/responses/QuerySuggestionsConfigurationResponse.yml rename to specs/query-suggestions/common/responses/ConfigurationResponse.yml index ea37a9b918..0609a3b151 100644 --- a/specs/query-suggestions/common/responses/QuerySuggestionsConfigurationResponse.yml +++ b/specs/query-suggestions/common/responses/ConfigurationResponse.yml @@ -1,9 +1,9 @@ -QuerySuggestionsConfigurationResponse: +ConfigurationResponse: type: object description: API response for retrieving Query Suggestions configurations. allOf: - $ref: '#/AppID' - - $ref: '../schemas/QuerySuggestionsConfiguration.yml#/QuerySuggestionsConfigurationWithIndex' + - $ref: '../schemas/Configuration.yml#/ConfigurationWithIndex' required: - appID - allowSpecialCharacters diff --git a/specs/query-suggestions/common/schemas/QuerySuggestionsConfiguration.yml b/specs/query-suggestions/common/schemas/Configuration.yml similarity index 96% rename from specs/query-suggestions/common/schemas/QuerySuggestionsConfiguration.yml rename to specs/query-suggestions/common/schemas/Configuration.yml index b8b335af11..669feccd25 100644 --- a/specs/query-suggestions/common/schemas/QuerySuggestionsConfiguration.yml +++ b/specs/query-suggestions/common/schemas/Configuration.yml @@ -1,4 +1,4 @@ -QuerySuggestionsConfigurationWithIndex: +ConfigurationWithIndex: type: object description: Query Suggestions configuration. required: @@ -8,10 +8,10 @@ QuerySuggestionsConfigurationWithIndex: - type: object properties: indexName: - $ref: './QuerySuggestionsIndexName.yml' - - $ref: '#/QuerySuggestionsConfiguration' + $ref: './IndexName.yml' + - $ref: '#/Configuration' -QuerySuggestionsConfiguration: +Configuration: type: object description: Query Suggestions configuration. required: diff --git a/specs/query-suggestions/common/schemas/QuerySuggestionsIndexName.yml b/specs/query-suggestions/common/schemas/IndexName.yml similarity index 100% rename from specs/query-suggestions/common/schemas/QuerySuggestionsIndexName.yml rename to specs/query-suggestions/common/schemas/IndexName.yml diff --git a/specs/query-suggestions/paths/getConfigurationStatus.yml b/specs/query-suggestions/paths/getConfigurationStatus.yml index 6508034777..ce89a40c1e 100644 --- a/specs/query-suggestions/paths/getConfigurationStatus.yml +++ b/specs/query-suggestions/paths/getConfigurationStatus.yml @@ -18,7 +18,7 @@ get: additionalProperties: false properties: indexName: - $ref: '../common/schemas/QuerySuggestionsIndexName.yml' + $ref: '../common/schemas/IndexName.yml' isRunning: type: boolean description: Whether the creation or update of the Query Suggestions index is in progress. diff --git a/specs/query-suggestions/paths/qsConfig.yml b/specs/query-suggestions/paths/qsConfig.yml index 69ec96c431..b6df6eaf06 100644 --- a/specs/query-suggestions/paths/qsConfig.yml +++ b/specs/query-suggestions/paths/qsConfig.yml @@ -14,7 +14,7 @@ get: content: application/json: schema: - $ref: '../common/responses/QuerySuggestionsConfigurationResponse.yml#/QuerySuggestionsConfigurationResponse' + $ref: '../common/responses/ConfigurationResponse.yml#/ConfigurationResponse' '400': $ref: '../common/responses/BadRequest.yml' '401': @@ -37,7 +37,7 @@ put: content: application/json: schema: - $ref: '../common/schemas/QuerySuggestionsConfiguration.yml#/QuerySuggestionsConfiguration' + $ref: '../common/schemas/Configuration.yml#/Configuration' responses: '200': description: OK diff --git a/specs/query-suggestions/paths/qsConfigs.yml b/specs/query-suggestions/paths/qsConfigs.yml index f5bbe567e8..cee0ecb089 100644 --- a/specs/query-suggestions/paths/qsConfigs.yml +++ b/specs/query-suggestions/paths/qsConfigs.yml @@ -14,7 +14,7 @@ get: schema: type: array items: - $ref: '../common/responses/QuerySuggestionsConfigurationResponse.yml#/QuerySuggestionsConfigurationResponse' + $ref: '../common/responses/ConfigurationResponse.yml#/ConfigurationResponse' '401': $ref: '../common/responses/Unauthorized.yml' @@ -34,7 +34,7 @@ post: content: application/json: schema: - $ref: '../common/schemas/QuerySuggestionsConfiguration.yml#/QuerySuggestionsConfigurationWithIndex' + $ref: '../common/schemas/Configuration.yml#/ConfigurationWithIndex' responses: '200': description: OK diff --git a/templates/go/client.mustache b/templates/go/client.mustache index 816b4b3b0e..d4c6fd949a 100644 --- a/templates/go/client.mustache +++ b/templates/go/client.mustache @@ -29,13 +29,13 @@ import ( // In most cases there should be only one, shared, APIClient. type APIClient struct { appID string - cfg *Configuration + cfg *{{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration transport *transport.Transport } // NewClient creates a new API client with {{#hasRegionalHost}}appID, apiKey and region.{{/hasRegionalHost}}{{^hasRegionalHost}}appID and apiKey.{{/hasRegionalHost}} func NewClient(appID, apiKey string{{#hasRegionalHost}}, region Region{{/hasRegionalHost}}) (*APIClient, error) { -return NewClientWithConfig(Configuration{ +return NewClientWithConfig({{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration{ Configuration: transport.Configuration{ AppID: appID, ApiKey: apiKey, @@ -48,7 +48,7 @@ return NewClientWithConfig(Configuration{ } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) (*APIClient, error) { +func NewClientWithConfig(cfg {{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration) (*APIClient, error) { var hosts []transport.StatefulHost if cfg.AppID == "" { @@ -175,7 +175,7 @@ func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*ht // Allow modification of underlying config for alternate implementations and testing // Caution: modifying the configuration while live can cause data races and potentially unwanted behavior -func (c *APIClient) GetConfiguration() *Configuration { +func (c *APIClient) GetConfiguration() *{{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration { return c.cfg } diff --git a/templates/go/configuration.mustache b/templates/go/configuration.mustache index 40acb4a052..755512ba70 100644 --- a/templates/go/configuration.mustache +++ b/templates/go/configuration.mustache @@ -17,8 +17,8 @@ const ( ) {{/hasRegionalHost}} -// Configuration stores the configuration of the API client -type Configuration struct { +// {{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration stores the configuration of the API client +type {{#lambda.titlecase}}{{#lambda.camelcase}}{{client}}{{/lambda.camelcase}}{{/lambda.titlecase}}Configuration struct { transport.Configuration {{#hasRegionalHost}}Region Region{{/hasRegionalHost}} diff --git a/templates/go/tests/client/createClient.mustache b/templates/go/tests/client/createClient.mustache index 355d427fac..9239cc13d1 100644 --- a/templates/go/tests/client/createClient.mustache +++ b/templates/go/tests/client/createClient.mustache @@ -1,4 +1,4 @@ -cfg = {{clientPrefix}}.Configuration{ +cfg = {{clientPrefix}}.{{clientName}}Configuration{ Configuration: transport.Configuration{ AppID: "{{parametersWithDataTypeMap.appId.value}}", ApiKey: "{{parametersWithDataTypeMap.apiKey.value}}", diff --git a/templates/go/tests/client/suite.mustache b/templates/go/tests/client/suite.mustache index 1c771b8285..ac6153428d 100644 --- a/templates/go/tests/client/suite.mustache +++ b/templates/go/tests/client/suite.mustache @@ -20,7 +20,7 @@ import ( func create{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t *testing.T) (*{{clientPrefix}}.APIClient, *tests.EchoRequester) { echo := &tests.EchoRequester{} - cfg := {{clientPrefix}}.Configuration{ + cfg := {{clientPrefix}}.{{clientName}}Configuration{ Configuration: transport.Configuration{ AppID: "appID", ApiKey: "apiKey", @@ -45,7 +45,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{testType}}{{/lambda.titlecase}}{ {{^autoCreateClient}} echo := &tests.EchoRequester{} var client *{{clientPrefix}}.APIClient - var cfg {{clientPrefix}}.Configuration + var cfg {{clientPrefix}}.{{clientName}}Configuration _ = client {{/autoCreateClient}} _ = echo diff --git a/templates/go/tests/requests/requests.mustache b/templates/go/tests/requests/requests.mustache index a3d91b8100..c21ad3ea7b 100644 --- a/templates/go/tests/requests/requests.mustache +++ b/templates/go/tests/requests/requests.mustache @@ -24,7 +24,7 @@ func create{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}Client(t *t t.Helper() echo := &tests.EchoRequester{} - cfg := {{clientPrefix}}.Configuration{ + cfg := {{clientPrefix}}.{{clientName}}Configuration{ Configuration: transport.Configuration{ AppID: "appID", ApiKey: "apiKey", diff --git a/templates/swift/api.mustache b/templates/swift/api.mustache index 3326844b7c..f957e8cf72 100644 --- a/templates/swift/api.mustache +++ b/templates/swift/api.mustache @@ -61,7 +61,7 @@ import Foundation /** {{#allParams}} - - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{{description}}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}} - returns: {{{returnType}}}{{#returnType}}{{#isResponseOptional}}?{{/isResponseOptional}}{{/returnType}}{{^returnType}}Void{{/returnType}} */ @@ -89,9 +89,9 @@ import Foundation - {{.}} {{/x-acl}} {{/vendorExtensions}}{{#allParams}} - - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{{description}}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}} - - returns: RequestBuilder<{{{returnType}}}{{#returnType}}{{#isResponseOptional}}?{{/isResponseOptional}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{description}} + - returns: RequestBuilder<{{{returnType}}}{{#returnType}}{{#isResponseOptional}}?{{/isResponseOptional}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{{description}}} */ {{#isDeprecated}} @available(*, deprecated, message: "This operation is deprecated.") diff --git a/templates/swift/tests/client/method.mustache b/templates/swift/tests/client/method.mustache index 7f96443d52..7d55306cf2 100644 --- a/templates/swift/tests/client/method.mustache +++ b/templates/swift/tests/client/method.mustache @@ -1,4 +1,4 @@ -let response = try {{#isAsync}}await {{/isAsync}}client{{#path}}.{{.}}{{#isAsync}}WithHTTPInfo{{/isAsync}}{{/path}}( +let response = try {{#isAsync}}await {{/isAsync}}client{{#path}}.{{.}}{{^isHelper}}WithHTTPInfo{{/isHelper}}{{/path}}( {{#parametersWithDataType}}{{> tests/generateParams }}{{^-last}},{{/-last}} {{/parametersWithDataType}}{{#requestOptions.parametersWithDataType}}{{#-first}}, requestOptions: RequestOptions({{/-first}} {{> tests/generateParams }}{{^-last}},{{/-last}} @@ -11,7 +11,4 @@ let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: {{^useEchoRequester}} let responseBodyJSON = try XCTUnwrap(responseBodyData.jsonString) {{/useEchoRequester}} -{{/isHelper}} -{{#isHelper}} -let responseBodyJSON = response {{/isHelper}} \ No newline at end of file diff --git a/templates/swift/tests/client/suite.mustache b/templates/swift/tests/client/suite.mustache index 21670ae792..24bd6fc144 100644 --- a/templates/swift/tests/client/suite.mustache +++ b/templates/swift/tests/client/suite.mustache @@ -12,10 +12,9 @@ final class {{client}}ClientTests: XCTestCase { let API_KEY = "my_api_key" {{#blocksClient}} {{#tests}} - {{^isHelper}} {{! Helper tests are not supported yet}} /** - {{testName}} + {{{testName}}} */ func test{{#lambda.titlecase}}{{testType}}{{/lambda.titlecase}}Test{{testIndex}}() async throws { {{#autoCreateClient}} @@ -58,20 +57,25 @@ final class {{client}}ClientTests: XCTestCase { XCTAssertEqual("{{{match}}}", echoResponse.host); {{/testHost}} {{#testResponse}} - {{#matchIsObject}} - let comparableData = "{{#lambda.escapeQuotes}}{{{match.parameters}}}{{/lambda.escapeQuotes}}".data(using: .utf8) - {{/matchIsObject}} - {{^matchIsObject}} - let comparableData = "{{#lambda.escapeQuotes}}{{{match}}}{{/lambda.escapeQuotes}}".data(using: .utf8) - {{/matchIsObject}} - let comparableJSON = try XCTUnwrap(comparableData?.jsonString) - XCTAssertEqual(comparableJSON, responseBodyJSON); + {{#isHelper}} + {{#matchIsObject}} + let comparableData = try XCTUnwrap("{{#lambda.escapeQuotes}}{{{match.parameters}}}{{/lambda.escapeQuotes}}".data(using: .utf8)) + try XCTLenientAssertEqual(received: CodableHelper.jsonEncoder.encode(response), expected: comparableData) + {{/matchIsObject}} + {{^matchIsObject}} + XCTAssertEqual("{{#lambda.escapeQuotes}}{{{match}}}{{/lambda.escapeQuotes}}", response) + {{/matchIsObject}} + {{/isHelper}} + {{^isHelper}} + let comparableData = "{{#lambda.escapeQuotes}}{{#matchIsObject}}{{{match.parameters}}}{{/matchIsObject}}{{^matchIsObject}}{{{match}}}{{/matchIsObject}}{{/lambda.escapeQuotes}}".data(using: .utf8) + let comparableJSON = try XCTUnwrap(comparableData?.jsonString) + XCTAssertEqual(comparableJSON, responseBodyJSON); + {{/isHelper}} {{/testResponse}} {{/match}} {{/isError}} {{/steps}} } - {{/isHelper}} {{/tests}} {{/blocksClient}} } \ No newline at end of file diff --git a/templates/swift/tests/requests/requests.mustache b/templates/swift/tests/requests/requests.mustache index 37a750dd30..4123615914 100644 --- a/templates/swift/tests/requests/requests.mustache +++ b/templates/swift/tests/requests/requests.mustache @@ -54,7 +54,7 @@ final class {{client}}RequestsTests: XCTestCase { {{#blocksRequests}} {{#tests}} /** - {{testName}} + {{{testName}}} */ func test{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}Test{{testIndex}}() async throws { let configuration = try {{client}}Configuration(appID: {{client}}RequestsTests.APPLICATION_ID, apiKey: {{client}}RequestsTests.API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) diff --git a/tests/CTS/requests/query-suggestions/updateConfig.json b/tests/CTS/requests/query-suggestions/updateConfig.json index db83168d7e..7a13aee666 100644 --- a/tests/CTS/requests/query-suggestions/updateConfig.json +++ b/tests/CTS/requests/query-suggestions/updateConfig.json @@ -2,7 +2,7 @@ { "parameters": { "indexName": "theIndexName", - "querySuggestionsConfiguration": { + "configuration": { "sourceIndices": [ { "indexName": "testIndex", diff --git a/tests/output/csharp/src/ClientExtensionsTests.cs b/tests/output/csharp/src/ClientExtensionsTests.cs index c175d106cf..5363d4b3b0 100644 --- a/tests/output/csharp/src/ClientExtensionsTests.cs +++ b/tests/output/csharp/src/ClientExtensionsTests.cs @@ -568,4 +568,4 @@ public async Task ShouldSearchForFacets() Assert.Single(hits); } -} \ No newline at end of file +} diff --git a/tests/output/swift/Tests/Utils/Utils.swift b/tests/output/swift/Tests/Utils/Utils.swift index a1ce272556..f7051568d1 100644 --- a/tests/output/swift/Tests/Utils/Utils.swift +++ b/tests/output/swift/Tests/Utils/Utils.swift @@ -36,7 +36,12 @@ public func XCTLenientAssertEqual(received: Data, expected: Data) { expected: JSONSerialization.jsonObject(with: expected, options: [.fragmentsAllowed]), received: JSONSerialization.jsonObject(with: received, options: [.fragmentsAllowed]) ) else { - XCTFail("Unable to unionize received and expected objects") + if let receivedString = String(data: received, encoding: .utf8), + let expectedString = String(data: expected, encoding: .utf8) { + XCTAssertEqual(receivedString, expectedString) + } else { + XCTFail("Unable to unionize received and expected objects") + } return } diff --git a/tests/output/swift/Tests/handwritten/E2ESearch.swift b/tests/output/swift/Tests/handwritten/E2ESearch.swift deleted file mode 100644 index f9d3f09cd5..0000000000 --- a/tests/output/swift/Tests/handwritten/E2ESearch.swift +++ /dev/null @@ -1,95 +0,0 @@ -// -// E2ESearch.swift -// -// -// Created by Algolia on 23/02/2024. -// - -import DotEnv -import Foundation -import XCTest -@testable import Core -@testable import Search - -struct Company: Codable { - let objectID: String - let name: String - let value: Int - let timestamp: Int64 -} - -class E2ESearchTests: XCTestCase { - static var APPLICATION_ID = "my_application_id" - static var API_KEY = "my_api_key" - static var e2eClient: SearchClient? - - override class func setUp() { - if !(Bool(ProcessInfo.processInfo.environment["CI"] ?? "false") ?? false) { - do { - let currentFileURL = try XCTUnwrap(URL(string: #file)) - - let packageDirectoryURL = currentFileURL - .deletingLastPathComponent() - .deletingLastPathComponent() - .deletingLastPathComponent() - .deletingLastPathComponent() - .deletingLastPathComponent() - - let dotEnvURL = packageDirectoryURL - .appendingPathComponent(".env") - dump(dotEnvURL.absoluteString) - try DotEnv.load(path: dotEnvURL.absoluteString, encoding: .utf8, overwrite: true) - } catch { - XCTFail("Unable to load .env file") - } - } - - do { - self.APPLICATION_ID = try XCTUnwrap(ProcessInfo.processInfo.environment["ALGOLIA_APPLICATION_ID"]) - } catch { - XCTFail("Please provide an `ALGOLIA_APPLICATION_ID` env var for e2e tests") - } - - do { - self.API_KEY = try XCTUnwrap(ProcessInfo.processInfo.environment["ALGOLIA_ADMIN_KEY"]) - } catch { - XCTFail("Please provide an `ALGOLIA_ADMIN_KEY` env var for e2e tests") - } - - self.e2eClient = try? SearchClient(appID: self.APPLICATION_ID, apiKey: self.API_KEY) - } - - func testReplaceAllObjectsSuccess() async throws { - guard let e2eClient = E2ESearchTests.e2eClient else { - XCTFail("Couldn't initialize the E2E client") - return - } - - let batchSize = 1000 - let indexName = "cts_e2e_swift_replace_all_objects" - let now = Int64(Date().timeIntervalSince1970) - var records: [Company] = [] - - for i in 0 ... Int.random(in: 250 ... 3500) { - try records.append( - .init( - objectID: randomString(), - name: randomString(length: (i % 5) + 1), - value: Int.random(in: 1 ... 9_999_999), - timestamp: now - ) - ) - } - - let response = try await e2eClient.replaceAllObjects(with: records, in: indexName) - - let expectedBatches = stride(from: 0, to: records.count, by: batchSize).map { - Array(records[$0 ..< min($0 + batchSize, records.count)]) - } - - XCTAssertEqual(response.batchResponses.count, expectedBatches.count) - for (index, batchResponse) in response.batchResponses.enumerated() { - XCTAssertEqual(batchResponse.objectIDs.count, expectedBatches[index].count) - } - } -} diff --git a/tests/output/swift/Tests/handwritten/SecuredApiKeyHelpers.swift b/tests/output/swift/Tests/handwritten/SecuredApiKeyHelpers.swift index de19136374..2f17b6ebb0 100644 --- a/tests/output/swift/Tests/handwritten/SecuredApiKeyHelpers.swift +++ b/tests/output/swift/Tests/handwritten/SecuredApiKeyHelpers.swift @@ -11,24 +11,6 @@ import XCTest @testable import Search class SecuredApiKeyHelpersTests: XCTestCase { - func testGenerateSecuredApiKeySuccess() async throws { - let client = try SearchClient(appID: "my-app-id", apiKey: "my-api-key") - - let securedApiKey = try client.generateSecuredApiKey( - parentApiKey: "parent-api-key" - ) - - guard let securedApiKey else { - XCTFail("Unable to generate secured API key") - return - } - - XCTAssertEqual( - securedApiKey, - "MGQ3NWNhMDc5ZTIwOTk0NGMzMTg5MjRhNDlhNGNkOWMzODI5ODM2NDUxNzg5ODg4YzBhMDg3YmQxMzAwYmRhNw==" - ) - } - func testGetSecuredApiKeyRemainingValiditySuccess() async throws { let now = Date().timeIntervalSince1970 let waitDuration: TimeInterval = .seconds(3)