From 4c5c1d73c242d3d012d5d76466a6faa922604f72 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Mon, 29 Jan 2024 10:22:13 +0100 Subject: [PATCH 1/7] fix(cts): enable cts on the CI --- scripts/cts/runCts.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/cts/runCts.ts b/scripts/cts/runCts.ts index d312219793..cc8646b457 100644 --- a/scripts/cts/runCts.ts +++ b/scripts/cts/runCts.ts @@ -51,6 +51,9 @@ async function runCtsOne(language: string): Promise { case 'scala': await run('sbt test', { cwd, language }); break; + case 'swift': + await run('swift test --parallel', { cwd, language }); + break; default: spinner.warn(`skipping unknown language '${language}' to run the CTS`); return; From e4fff9232e5b12b86dddb79dd8ca1a90a9b04615 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Fri, 26 Jan 2024 20:27:59 +0100 Subject: [PATCH 2/7] fix(cts): remove gen files and init client --- .../Sources/Core/Helpers/Version.swift | 43 - config/generation.config.mjs | 1 + templates/swift/tests/Package.mustache | 13 + .../swift/tests/client/createClient.mustache | 1 + templates/swift/tests/client/method.mustache | 3 + templates/swift/tests/client/suite.mustache | 68 + templates/swift/tests/paramValue.mustache | 2 +- tests/output/swift/Package.swift | 58 - tests/output/swift/Tests/Utils/Data.swift | 18 + .../swift/Tests/requests/AbtestingTests.swift | 687 ---- .../swift/Tests/requests/AnalyticsTests.swift | 1360 -------- .../swift/Tests/requests/IngestionTests.swift | 1388 -------- .../swift/Tests/requests/InsightsTests.swift | 710 ---- .../Tests/requests/MonitoringTests.swift | 735 ---- .../Tests/requests/PersonalizationTests.swift | 642 ---- .../requests/QuerySuggestionsTests.swift | 709 ---- .../swift/Tests/requests/RecommendTests.swift | 831 ----- .../swift/Tests/requests/SearchTests.swift | 2997 ----------------- 18 files changed, 105 insertions(+), 10161 deletions(-) delete mode 100644 clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift create mode 100644 templates/swift/tests/client/createClient.mustache create mode 100644 templates/swift/tests/client/method.mustache create mode 100644 templates/swift/tests/client/suite.mustache delete mode 100644 tests/output/swift/Package.swift create mode 100644 tests/output/swift/Tests/Utils/Data.swift delete mode 100644 tests/output/swift/Tests/requests/AbtestingTests.swift delete mode 100644 tests/output/swift/Tests/requests/AnalyticsTests.swift delete mode 100644 tests/output/swift/Tests/requests/IngestionTests.swift delete mode 100644 tests/output/swift/Tests/requests/InsightsTests.swift delete mode 100644 tests/output/swift/Tests/requests/MonitoringTests.swift delete mode 100644 tests/output/swift/Tests/requests/PersonalizationTests.swift delete mode 100644 tests/output/swift/Tests/requests/QuerySuggestionsTests.swift delete mode 100644 tests/output/swift/Tests/requests/RecommendTests.swift delete mode 100644 tests/output/swift/Tests/requests/SearchTests.swift diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift deleted file mode 100644 index a8e53744f6..0000000000 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift +++ /dev/null @@ -1,43 +0,0 @@ -// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. - -public struct Version { - public let major: Int - public let minor: Int - public let patch: Int - public let prereleaseIdentifier: String? - - public init(major: Int, minor: Int, patch: Int = 0, prereleaseIdentifier: String? = nil) { - self.major = major - self.minor = minor - self.patch = patch - self.prereleaseIdentifier = prereleaseIdentifier - } - - public init(version: String) { - let components = version.components(separatedBy: ".") - - guard components.count >= 3 else { - fatalError("version is not formatted correctly") - } - - major = Int(components[0]) ?? 0 - minor = Int(components[1]) ?? 0 - patch = Int(components[2]) ?? 0 - prereleaseIdentifier = components.count == 4 ? components[3] : nil - } -} - -extension Version: CustomStringConvertible { - public var description: String { - let main = [major, minor, patch].map(String.init).joined(separator: ".") - if let prereleaseIdentifier = prereleaseIdentifier { - return main + "-\(prereleaseIdentifier)" - } else { - return main - } - } -} - -public extension Version { - static let current: Version = .init(version: "9.0.0-alpha.2") -} diff --git a/config/generation.config.mjs b/config/generation.config.mjs index 459dfd8c03..3be6bbaec4 100644 --- a/config/generation.config.mjs +++ b/config/generation.config.mjs @@ -149,4 +149,5 @@ export const patterns = [ 'clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift', 'tests/output/swift/Package.swift', + '!tests/output/swift/Utils/**', ]; diff --git a/templates/swift/tests/Package.mustache b/templates/swift/tests/Package.mustache index 1604dafaaa..bf8c744be4 100644 --- a/templates/swift/tests/Package.mustache +++ b/templates/swift/tests/Package.mustache @@ -11,6 +11,19 @@ let package = Package( .package(path: "../../../clients/algoliasearch-client-swift"), ], targets: [ + .testTarget( + name: "client", + dependencies: [ + .product(name: "AnyCodable", package: "AnyCodable"), + .product(name: "SwiftyJSON", package: "SwiftyJSON"),{{#packageList}} + .product( + name: "{{.}}", + package: "algoliasearch-client-swift" + ),{{/packageList}} + ], + path: "Tests", + sources: ["client", "Utils"] + ), .testTarget( name: "requests", dependencies: [ diff --git a/templates/swift/tests/client/createClient.mustache b/templates/swift/tests/client/createClient.mustache new file mode 100644 index 0000000000..7a874efeaa --- /dev/null +++ b/templates/swift/tests/client/createClient.mustache @@ -0,0 +1 @@ +{{^autoCreateClient}}let client = {{/autoCreateClient}}try {{client}}(applicationID: "{{parametersWithDataTypeMap.appId.value}}", apiKey: "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}, region: {{#parametersWithDataTypeMap.region}}Region(rawValue: "{{parametersWithDataTypeMap.region.value}}"){{/parametersWithDataTypeMap.region}}{{^parametersWithDataTypeMap.region}}nil{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}) \ No newline at end of file diff --git a/templates/swift/tests/client/method.mustache b/templates/swift/tests/client/method.mustache new file mode 100644 index 0000000000..04adeae62f --- /dev/null +++ b/templates/swift/tests/client/method.mustache @@ -0,0 +1,3 @@ +let response = try await client{{#path}}.{{.}}WithHTTPInfo{{/path}}({{#parametersWithDataType}}{{> tests/generateParams }}{{^-last}}, {{/-last}}{{/parametersWithDataType}}) +let responseBodyData = try XCTUnwrap(response.bodyData) +let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) \ No newline at end of file diff --git a/templates/swift/tests/client/suite.mustache b/templates/swift/tests/client/suite.mustache new file mode 100644 index 0000000000..0bc355ce81 --- /dev/null +++ b/templates/swift/tests/client/suite.mustache @@ -0,0 +1,68 @@ +import XCTest +import SwiftyJSON +#if canImport(AnyCodable) +import AnyCodable +#endif + +@testable import Core +@testable import {{import}} + +final class {{client}}ClientTests: XCTestCase { + + let APPLICATION_ID = "" + let API_KEY = "" +{{#blocksClient}} + {{#tests}} + + /** + {{testName}} + */ + func test{{#lambda.titlecase}}{{testType}}{{/lambda.titlecase}}Test{{testIndex}}() async throws { + {{#autoCreateClient}} + let statusCode: HTTPStatusСode = 200 + let configuration: {{import}}.Configuration = try {{import}}.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) + let transporter: Transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder(statusCode: statusCode)) + let client: {{client}} = {{client}}(configuration: configuration, transporter: transporter) + {{/autoCreateClient}} + + {{#steps}} + {{#isError}} + do { + {{#dynamicTemplate}}{{/dynamicTemplate}} + + _ = client + XCTFail("Expected an error to be thrown") + } catch { + XCTAssertEqual(error.localizedDescription, "{{{expectedError}}}") + } + {{/isError}} + {{^isError}} + {{#dynamicTemplate}}{{/dynamicTemplate}} + {{#match}} + {{#testUserAgent}} + + let pattern = "{{#lambda.escapeSlash}}{{{match}}}{{/lambda.escapeSlash}}" + let rule = StringRule(pattern: pattern) + let userAgent = try XCTUnwrap(echoResponse.headers?["user-agent"]) + guard let userAgent = userAgent else { + XCTFail("Expected user-agent header") + return + } + + XCTAssertNoThrow(try Validator.validate(userAgent, against: rule), "Expected " + userAgent + " to match the following regex: " + pattern); + {{/testUserAgent}} + + {{#testTimeouts}} + + XCTAssertEqual(TimeInterval({{{match.parametersWithDataTypeMap.responseTimeout.value}}} / 1000), echoResponse.timeout); + {{/testTimeouts}} + {{#testHost}} + XCTAssertEqual("{{{match}}}", echoResponse.url); + {{/testHost}} + {{/match}} + {{/isError}} + {{/steps}} + } + {{/tests}} + {{/blocksClient}} +} \ No newline at end of file diff --git a/templates/swift/tests/paramValue.mustache b/templates/swift/tests/paramValue.mustache index 0ecac6bd3e..689b7a1d0a 100644 --- a/templates/swift/tests/paramValue.mustache +++ b/templates/swift/tests/paramValue.mustache @@ -1 +1 @@ -{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}} \ No newline at end of file +{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}""{{/isNull}} \ No newline at end of file diff --git a/tests/output/swift/Package.swift b/tests/output/swift/Package.swift deleted file mode 100644 index 7005e006e7..0000000000 --- a/tests/output/swift/Package.swift +++ /dev/null @@ -1,58 +0,0 @@ -// swift-tools-version: 5.9 -// - -import PackageDescription - -let package = Package( - name: "AlgoliaSearchClientTests", - dependencies: [ - .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.1")), - .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"), - .package(path: "../../../clients/algoliasearch-client-swift"), - ], - targets: [ - .testTarget( - name: "requests", - dependencies: [ - .product(name: "AnyCodable", package: "AnyCodable"), - .product(name: "SwiftyJSON", package: "SwiftyJSON"), - .product( - name: "Abtesting", - package: "algoliasearch-client-swift" - ), - .product( - name: "Analytics", - package: "algoliasearch-client-swift" - ), - .product( - name: "Ingestion", - package: "algoliasearch-client-swift" - ), - .product( - name: "Insights", - package: "algoliasearch-client-swift" - ), - .product( - name: "Monitoring", - package: "algoliasearch-client-swift" - ), - .product( - name: "Personalization", - package: "algoliasearch-client-swift" - ), - .product( - name: "QuerySuggestions", - package: "algoliasearch-client-swift" - ), - .product( - name: "Recommend", - package: "algoliasearch-client-swift" - ), - .product( - name: "Search", - package: "algoliasearch-client-swift" - ), - ] - ) - ] -) \ No newline at end of file diff --git a/tests/output/swift/Tests/Utils/Data.swift b/tests/output/swift/Tests/Utils/Data.swift new file mode 100644 index 0000000000..88b93a2091 --- /dev/null +++ b/tests/output/swift/Tests/Utils/Data.swift @@ -0,0 +1,18 @@ +// +// Data.swift +// +// +// Created by Algolia on 26/01/2024. +// + +import Foundation + +extension Data { + var jsonString: String? { + return (try? JSONSerialization.jsonObject(with: self, options: .allowFragments)) + .flatMap { + try? JSONSerialization.data(withJSONObject: $0, options: [.prettyPrinted, .fragmentsAllowed, .sortedKeys]) + } + .flatMap { String(data: $0, encoding: .utf8) } + } +} diff --git a/tests/output/swift/Tests/requests/AbtestingTests.swift b/tests/output/swift/Tests/requests/AbtestingTests.swift deleted file mode 100644 index 9fc7cb5956..0000000000 --- a/tests/output/swift/Tests/requests/AbtestingTests.swift +++ /dev/null @@ -1,687 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Abtesting -@testable import Core - -final class AbtestingClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - addABTests with minimal parameters - */ - func testAddABTestsTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.addABTestsWithHTTPInfo(addABTestsRequest: AddABTestsRequest(name: "myABTest", variants: [AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_1", trafficPercentage: 30)), AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_2", trafficPercentage: 50))], endAt: "2022-12-31T00:00:00.000Z"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/2/abtests") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteABTest - */ - func testDeleteABTestTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteABTestWithHTTPInfo(id: 42, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/abtests/42") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getABTest - */ - func testGetABTestTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.getABTestWithHTTPInfo(id: 42, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/abtests/42") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listABTests with minimal parameters - */ - func testListABTestsTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.listABTestsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/abtests") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listABTests with parameters - */ - func testListABTestsTest1() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.listABTestsWithHTTPInfo(offset: 42, limit: 21, indexPrefix: "foo", indexSuffix: "bar", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/abtests") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"offset\":\"42\",\"limit\":\"21\",\"indexPrefix\":\"foo\",\"indexSuffix\":\"bar\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - stopABTest - */ - func testStopABTestTest0() async throws { - let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AbtestingClient(configuration: configuration, transporter: transporter) - - let response = try await client.stopABTestWithHTTPInfo(id: 42, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/2/abtests/42/stop") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/AnalyticsTests.swift b/tests/output/swift/Tests/requests/AnalyticsTests.swift deleted file mode 100644 index b7c1546646..0000000000 --- a/tests/output/swift/Tests/requests/AnalyticsTests.swift +++ /dev/null @@ -1,1360 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Analytics -@testable import Core - -final class AnalyticsClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getAverageClickPosition with minimal parameters - */ - func testGetAverageClickPositionTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getAverageClickPositionWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/averageClickPosition") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getAverageClickPosition with all parameters - */ - func testGetAverageClickPositionTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getAverageClickPositionWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/averageClickPosition") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getClickPositions with minimal parameters - */ - func testGetClickPositionsTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClickPositionsWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/positions") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getClickPositions with all parameters - */ - func testGetClickPositionsTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClickPositionsWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/positions") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getClickThroughRate with minimal parameters - */ - func testGetClickThroughRateTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClickThroughRateWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/clickThroughRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getClickThroughRate with all parameters - */ - func testGetClickThroughRateTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClickThroughRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/clicks/clickThroughRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getConversationRate with minimal parameters - */ - func testGetConversationRateTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getConversationRateWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/conversions/conversionRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getConversationRate with all parameters - */ - func testGetConversationRateTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getConversationRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/conversions/conversionRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getNoClickRate with minimal parameters - */ - func testGetNoClickRateTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getNoClickRateWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noClickRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getNoClickRate with all parameters - */ - func testGetNoClickRateTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getNoClickRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noClickRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getNoResultsRate with minimal parameters - */ - func testGetNoResultsRateTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getNoResultsRateWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noResultRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getNoResultsRate with all parameters - */ - func testGetNoResultsRateTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getNoResultsRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noResultRate") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesCount with minimal parameters - */ - func testGetSearchesCountTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesCountWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/count") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesCount with all parameters - */ - func testGetSearchesCountTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesCountWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/count") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesNoClicks with minimal parameters - */ - func testGetSearchesNoClicksTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesNoClicksWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noClicks") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesNoClicks with all parameters - */ - func testGetSearchesNoClicksTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesNoClicksWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noClicks") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesNoResults with minimal parameters - */ - func testGetSearchesNoResultsTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesNoResultsWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noResults") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getSearchesNoResults with all parameters - */ - func testGetSearchesNoResultsTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSearchesNoResultsWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches/noResults") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getStatus with minimal parameters - */ - func testGetStatusTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getStatusWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/status") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopCountries with minimal parameters - */ - func testGetTopCountriesTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopCountriesWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/countries") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopCountries with all parameters - */ - func testGetTopCountriesTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopCountriesWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/countries") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterAttributes with minimal parameters - */ - func testGetTopFilterAttributesTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterAttributesWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterAttributes with all parameters - */ - func testGetTopFilterAttributesTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterAttributesWithHTTPInfo(index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterForAttribute with minimal parameters - */ - func testGetTopFilterForAttributeTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute", index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterForAttribute with minimal parameters and multiple attributes - */ - func testGetTopFilterForAttributeTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute1,myAttribute2", index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute1%2CmyAttribute2") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterForAttribute with all parameters - */ - func testGetTopFilterForAttributeTest2() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute", index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFilterForAttribute with all parameters and multiple attributes - */ - func testGetTopFilterForAttributeTest3() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute1,myAttribute2", index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute1%2CmyAttribute2") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFiltersNoResults with minimal parameters - */ - func testGetTopFiltersNoResultsTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFiltersNoResultsWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/noResults") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopFiltersNoResults with all parameters - */ - func testGetTopFiltersNoResultsTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopFiltersNoResultsWithHTTPInfo(index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/filters/noResults") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopHits with minimal parameters - */ - func testGetTopHitsTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopHitsWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/hits") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopHits with all parameters - */ - func testGetTopHitsTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopHitsWithHTTPInfo(index: "index", search: "mySearch", clickAnalytics: true, startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/hits") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopSearches with minimal parameters - */ - func testGetTopSearchesTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopSearchesWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getTopSearches with all parameters - */ - func testGetTopSearchesTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopSearchesWithHTTPInfo(index: "index", clickAnalytics: true, startDate: "1999-09-19", endDate: "2001-01-01", orderBy: OrderBy.searchCount, direction: Direction.asc, limit: 21, offset: 42, tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/searches") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"orderBy\":\"searchCount\",\"direction\":\"asc\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getUsersCount with minimal parameters - */ - func testGetUsersCountTest0() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getUsersCountWithHTTPInfo(index: "index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/users/count") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - get getUsersCount with all parameters - */ - func testGetUsersCountTest1() async throws { - let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = AnalyticsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getUsersCountWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/2/users/count") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } -} diff --git a/tests/output/swift/Tests/requests/IngestionTests.swift b/tests/output/swift/Tests/requests/IngestionTests.swift deleted file mode 100644 index f254f61f18..0000000000 --- a/tests/output/swift/Tests/requests/IngestionTests.swift +++ /dev/null @@ -1,1388 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Ingestion - -final class IngestionClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - createAuthenticationOAuth - */ - func testCreateAuthenticationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createAuthenticationWithHTTPInfo(authenticationCreate: AuthenticationCreate(type: AuthenticationType.oauth, name: "authName", input: AuthInput.authOAuth(AuthOAuth(url: "http://test.oauth", clientId: "myID", clientSecret: "mySecret"))), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"type\":\"oauth\",\"name\":\"authName\",\"input\":{\"url\":\"http://test.oauth\",\"client_id\":\"myID\",\"client_secret\":\"mySecret\"}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/authentications") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createAuthenticationAlgolia - */ - func testCreateAuthenticationTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createAuthenticationWithHTTPInfo(authenticationCreate: AuthenticationCreate(type: AuthenticationType.algolia, name: "authName", input: AuthInput.authAlgolia(AuthAlgolia(appID: "myappID", apiKey: "randomApiKey"))), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"type\":\"algolia\",\"name\":\"authName\",\"input\":{\"appID\":\"myappID\",\"apiKey\":\"randomApiKey\"}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/authentications") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createDestination - */ - func testCreateDestinationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createDestinationWithHTTPInfo(destinationCreate: DestinationCreate(type: DestinationType.search, name: "destinationName", input: DestinationInput.destinationIndexPrefix(DestinationIndexPrefix(indexPrefix: "prefix_")), authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"type\":\"search\",\"name\":\"destinationName\",\"input\":{\"indexPrefix\":\"prefix_\"},\"authenticationID\":\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/destinations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createSource - */ - func testCreateSourceTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createSourceWithHTTPInfo(sourceCreate: SourceCreate(type: SourceType.commercetools, name: "sourceName", input: SourceInput.sourceCommercetools(SourceCommercetools(storeKeys: ["myStore"], locales: ["de"], url: "http://commercetools.com", projectKey: "keyID")), authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"type\":\"commercetools\",\"name\":\"sourceName\",\"input\":{\"storeKeys\":[\"myStore\"],\"locales\":[\"de\"],\"url\":\"http://commercetools.com\",\"projectKey\":\"keyID\"},\"authenticationID\":\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/sources") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createTaskOnDemand - */ - func testCreateTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.onDemandTriggerInput(OnDemandTriggerInput(type: OnDemandTriggerType.onDemand)), action: ActionType.replace), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"onDemand\"},\"action\":\"replace\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/tasks") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createTaskSchedule - */ - func testCreateTaskTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.scheduleTriggerInput(ScheduleTriggerInput(type: ScheduleTriggerType.schedule, cron: "* * * * *")), action: ActionType.replace), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"schedule\",\"cron\":\"* * * * *\"},\"action\":\"replace\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/tasks") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - createTaskSubscription - */ - func testCreateTaskTest2() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.onDemandTriggerInput(OnDemandTriggerInput(type: OnDemandTriggerType.onDemand)), action: ActionType.replace), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"onDemand\"},\"action\":\"replace\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/tasks") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteAuthentication - */ - func testDeleteAuthenticationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteDestination - */ - func testDeleteDestinationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteSource - */ - func testDeleteSourceTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteTask - */ - func testDeleteTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - disableTask - */ - func testDisableTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.disableTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/disable") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - enableTask - */ - func testEnableTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.enableTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/enable") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getAuthentication - */ - func testGetAuthenticationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getAuthentications - */ - func testGetAuthenticationsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getAuthenticationsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/authentications") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getDestination - */ - func testGetDestinationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getDestinations - */ - func testGetDestinationsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getDestinationsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/destinations") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getDockerSourceStreams - */ - func testGetDockerSourceStreamsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getDockerSourceStreamsWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getEvent - */ - func testGetEventTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getEventWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", eventID: "6c02aeb1-775e-418e-870b-1faccd4b2c0c", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events/6c02aeb1-775e-418e-870b-1faccd4b2c0c") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getEvents - */ - func testGetEventsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getEventsWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getRun - */ - func testGetRunTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRunWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getRuns - */ - func testGetRunsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRunsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/runs") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getSource - */ - func testGetSourceTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getSources - */ - func testGetSourcesTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSourcesWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/sources") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getTask - */ - func testGetTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getTasks - */ - func testGetTasksTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTasksWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/tasks") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - runTask - */ - func testRunTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.runTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/run") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchAuthentications - */ - func testSearchAuthenticationsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchAuthenticationsWithHTTPInfo(authenticationSearch: AuthenticationSearch(authenticationIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"authenticationIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/authentications/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchDestinations - */ - func testSearchDestinationsTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchDestinationsWithHTTPInfo(destinationSearch: DestinationSearch(destinationIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"destinationIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/destinations/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchSources - */ - func testSearchSourcesTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSourcesWithHTTPInfo(sourceSearch: SourceSearch(sourceIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"sourceIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/sources/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchTasks - */ - func testSearchTasksTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchTasksWithHTTPInfo(taskSearch: TaskSearch(taskIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"taskIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/tasks/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - triggerDockerSourceDiscover - */ - func testTriggerDockerSourceDiscoverTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.triggerDockerSourceDiscoverWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateAuthentication - */ - func testUpdateAuthenticationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", authenticationUpdate: AuthenticationUpdate(name: "newName"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"name\":\"newName\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.patch) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateDestination - */ - func testUpdateDestinationTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", destinationUpdate: DestinationUpdate(name: "newName"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"name\":\"newName\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.patch) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateSource - */ - func testUpdateSourceTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", sourceUpdate: SourceUpdate(name: "newName"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"name\":\"newName\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.patch) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateTask - */ - func testUpdateTaskTest0() async throws { - let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = IngestionClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", taskUpdate: TaskUpdate(enabled: false), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"enabled\":false}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") - XCTAssertEqual(echoResponse.method, HTTPMethod.patch) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/InsightsTests.swift b/tests/output/swift/Tests/requests/InsightsTests.swift deleted file mode 100644 index 2e8a9b1cff..0000000000 --- a/tests/output/swift/Tests/requests/InsightsTests.swift +++ /dev/null @@ -1,710 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Insights - -final class InsightsClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteUserToken0 - */ - func testDeleteUserTokenTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteUserTokenWithHTTPInfo(userToken: "test-user-1", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/usertokens/test-user-1") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - pushEvents0 - */ - func testPushEventsTest0() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.clickedObjectIDsAfterSearch(ClickedObjectIDsAfterSearch(eventName: "Product Clicked", eventType: ClickEvent.click, index: "products", objectIDs: ["9780545139700", "9780439784542"], positions: [7, 6], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"events\":[{\"eventType\":\"click\",\"eventName\":\"Product Clicked\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"positions\":[7,6]}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - Many events type - */ - func testPushEventsTest1() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.convertedObjectIDsAfterSearch(ConvertedObjectIDsAfterSearch(eventName: "Product Purchased", eventType: ConversionEvent.conversion, index: "products", objectIDs: ["9780545139700", "9780439784542"], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962))), EventsItems.viewedObjectIDs(ViewedObjectIDs(eventName: "Product Detail Page Viewed", eventType: ViewEvent.view, index: "products", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - ConvertedObjectIDsAfterSearch - */ - func testPushEventsTest2() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.convertedObjectIDsAfterSearch(ConvertedObjectIDsAfterSearch(eventName: "Product Purchased", eventType: ConversionEvent.conversion, index: "products", objectIDs: ["9780545139700", "9780439784542"], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - ViewedObjectIDs - */ - func testPushEventsTest3() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.viewedObjectIDs(ViewedObjectIDs(eventName: "Product Detail Page Viewed", eventType: ViewEvent.view, index: "products", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"events\":[{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - AddedToCartObjectIDs - */ - func testPushEventsTest4() async throws { - let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = InsightsClient(configuration: configuration, transporter: transporter) - - let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.addedToCartObjectIDsAfterSearch(AddedToCartObjectIDsAfterSearch(eventName: "Product Added To Cart", eventType: ConversionEvent.conversion, eventSubtype: AddToCartEvent.addToCart, index: "products", queryID: "43b15df305339e827f0ac0bdc5ebcaa7", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", currency: "USD", objectData: [ObjectDataAfterSearch(price: Price.double(19.99), quantity: 10, discount: Discount.double(2.5)), ObjectDataAfterSearch(price: Price.string("8$"), quantity: 7, discount: Discount.string("30%"))], timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"events\":[{\"eventType\":\"conversion\",\"eventSubtype\":\"addToCart\",\"eventName\":\"Product Added To Cart\",\"index\":\"products\",\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"objectData\":[{\"price\":19.99,\"quantity\":10,\"discount\":2.5},{\"price\":\"8$\",\"quantity\":7,\"discount\":\"30%\"}],\"currency\":\"USD\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/events") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/MonitoringTests.swift b/tests/output/swift/Tests/requests/MonitoringTests.swift deleted file mode 100644 index 063963b5f4..0000000000 --- a/tests/output/swift/Tests/requests/MonitoringTests.swift +++ /dev/null @@ -1,735 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Monitoring - -final class MonitoringClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - getClusterIncidents - */ - func testGetClusterIncidentsTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClusterIncidentsWithHTTPInfo(clusters: "c1-de", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/incidents/c1-de") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getClusterStatus - */ - func testGetClusterStatusTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getClusterStatusWithHTTPInfo(clusters: "c1-de", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/status/c1-de") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getIncidents - */ - func testGetIncidentsTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getIncidentsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/incidents") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getIndexingTime - */ - func testGetIndexingTimeTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getIndexingTimeWithHTTPInfo(clusters: "c1-de", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexing/c1-de") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getInventory - */ - func testGetInventoryTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getInventoryWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/inventory/servers") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getLatency - */ - func testGetLatencyTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getLatencyWithHTTPInfo(clusters: "c1-de", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/latency/c1-de") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getMetrics - */ - func testGetMetricsTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getMetricsWithHTTPInfo(metric: Metric.avgBuildTime, period: Period.minute, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/infrastructure/avg_build_time/period/minute") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getReachability - */ - func testGetReachabilityTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getReachabilityWithHTTPInfo(clusters: "c1-de", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/reachability/c1-de/probes") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getStatus - */ - func testGetStatusTest0() async throws { - let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = MonitoringClient(configuration: configuration, transporter: transporter) - - let response = try await client.getStatusWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/status") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/PersonalizationTests.swift b/tests/output/swift/Tests/requests/PersonalizationTests.swift deleted file mode 100644 index a0b72ddd14..0000000000 --- a/tests/output/swift/Tests/requests/PersonalizationTests.swift +++ /dev/null @@ -1,642 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Personalization - -final class PersonalizationClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - delete deleteUserProfile - */ - func testDeleteUserProfileTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteUserProfileWithHTTPInfo(userToken: "UserToken", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/profiles/UserToken") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get getPersonalizationStrategy - */ - func testGetPersonalizationStrategyTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.getPersonalizationStrategyWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/strategies/personalization") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get getUserTokenProfile - */ - func testGetUserTokenProfileTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.getUserTokenProfileWithHTTPInfo(userToken: "UserToken", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/profiles/personalization/UserToken") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - set setPersonalizationStrategy - */ - func testSetPersonalizationStrategyTest0() async throws { - let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = PersonalizationClient(configuration: configuration, transporter: transporter) - - let response = try await client.setPersonalizationStrategyWithHTTPInfo(personalizationStrategyParams: PersonalizationStrategyParams(eventScoring: [EventScoring(score: 42, eventName: "Algolia", eventType: "Event")], facetScoring: [FacetScoring(score: 42, facetName: "Event")], personalizationImpact: 42), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"eventScoring\":[{\"score\":42,\"eventName\":\"Algolia\",\"eventType\":\"Event\"}],\"facetScoring\":[{\"score\":42,\"facetName\":\"Event\"}],\"personalizationImpact\":42}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/strategies/personalization") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift b/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift deleted file mode 100644 index 2e8b464ee8..0000000000 --- a/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift +++ /dev/null @@ -1,709 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import QuerySuggestions - -final class QuerySuggestionsClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - createConfig0 - */ - func testCreateConfigTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.createConfigWithHTTPInfo(querySuggestionsConfigurationWithIndex: QuerySuggestionsConfigurationWithIndex(indexName: "theIndexName", sourceIndices: [SourceIndex(indexName: "testIndex", facets: [Facet(attribute: "test")], generate: [["facetA", "facetB"], ["facetC"]])], languages: Languages.arrayOfString(["french"]), exclude: ["test"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"indexName\":\"theIndexName\",\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attribute\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/configs") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteConfig0 - */ - func testDeleteConfigTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteConfigWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getAllConfigs0 - */ - func testGetAllConfigsTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getAllConfigsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/configs") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getConfig0 - */ - func testGetConfigTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getConfigWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getConfigStatus0 - */ - func testGetConfigStatusTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getConfigStatusWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName/status") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getLogFile0 - */ - func testGetLogFileTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.getLogFileWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/logs/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateConfig0 - */ - func testUpdateConfigTest0() async throws { - let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateConfigWithHTTPInfo(indexName: "theIndexName", querySuggestionsConfiguration: QuerySuggestionsConfiguration(sourceIndices: [SourceIndex(indexName: "testIndex", facets: [Facet(attribute: "test")], generate: [["facetA", "facetB"], ["facetC"]])], languages: Languages.arrayOfString(["french"]), exclude: ["test"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attribute\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/RecommendTests.swift b/tests/output/swift/Tests/requests/RecommendTests.swift deleted file mode 100644 index fa08eec4f7..0000000000 --- a/tests/output/swift/Tests/requests/RecommendTests.swift +++ /dev/null @@ -1,831 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Recommend - -final class RecommendClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteRecommendRule0 - */ - func testDeleteRecommendRuleTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteRecommendRuleWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, objectID: "objectID", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/objectID") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getRecommendRule0 - */ - func testGetRecommendRuleTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendRuleWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, objectID: "objectID", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/objectID") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getRecommendStatus0 - */ - func testGetRecommendStatusTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendStatusWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, taskID: Int64(12345), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/task/12345") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get recommendations for recommend model with minimal parameters - */ - func testGetRecommendationsTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName", threshold: 42, model: RecommendationModels.relatedProducts, objectID: "objectID"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get recommendations for recommend model with all parameters - */ - func testGetRecommendationsTest1() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName", threshold: 42, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback")]))))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get recommendations for trending model with minimal parameters - */ - func testGetRecommendationsTest2() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.trendingItemsQuery(TrendingItemsQuery(indexName: "indexName", threshold: 42, model: TrendingItemsModel.trendingItems))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get recommendations for trending model with all parameters - */ - func testGetRecommendationsTest3() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.trendingItemsQuery(TrendingItemsQuery(indexName: "indexName", threshold: 42, maxRecommendations: 10, facetName: "myFacetName", facetValue: "myFacetValue", model: TrendingItemsModel.trendingItems, queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback")]))))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42,\"maxRecommendations\":10,\"facetName\":\"myFacetName\",\"facetValue\":\"myFacetValue\",\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get multiple recommendations with minimal parameters - */ - func testGetRecommendationsTest4() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 21, model: RecommendationModels.relatedProducts, objectID: "objectID1")), RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName2", threshold: 21, model: RecommendationModels.relatedProducts, objectID: "objectID2"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get multiple recommendations with all parameters - */ - func testGetRecommendationsTest5() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 21, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID1", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query1")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback1")])))), RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName2", threshold: 21, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID2", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query2")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback2")]))))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query1\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback1\"]}},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query2\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback2\"]}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get frequently bought together recommendations - */ - func testGetRecommendationsTest6() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 42, model: RecommendationModels.boughtTogether, objectID: "objectID1"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"bought-together\",\"threshold\":42}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchRecommendRules0 - */ - func testSearchRecommendRulesTest0() async throws { - let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = RecommendClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchRecommendRulesWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } -} diff --git a/tests/output/swift/Tests/requests/SearchTests.swift b/tests/output/swift/Tests/requests/SearchTests.swift deleted file mode 100644 index 740dc6c0bd..0000000000 --- a/tests/output/swift/Tests/requests/SearchTests.swift +++ /dev/null @@ -1,2997 +0,0 @@ -import SwiftyJSON -import XCTest -#if canImport(AnyCodable) - import AnyCodable -#endif - -@testable import Core -@testable import Search - -final class SearchClientRequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" - - /** - addApiKey0 - */ - func testAddApiKeyTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.addApiKeyWithHTTPInfo(apiKey: ApiKey(acl: [Acl.search, Acl.addObject], description: "my new api key", maxHitsPerQuery: 20, maxQueriesPerIPPerHour: 100, validity: 300), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"acl\":[\"search\",\"addObject\"],\"description\":\"my new api key\",\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/keys") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - addOrUpdateObject0 - */ - func testAddOrUpdateObjectTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.addOrUpdateObjectWithHTTPInfo(indexName: "indexName", objectID: "uniqueID", body: ["key": "value"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"key\":\"value\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/uniqueID") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - appendSource0 - */ - func testAppendSourceTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.appendSourceWithHTTPInfo(source: Source(source: "theSource", description: "theDescription"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"source\":\"theSource\",\"description\":\"theDescription\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/security/sources/append") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - assignUserId0 - */ - func testAssignUserIdTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.assignUserIdWithHTTPInfo(xAlgoliaUserID: "userID", assignUserIdParams: AssignUserIdParams(cluster: "theCluster"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"cluster\":\"theCluster\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-user-id\":\"userID\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - allows batch method with `addObject` action - */ - func testBatchTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.addObject, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"addObject\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `clear` action - */ - func testBatchTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.clear, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"clear\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `delete` action - */ - func testBatchTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.delete, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"delete\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `deleteObject` action - */ - func testBatchTest3() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.deleteObject, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"deleteObject\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `partialUpdateObject` action - */ - func testBatchTest4() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.partialUpdateObject, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"partialUpdateObject\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `partialUpdateObjectNoCreate` action - */ - func testBatchTest5() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.partialUpdateObjectNoCreate, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"partialUpdateObjectNoCreate\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allows batch method with `updateObject` action - */ - func testBatchTest6() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.updateObject, body: ["key": "value"])]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"updateObject\",\"body\":{\"key\":\"value\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - batchAssignUserIds0 - */ - func testBatchAssignUserIdsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchAssignUserIdsWithHTTPInfo(xAlgoliaUserID: "userID", batchAssignUserIdsParams: BatchAssignUserIdsParams(cluster: "theCluster", users: ["user1", "user2"]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"cluster\":\"theCluster\",\"users\":[\"user1\",\"user2\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-user-id\":\"userID\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - get batchDictionaryEntries results with minimal parameters - */ - func testBatchDictionaryEntriesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(objectID: "1", language: "en")), BatchDictionaryEntriesRequest(action: DictionaryAction.deleteEntry, body: DictionaryEntry(objectID: "2", language: "fr"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get batchDictionaryEntries results with all parameters - */ - func testBatchDictionaryEntriesTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(clearExistingDictionaryEntries: false, requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(objectID: "1", language: "en", word: "fancy", words: ["believe", "algolia"], decomposition: ["trust", "algolia"], state: DictionaryEntryState.enabled)), BatchDictionaryEntriesRequest(action: DictionaryAction.deleteEntry, body: DictionaryEntry(objectID: "2", language: "fr", word: "humility", words: ["candor", "algolia"], decomposition: ["grit", "algolia"], state: DictionaryEntryState.enabled))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"clearExistingDictionaryEntries\":false,\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\",\"word\":\"fancy\",\"words\":[\"believe\",\"algolia\"],\"decomposition\":[\"trust\",\"algolia\"],\"state\":\"enabled\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\",\"word\":\"humility\",\"words\":[\"candor\",\"algolia\"],\"decomposition\":[\"grit\",\"algolia\"],\"state\":\"enabled\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get batchDictionaryEntries results additional properties - */ - func testBatchDictionaryEntriesTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(from: ["objectID": "1", "language": "en", "additional": "try me"]))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\",\"additional\":\"try me\"}}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - browse with minimal parameters - */ - func testBrowseTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.browseWithHTTPInfo(indexName: "cts_e2e_browse", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_browse/browse") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - browse with search parameters - */ - func testBrowseTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.browseWithHTTPInfo(indexName: "indexName", browseParams: BrowseParams.browseParamsObject(BrowseParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("tags:algolia")]))), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/browse") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - browse allow a cursor in parameters - */ - func testBrowseTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.browseWithHTTPInfo(indexName: "indexName", browseParams: BrowseParams.browseParamsObject(BrowseParamsObject(cursor: "test")), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"cursor\":\"test\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/browse") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - clearObjects0 - */ - func testClearObjectsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.clearObjectsWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/clear") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - clearRules0 - */ - func testClearRulesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.clearRulesWithHTTPInfo(indexName: "indexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/clear") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - clearSynonyms0 - */ - func testClearSynonymsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.clearSynonymsWithHTTPInfo(indexName: "indexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/clear") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with minimal parameters - */ - func testCustomDeleteTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow del method for a custom path with all parameters - */ - func testCustomDeleteTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow get method for a custom path with minimal parameters - */ - func testCustomGetTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow get method for a custom path with all parameters - */ - func testCustomGetTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow post method for a custom path with minimal parameters - */ - func testCustomPostTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow post method for a custom path with all parameters - */ - func testCustomPostTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default query parameters - */ - func testCustomPostTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions merges query parameters with default ones - */ - func testCustomPostTest3() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "query2": "myQueryParameter", - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions can override default headers - */ - func testCustomPostTest4() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions merges headers with default ones - */ - func testCustomPostTest5() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - headers: [ - "x-algolia-api-key": "myApiKey", - ] - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - - let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) - let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) - - let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) - for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) - } - } - - /** - requestOptions queryParameters accepts booleans - */ - func testCustomPostTest6() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "isItWorking": true, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts integers - */ - func testCustomPostTest7() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": 2, - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of string - */ - func testCustomPostTest8() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": ["c", "d"], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of booleans - */ - func testCustomPostTest9() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [true, true, false], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - requestOptions queryParameters accepts list of integers - */ - func testCustomPostTest10() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let requestOptions = RequestOptions( - queryItems: APIHelper.mapValuesToQueryItems([ - "myParam": [1, 2], - ]) - ) - - let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"facet\":\"filters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - allow put method for a custom path with minimal parameters - */ - func testCustomPutTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/minimal") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - allow put method for a custom path with all parameters - */ - func testCustomPutTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"body\":\"parameters\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/test/all") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - deleteApiKey0 - */ - func testDeleteApiKeyTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteApiKeyWithHTTPInfo(key: "myTestApiKey", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/keys/myTestApiKey") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteBy0 - */ - func testDeleteByTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteByWithHTTPInfo(indexName: "theIndexName", deleteByParams: DeleteByParams(filters: "brand:brandName"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"filters\":\"brand:brandName\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/deleteByQuery") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteIndex0 - */ - func testDeleteIndexTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteIndexWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteObject0 - */ - func testDeleteObjectTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - delete rule simple case - */ - func testDeleteRuleTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - delete rule with simple characters to encode in objectID - */ - func testDeleteRuleTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteRuleWithHTTPInfo(indexName: "indexName", objectID: "test/with/slash", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/test%2Fwith%2Fslash") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteSource0 - */ - func testDeleteSourceTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteSourceWithHTTPInfo(source: "theSource", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/security/sources/theSource") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - deleteSynonym0 - */ - func testDeleteSynonymTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.deleteSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getApiKey0 - */ - func testGetApiKeyTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getApiKeyWithHTTPInfo(key: "myTestApiKey", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/keys/myTestApiKey") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get getDictionaryLanguages - */ - func testGetDictionaryLanguagesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getDictionaryLanguagesWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/languages") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get getDictionarySettings results - */ - func testGetDictionarySettingsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getDictionarySettingsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getLogs with minimal parameters - */ - func testGetLogsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getLogsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/logs") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getLogs with parameters - */ - func testGetLogsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getLogsWithHTTPInfo(offset: 5, length: 10, indexName: "theIndexName", type: LogType.all, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/logs") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - getObject0 - */ - func testGetObjectTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", attributesToRetrieve: ["attr1", "attr2"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"attributesToRetrieve\":\"attr1,attr2\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - getObjects0 - */ - func testGetObjectsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getObjectsWithHTTPInfo(getObjectsParams: GetObjectsParams(requests: [GetObjectsRequest(attributesToRetrieve: ["attr1", "attr2"], objectID: "uniqueID", indexName: "theIndexName")]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"attributesToRetrieve\":[\"attr1\",\"attr2\"],\"objectID\":\"uniqueID\",\"indexName\":\"theIndexName\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/objects") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getRule0 - */ - func testGetRuleTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getSettings0 - */ - func testGetSettingsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSettingsWithHTTPInfo(indexName: "cts_e2e_settings", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_settings/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getSources0 - */ - func testGetSourcesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSourcesWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/security/sources") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getSynonym0 - */ - func testGetSynonymTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getTask0 - */ - func testGetTaskTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTaskWithHTTPInfo(indexName: "theIndexName", taskID: Int64(123), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/task/123") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getTopUserIds0 - */ - func testGetTopUserIdsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getTopUserIdsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/top") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - getUserId0 - */ - func testGetUserIdTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.getUserIdWithHTTPInfo(userID: "uniqueID", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/uniqueID") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - hasPendingMappings with minimal parameters - */ - func testHasPendingMappingsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.hasPendingMappingsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/pending") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - hasPendingMappings with parameters - */ - func testHasPendingMappingsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.hasPendingMappingsWithHTTPInfo(getClusters: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/pending") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"getClusters\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - listApiKeys0 - */ - func testListApiKeysTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listApiKeysWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/keys") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listClusters0 - */ - func testListClustersTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listClustersWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listIndices with minimal parameters - */ - func testListIndicesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listIndicesWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listIndices with parameters - */ - func testListIndicesTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listIndicesWithHTTPInfo(page: 8, hitsPerPage: 3, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/indexes") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"page\":\"8\",\"hitsPerPage\":\"3\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - listUserIds with minimal parameters - */ - func testListUserIdsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listUserIdsWithHTTPInfo(requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - listUserIds with parameters - */ - func testListUserIdsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.listUserIdsWithHTTPInfo(page: 8, hitsPerPage: 100, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") - XCTAssertEqual(echoResponse.method, HTTPMethod.get) - - let comparableQueryItems = try XCTUnwrap("{\"page\":\"8\",\"hitsPerPage\":\"100\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - multipleBatch0 - */ - func testMultipleBatchTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.multipleBatchWithHTTPInfo(batchParams: BatchParams(requests: [MultipleBatchRequest(action: Action.addObject, body: ["key": "value"], indexName: "theIndexName")]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"action\":\"addObject\",\"body\":{\"key\":\"value\"},\"indexName\":\"theIndexName\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - operationIndex0 - */ - func testOperationIndexTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.operationIndexWithHTTPInfo(indexName: "theIndexName", operationIndexParams: OperationIndexParams(operation: OperationType.copy, destination: "dest", scope: [ScopeType.rules, ScopeType.settings]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"operation\":\"copy\",\"destination\":\"dest\",\"scope\":[\"rules\",\"settings\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/operation") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - partialUpdateObject0 - */ - func testPartialUpdateObjectTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.partialUpdateObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", attributesToUpdate: ["id1": AttributeToUpdate.string("test"), "id2": AttributeToUpdate.builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: "test2"))], createIfNotExists: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"id1\":\"test\",\"id2\":{\"_operation\":\"AddUnique\",\"value\":\"test2\"}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID/partial") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"createIfNotExists\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - removeUserId0 - */ - func testRemoveUserIdTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.removeUserIdWithHTTPInfo(userID: "uniqueID", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - XCTAssertNil(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/uniqueID") - XCTAssertEqual(echoResponse.method, HTTPMethod.delete) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - replaceSources0 - */ - func testReplaceSourcesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.replaceSourcesWithHTTPInfo(source: [Source(source: "theSource", description: "theDescription")], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "[{\"source\":\"theSource\",\"description\":\"theDescription\"}]" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/security/sources") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - restoreApiKey0 - */ - func testRestoreApiKeyTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.restoreApiKeyWithHTTPInfo(key: "myApiKey", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - - XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) - - XCTAssertEqual(echoResponse.path, "/1/keys/myApiKey/restore") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - saveObject0 - */ - func testSaveObjectTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveObjectWithHTTPInfo(indexName: "theIndexName", body: ["objectID": "id", "test": "val"], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"objectID\":\"id\",\"test\":\"val\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - saveRule with minimal parameters - */ - func testSaveRuleTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", rule: Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains)]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - saveRule with all parameters - */ - func testSaveRuleTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", rule: Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains, alternatives: false, context: "search")], consequence: Consequence(params: ConsequenceParams(filters: "brand:apple", query: ConsequenceQuery.consequenceQueryObject(ConsequenceQueryObject(remove: ["algolia"], edits: [Edit(type: EditType.remove, delete: "abc", insert: "cde"), Edit(type: EditType.replace, delete: "abc", insert: "cde")]))), promote: [Promote.promoteObjectID(PromoteObjectID(objectID: "abc", position: 3)), Promote.promoteObjectIDs(PromoteObjectIDs(objectIDs: ["abc", "def"], position: 1))], filterPromotes: false, hide: [ConsequenceHide(objectID: "321")], userData: ["algolia": "aloglia"]), description: "test", enabled: true, validity: [TimeRange(from: 1_656_670_273, until: 1_656_670_277)]), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\",\"alternatives\":false,\"context\":\"search\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\",\"query\":{\"remove\":[\"algolia\"],\"edits\":[{\"type\":\"remove\",\"delete\":\"abc\",\"insert\":\"cde\"},{\"type\":\"replace\",\"delete\":\"abc\",\"insert\":\"cde\"}]}},\"hide\":[{\"objectID\":\"321\"}],\"filterPromotes\":false,\"userData\":{\"algolia\":\"aloglia\"},\"promote\":[{\"objectID\":\"abc\",\"position\":3},{\"objectIDs\":[\"abc\",\"def\"],\"position\":1}]},\"description\":\"test\",\"enabled\":true,\"validity\":[{\"from\":1656670273,\"until\":1656670277}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - saveRules with minimal parameters - */ - func testSaveRulesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveRulesWithHTTPInfo(indexName: "indexName", rules: [Rule(objectID: "a-rule-id", conditions: [Condition(pattern: "smartphone", anchoring: Anchoring.contains)]), Rule(objectID: "a-second-rule-id", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains)])], requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "[{\"objectID\":\"a-rule-id\",\"conditions\":[{\"pattern\":\"smartphone\",\"anchoring\":\"contains\"}]},{\"objectID\":\"a-second-rule-id\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}]}]" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - saveRules with all parameters - */ - func testSaveRulesTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveRulesWithHTTPInfo(indexName: "indexName", rules: [Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains, alternatives: false, context: "search")], consequence: Consequence(params: ConsequenceParams(filters: "brand:apple", query: ConsequenceQuery.consequenceQueryObject(ConsequenceQueryObject(remove: ["algolia"], edits: [Edit(type: EditType.remove, delete: "abc", insert: "cde"), Edit(type: EditType.replace, delete: "abc", insert: "cde")]))), promote: [Promote.promoteObjectID(PromoteObjectID(objectID: "abc", position: 3)), Promote.promoteObjectIDs(PromoteObjectIDs(objectIDs: ["abc", "def"], position: 1))], filterPromotes: false, hide: [ConsequenceHide(objectID: "321")], userData: ["algolia": "aloglia"]), description: "test", enabled: true, validity: [TimeRange(from: 1_656_670_273, until: 1_656_670_277)])], forwardToReplicas: true, clearExistingRules: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "[{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\",\"alternatives\":false,\"context\":\"search\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\",\"query\":{\"remove\":[\"algolia\"],\"edits\":[{\"type\":\"remove\",\"delete\":\"abc\",\"insert\":\"cde\"},{\"type\":\"replace\",\"delete\":\"abc\",\"insert\":\"cde\"}]}},\"hide\":[{\"objectID\":\"321\"}],\"filterPromotes\":false,\"userData\":{\"algolia\":\"aloglia\"},\"promote\":[{\"objectID\":\"abc\",\"position\":3},{\"objectIDs\":[\"abc\",\"def\"],\"position\":1}]},\"description\":\"test\",\"enabled\":true,\"validity\":[{\"from\":1656670273,\"until\":1656670277}]}]" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - saveSynonym0 - */ - func testSaveSynonymTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", synonymHit: SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - saveSynonyms0 - */ - func testSaveSynonymsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.saveSynonymsWithHTTPInfo(indexName: "indexName", synonymHit: [SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]), SynonymHit(objectID: "id2", type: SynonymType.onewaysynonym, synonyms: ["ephone", "aphone", "yphone"], input: "iphone")], forwardToReplicas: true, replaceExistingSynonyms: false, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "[{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]},{\"objectID\":\"id2\",\"type\":\"onewaysynonym\",\"input\":\"iphone\",\"synonyms\":[\"ephone\",\"aphone\",\"yphone\"]}]" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/batch") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - search for a single hits request with minimal parameters - */ - func testSearchTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(indexName: "cts_e2e_search_empty_index"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"cts_e2e_search_empty_index\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search for a single facet request with minimal parameters - */ - func testSearchTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(facet: "editor", indexName: "cts_e2e_search_facet", type: SearchTypeFacet.facet))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"cts_e2e_search_facet\",\"type\":\"facet\",\"facet\":\"editor\"}],\"strategy\":\"stopIfEnoughMatches\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search for a single hits request with all parameters - */ - func testSearchTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(query: "myQuery", hitsPerPage: 50, indexName: "theIndexName", type: SearchTypeDefault.default))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"theIndexName\",\"query\":\"myQuery\",\"hitsPerPage\":50,\"type\":\"default\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search for a single facet request with all parameters - */ - func testSearchTest3() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(query: "theQuery", maxFacetHits: 50, facet: "theFacet", indexName: "theIndexName", facetQuery: "theFacetQuery", type: SearchTypeFacet.facet))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"theIndexName\",\"type\":\"facet\",\"facet\":\"theFacet\",\"facetQuery\":\"theFacetQuery\",\"query\":\"theQuery\",\"maxFacetHits\":50}],\"strategy\":\"stopIfEnoughMatches\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search for multiple mixed requests in multiple indices with minimal parameters - */ - func testSearchTest4() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(indexName: "theIndexName")), SearchQuery.searchForFacets(SearchForFacets(facet: "theFacet", indexName: "theIndexName2", type: SearchTypeFacet.facet)), SearchQuery.searchForHits(SearchForHits(indexName: "theIndexName", type: SearchTypeDefault.default))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"theIndexName\"},{\"indexName\":\"theIndexName2\",\"type\":\"facet\",\"facet\":\"theFacet\"},{\"indexName\":\"theIndexName\",\"type\":\"default\"}],\"strategy\":\"stopIfEnoughMatches\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search for multiple mixed requests in multiple indices with all parameters - */ - func testSearchTest5() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(query: "theQuery", maxFacetHits: 50, facet: "theFacet", indexName: "theIndexName", facetQuery: "theFacetQuery", type: SearchTypeFacet.facet)), SearchQuery.searchForHits(SearchForHits(query: "myQuery", hitsPerPage: 50, indexName: "theIndexName", type: SearchTypeDefault.default))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"theIndexName\",\"type\":\"facet\",\"facet\":\"theFacet\",\"facetQuery\":\"theFacetQuery\",\"query\":\"theQuery\",\"maxFacetHits\":50},{\"indexName\":\"theIndexName\",\"query\":\"myQuery\",\"hitsPerPage\":50,\"type\":\"default\"}],\"strategy\":\"stopIfEnoughMatches\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search filters accept all of the possible shapes - */ - func testSearchTest6() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(facetFilters: FacetFilters.string("mySearch:filters"), optionalFilters: OptionalFilters.string("mySearch:filters"), numericFilters: NumericFilters.string("mySearch:filters"), tagFilters: TagFilters.string("mySearch:filters"), reRankingApplyFilter: ReRankingApplyFilter.string("mySearch:filters"), indexName: "theIndexName")), SearchQuery.searchForHits(SearchForHits(facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), optionalFilters: OptionalFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), numericFilters: NumericFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), tagFilters: TagFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), reRankingApplyFilter: ReRankingApplyFilter.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), indexName: "theIndexName"))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"indexName\":\"theIndexName\",\"facetFilters\":\"mySearch:filters\",\"reRankingApplyFilter\":\"mySearch:filters\",\"tagFilters\":\"mySearch:filters\",\"numericFilters\":\"mySearch:filters\",\"optionalFilters\":\"mySearch:filters\"},{\"indexName\":\"theIndexName\",\"facetFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"reRankingApplyFilter\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"tagFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"numericFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"optionalFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]]}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search with all search parameters - */ - func testSearchTest7() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(query: "", similarQuery: "", filters: "", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), optionalFilters: OptionalFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), numericFilters: NumericFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), tagFilters: TagFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), sumOrFiltersScores: true, restrictSearchableAttributes: [""], facets: [""], facetingAfterDistinct: true, page: 0, offset: 0, length: 1, aroundLatLng: "", aroundLatLngViaIP: true, aroundRadius: AroundRadius.aroundRadiusAll(AroundRadiusAll.all), aroundPrecision: AroundPrecision.int(0), minimumAroundRadius: 1, insideBoundingBox: [[47.3165, 4.9665, 47.3424, 5.0201], [40.9234, 2.1185, 38.643, 1.9916]], insidePolygon: [[47.3165, 4.9665, 47.3424, 5.0201, 47.32, 4.9], [40.9234, 2.1185, 38.643, 1.9916, 39.2587, 2.0104]], naturalLanguages: [""], ruleContexts: [""], personalizationImpact: 0, userToken: "", getRankingInfo: true, explain: ["foo", "bar"], synonyms: true, clickAnalytics: true, analytics: true, analyticsTags: [""], percentileComputation: true, enableABTest: true, attributesForFaceting: [""], attributesToRetrieve: [""], ranking: [""], customRanking: [""], relevancyStrictness: 0, attributesToHighlight: [""], attributesToSnippet: [""], highlightPreTag: "", highlightPostTag: "", snippetEllipsisText: "", restrictHighlightAndSnippetArrays: true, hitsPerPage: 1, minWordSizefor1Typo: 0, minWordSizefor2Typos: 0, typoTolerance: TypoTolerance.typoToleranceEnum(TypoToleranceEnum.min), allowTyposOnNumericTokens: true, disableTypoToleranceOnAttributes: [""], ignorePlurals: IgnorePlurals.bool(false), removeStopWords: RemoveStopWords.bool(true), keepDiacriticsOnCharacters: "", queryLanguages: [""], decompoundQuery: true, enableRules: true, enablePersonalization: true, queryType: QueryType.prefixAll, removeWordsIfNoResults: RemoveWordsIfNoResults.allOptional, advancedSyntax: true, optionalWords: [""], disableExactOnAttributes: [""], exactOnSingleWordQuery: ExactOnSingleWordQuery.attribute, alternativesAsExact: [AlternativesAsExact.multiWordsSynonym], advancedSyntaxFeatures: [AdvancedSyntaxFeatures.exactPhrase], distinct: Distinct.int(0), replaceSynonymsInHighlight: true, minProximity: 1, responseFields: [""], maxValuesPerFacet: 0, sortFacetValuesBy: "", attributeCriteriaComputedByMinProximity: true, renderingContent: RenderingContent(facetOrdering: FacetOrdering(facets: Facets(order: ["a", "b"]), values: ["a": Value(order: ["b"], sortRemainingBy: SortRemainingBy.count)])), enableReRanking: true, reRankingApplyFilter: ReRankingApplyFilter.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), indexName: "theIndexName", type: SearchTypeDefault.default))]), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"requests\":[{\"advancedSyntax\":true,\"advancedSyntaxFeatures\":[\"exactPhrase\"],\"allowTyposOnNumericTokens\":true,\"alternativesAsExact\":[\"multiWordsSynonym\"],\"analytics\":true,\"analyticsTags\":[\"\"],\"aroundLatLng\":\"\",\"aroundLatLngViaIP\":true,\"aroundPrecision\":0,\"aroundRadius\":\"all\",\"attributeCriteriaComputedByMinProximity\":true,\"attributesForFaceting\":[\"\"],\"attributesToHighlight\":[\"\"],\"attributesToRetrieve\":[\"\"],\"attributesToSnippet\":[\"\"],\"clickAnalytics\":true,\"customRanking\":[\"\"],\"decompoundQuery\":true,\"disableExactOnAttributes\":[\"\"],\"disableTypoToleranceOnAttributes\":[\"\"],\"distinct\":0,\"enableABTest\":true,\"enablePersonalization\":true,\"enableReRanking\":true,\"enableRules\":true,\"exactOnSingleWordQuery\":\"attribute\",\"explain\":[\"foo\",\"bar\"],\"facetFilters\":[\"\"],\"facetingAfterDistinct\":true,\"facets\":[\"\"],\"filters\":\"\",\"getRankingInfo\":true,\"highlightPostTag\":\"\",\"highlightPreTag\":\"\",\"hitsPerPage\":1,\"ignorePlurals\":false,\"indexName\":\"theIndexName\",\"insideBoundingBox\":[[47.3165,4.9665,47.3424,5.0201],[40.9234,2.1185,38.643,1.9916]],\"insidePolygon\":[[47.3165,4.9665,47.3424,5.0201,47.32,4.9],[40.9234,2.1185,38.643,1.9916,39.2587,2.0104]],\"keepDiacriticsOnCharacters\":\"\",\"length\":1,\"maxValuesPerFacet\":0,\"minProximity\":1,\"minWordSizefor1Typo\":0,\"minWordSizefor2Typos\":0,\"minimumAroundRadius\":1,\"naturalLanguages\":[\"\"],\"numericFilters\":[\"\"],\"offset\":0,\"optionalFilters\":[\"\"],\"optionalWords\":[\"\"],\"page\":0,\"percentileComputation\":true,\"personalizationImpact\":0,\"query\":\"\",\"queryLanguages\":[\"\"],\"queryType\":\"prefixAll\",\"ranking\":[\"\"],\"reRankingApplyFilter\":[\"\"],\"relevancyStrictness\":0,\"removeStopWords\":true,\"removeWordsIfNoResults\":\"allOptional\",\"renderingContent\":{\"facetOrdering\":{\"facets\":{\"order\":[\"a\",\"b\"]},\"values\":{\"a\":{\"order\":[\"b\"],\"sortRemainingBy\":\"count\"}}}},\"replaceSynonymsInHighlight\":true,\"responseFields\":[\"\"],\"restrictHighlightAndSnippetArrays\":true,\"restrictSearchableAttributes\":[\"\"],\"ruleContexts\":[\"\"],\"similarQuery\":\"\",\"snippetEllipsisText\":\"\",\"sortFacetValuesBy\":\"\",\"sumOrFiltersScores\":true,\"synonyms\":true,\"tagFilters\":[\"\"],\"type\":\"default\",\"typoTolerance\":\"min\",\"userToken\":\"\"}]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get searchDictionaryEntries results with minimal parameters - */ - func testSearchDictionaryEntriesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, searchDictionaryEntriesParams: SearchDictionaryEntriesParams(query: "foo"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"foo\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get searchDictionaryEntries results with all parameters - */ - func testSearchDictionaryEntriesTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, searchDictionaryEntriesParams: SearchDictionaryEntriesParams(query: "foo", page: 4, hitsPerPage: 2, language: "fr"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"foo\",\"page\":4,\"hitsPerPage\":2,\"language\":\"fr\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get searchForFacetValues results with minimal parameters - */ - func testSearchForFacetValuesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchForFacetValuesWithHTTPInfo(indexName: "indexName", facetName: "facetName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/facets/facetName/query") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get searchForFacetValues results with all parameters - */ - func testSearchForFacetValuesTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchForFacetValuesWithHTTPInfo(indexName: "indexName", facetName: "facetName", searchForFacetValuesRequest: SearchForFacetValuesRequest(params: "query=foo&facetFilters=['bar']", facetQuery: "foo", maxFacetHits: 42), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"params\":\"query=foo&facetFilters=['bar']\",\"facetQuery\":\"foo\",\"maxFacetHits\":42}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/facets/facetName/query") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchRules0 - */ - func testSearchRulesTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchRulesWithHTTPInfo(indexName: "indexName", searchRulesParams: SearchRulesParams(query: "something"), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"something\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search with minimal parameters - */ - func testSearchSingleIndexTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "indexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/query") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search with special characters in indexName - */ - func testSearchSingleIndexTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "cts_e2e_space in index", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_space%20in%20index/query") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - search with searchParams - */ - func testSearchSingleIndexTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "indexName", searchParams: SearchParams.searchParamsObject(SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("tags:algolia")]))), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/query") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchSynonyms with minimal parameters - */ - func testSearchSynonymsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSynonymsWithHTTPInfo(indexName: "indexName", requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchSynonyms with all parameters - */ - func testSearchSynonymsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchSynonymsWithHTTPInfo(indexName: "indexName", searchSynonymsParams: SearchSynonymsParams(query: "myQuery", type: SynonymType.altcorrection1, page: 10, hitsPerPage: 10), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"myQuery\",\"type\":\"altcorrection1\",\"page\":10,\"hitsPerPage\":10}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - searchUserIds0 - */ - func testSearchUserIdsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.searchUserIdsWithHTTPInfo(searchUserIdsParams: SearchUserIdsParams(query: "test", clusterName: "theClusterName", page: 5, hitsPerPage: 10), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"query\":\"test\",\"clusterName\":\"theClusterName\",\"page\":5,\"hitsPerPage\":10}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/search") - XCTAssertEqual(echoResponse.method, HTTPMethod.post) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get setDictionarySettings results with minimal parameters - */ - func testSetDictionarySettingsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setDictionarySettingsWithHTTPInfo(dictionarySettingsParams: DictionarySettingsParams(disableStandardEntries: StandardEntries(plurals: ["fr": false, "en": false, "ru": true])), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true}}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - get setDictionarySettings results with all parameters - */ - func testSetDictionarySettingsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setDictionarySettingsWithHTTPInfo(dictionarySettingsParams: DictionarySettingsParams(disableStandardEntries: StandardEntries(plurals: ["fr": false, "en": false, "ru": true], stopwords: ["fr": false], compounds: ["ru": true])), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true},\"stopwords\":{\"fr\":false},\"compounds\":{\"ru\":true}}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - setSettings with minimal parameters - */ - func testSetSettingsTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "cts_e2e_settings", indexSettings: IndexSettings(paginationLimitedTo: 10), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"paginationLimitedTo\":10}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_settings/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow boolean `typoTolerance` - */ - func testSetSettingsTest1() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(typoTolerance: TypoTolerance.bool(true)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"typoTolerance\":true}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow enum `typoTolerance` - */ - func testSetSettingsTest2() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(typoTolerance: TypoTolerance.typoToleranceEnum(TypoToleranceEnum.min)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"typoTolerance\":\"min\"}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow boolean `ignorePlurals` - */ - func testSetSettingsTest3() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(ignorePlurals: IgnorePlurals.bool(true)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"ignorePlurals\":true}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow list of string `ignorePlurals` - */ - func testSetSettingsTest4() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(ignorePlurals: IgnorePlurals.arrayOfString(["algolia"])), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"ignorePlurals\":[\"algolia\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow boolean `removeStopWords` - */ - func testSetSettingsTest5() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(removeStopWords: RemoveStopWords.bool(true)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"removeStopWords\":true}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow list of string `removeStopWords` - */ - func testSetSettingsTest6() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(removeStopWords: RemoveStopWords.arrayOfString(["algolia"])), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"removeStopWords\":[\"algolia\"]}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow boolean `distinct` - */ - func testSetSettingsTest7() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(distinct: Distinct.bool(true)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"distinct\":true}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow integers for `distinct` - */ - func testSetSettingsTest8() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(distinct: Distinct.int(1)), forwardToReplicas: true, requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"distinct\":1}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) - let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) - - XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) - } - - /** - setSettings allow all `indexSettings` - */ - func testSetSettingsTest9() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(replicas: [""], paginationLimitedTo: 0, unretrievableAttributes: ["foo"], disableTypoToleranceOnWords: ["algolia"], attributesToTransliterate: ["algolia"], camelCaseAttributes: ["algolia"], decompoundedAttributes: ["algolia": "aloglia"], indexLanguages: ["algolia"], disablePrefixOnAttributes: ["algolia"], allowCompressionOfIntegerArray: true, numericAttributesForFiltering: ["algolia"], separatorsToIndex: "bar", searchableAttributes: ["foo"], userData: ["user": "data"], customNormalization: ["algolia": ["aloglia": "aglolia"]], attributeForDistinct: "test", attributesForFaceting: ["algolia"], attributesToRetrieve: ["algolia"], ranking: ["geo"], customRanking: ["algolia"], relevancyStrictness: 10, attributesToHighlight: ["algolia"], attributesToSnippet: ["algolia"], highlightPreTag: "", highlightPostTag: "", snippetEllipsisText: "---", restrictHighlightAndSnippetArrays: true, hitsPerPage: 10, minWordSizefor1Typo: 5, minWordSizefor2Typos: 11, typoTolerance: TypoTolerance.bool(false), allowTyposOnNumericTokens: true, disableTypoToleranceOnAttributes: ["algolia"], ignorePlurals: IgnorePlurals.bool(false), removeStopWords: RemoveStopWords.bool(false), keepDiacriticsOnCharacters: "abc", queryLanguages: ["algolia"], decompoundQuery: false, enableRules: true, enablePersonalization: true, queryType: QueryType.prefixLast, removeWordsIfNoResults: RemoveWordsIfNoResults.lastWords, mode: Mode.neuralSearch, semanticSearch: SemanticSearch(eventSources: ["foo"]), advancedSyntax: true, optionalWords: ["myspace"], disableExactOnAttributes: ["algolia"], exactOnSingleWordQuery: ExactOnSingleWordQuery.attribute, alternativesAsExact: [AlternativesAsExact.singleWordSynonym], advancedSyntaxFeatures: [AdvancedSyntaxFeatures.exactPhrase], distinct: Distinct.int(3), replaceSynonymsInHighlight: true, minProximity: 6, responseFields: ["algolia"], maxFacetHits: 20, maxValuesPerFacet: 30, sortFacetValuesBy: "date", attributeCriteriaComputedByMinProximity: true, renderingContent: RenderingContent(facetOrdering: FacetOrdering(facets: Facets(order: ["a", "b"]), values: ["a": Value(order: ["b"], sortRemainingBy: SortRemainingBy.count)])), enableReRanking: false, reRankingApplyFilter: ReRankingApplyFilter.string("mySearch:filters")), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"advancedSyntax\":true,\"advancedSyntaxFeatures\":[\"exactPhrase\"],\"allowCompressionOfIntegerArray\":true,\"allowTyposOnNumericTokens\":true,\"alternativesAsExact\":[\"singleWordSynonym\"],\"attributeCriteriaComputedByMinProximity\":true,\"attributeForDistinct\":\"test\",\"attributesForFaceting\":[\"algolia\"],\"attributesToHighlight\":[\"algolia\"],\"attributesToRetrieve\":[\"algolia\"],\"attributesToSnippet\":[\"algolia\"],\"attributesToTransliterate\":[\"algolia\"],\"camelCaseAttributes\":[\"algolia\"],\"customNormalization\":{\"algolia\":{\"aloglia\":\"aglolia\"}},\"customRanking\":[\"algolia\"],\"decompoundQuery\":false,\"decompoundedAttributes\":{\"algolia\":\"aloglia\"},\"disableExactOnAttributes\":[\"algolia\"],\"disablePrefixOnAttributes\":[\"algolia\"],\"disableTypoToleranceOnAttributes\":[\"algolia\"],\"disableTypoToleranceOnWords\":[\"algolia\"],\"distinct\":3,\"enablePersonalization\":true,\"enableReRanking\":false,\"enableRules\":true,\"exactOnSingleWordQuery\":\"attribute\",\"highlightPreTag\":\"\",\"highlightPostTag\":\"\",\"hitsPerPage\":10,\"ignorePlurals\":false,\"indexLanguages\":[\"algolia\"],\"keepDiacriticsOnCharacters\":\"abc\",\"maxFacetHits\":20,\"maxValuesPerFacet\":30,\"minProximity\":6,\"minWordSizefor1Typo\":5,\"minWordSizefor2Typos\":11,\"mode\":\"neuralSearch\",\"numericAttributesForFiltering\":[\"algolia\"],\"optionalWords\":[\"myspace\"],\"paginationLimitedTo\":0,\"queryLanguages\":[\"algolia\"],\"queryType\":\"prefixLast\",\"ranking\":[\"geo\"],\"reRankingApplyFilter\":\"mySearch:filters\",\"relevancyStrictness\":10,\"removeStopWords\":false,\"removeWordsIfNoResults\":\"lastWords\",\"renderingContent\":{\"facetOrdering\":{\"facets\":{\"order\":[\"a\",\"b\"]},\"values\":{\"a\":{\"order\":[\"b\"],\"sortRemainingBy\":\"count\"}}}},\"replaceSynonymsInHighlight\":true,\"replicas\":[\"\"],\"responseFields\":[\"algolia\"],\"restrictHighlightAndSnippetArrays\":true,\"searchableAttributes\":[\"foo\"],\"semanticSearch\":{\"eventSources\":[\"foo\"]},\"separatorsToIndex\":\"bar\",\"snippetEllipsisText\":\"---\",\"sortFacetValuesBy\":\"date\",\"typoTolerance\":false,\"unretrievableAttributes\":[\"foo\"],\"userData\":{\"user\":\"data\"}}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } - - /** - updateApiKey0 - */ - func testUpdateApiKeyTest0() async throws { - let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) - let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) - let client = SearchClient(configuration: configuration, transporter: transporter) - - let response = try await client.updateApiKeyWithHTTPInfo(key: "myApiKey", apiKey: ApiKey(acl: [Acl.search, Acl.addObject], maxHitsPerQuery: 20, maxQueriesPerIPPerHour: 100, validity: 300), requestOptions: nil) - let responseBodyData = try XCTUnwrap(response.bodyData) - let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) - - let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) - - let comparableJSON = JSON(parseJSON: - "{\"acl\":[\"search\",\"addObject\"],\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}" - ) - - XCTAssertEqual(echoResponseBodyJSON, comparableJSON) - - XCTAssertEqual(echoResponse.path, "/1/keys/myApiKey") - XCTAssertEqual(echoResponse.method, HTTPMethod.put) - - XCTAssertNil(echoResponse.queryItems) - } -} From 7f27498a3ce8d08e6f2d4cfeffe7ba4f29cd9b35 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Fri, 26 Jan 2024 20:25:16 +0100 Subject: [PATCH 3/7] fix(cts): linux tests interop --- .../Sources/Core/Networking/Transporter.swift | 18 +++--------------- templates/swift/Version.mustache | 14 +++++++++++--- templates/swift/tests/Package.mustache | 10 ++++------ templates/swift/tests/client/suite.mustache | 5 +++-- .../swift/tests/requests/requests.mustache | 12 ++++++------ tests/output/swift/Tests/Utils/Data.swift | 2 +- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift index 037efba589..50082a6a26 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift @@ -85,13 +85,13 @@ open class Transporter { request = request.set(\.timeoutInterval, to: timeout) for (key, value) in configuration.defaultHeaders ?? [:] { - request.setValue(value, forHTTPHeaderField: key.lowercased()) + request.setValue(value, forHTTPHeaderField: key.capitalized) } request.setValue( - UserAgentController.httpHeaderValue, forHTTPHeaderField: "User-Agent".lowercased() + UserAgentController.httpHeaderValue, forHTTPHeaderField: "User-Agent".capitalized ) for (key, value) in headers { - request.setValue(value, forHTTPHeaderField: key.lowercased()) + request.setValue(value, forHTTPHeaderField: key.capitalized) } if callType == CallType.write { @@ -126,16 +126,4 @@ open class Transporter { throw AlgoliaError.noReachableHosts(intermediateErrors: intermediateErrors) } - - private func buildHeaders(with requestHeaders: [String: String]) -> [String: String] { - var httpHeaders: [String: String] = [:] - for (key, value) in configuration.defaultHeaders ?? [:] { - httpHeaders.updateValue(value, forKey: key) - } - httpHeaders.updateValue(UserAgentController.httpHeaderValue, forKey: "User-Agent") - for (key, value) in requestHeaders { - httpHeaders.updateValue(value, forKey: key) - } - return httpHeaders - } } diff --git a/templates/swift/Version.mustache b/templates/swift/Version.mustache index fc77762eb6..2b32939279 100644 --- a/templates/swift/Version.mustache +++ b/templates/swift/Version.mustache @@ -18,13 +18,21 @@ public struct Version { let components = version.components(separatedBy: ".") guard components.count >= 3 else { - fatalError("version is not formatted correctly") + fatalError("version is not formatted correctly") } self.major = Int(components[0]) ?? 0 self.minor = Int(components[1]) ?? 0 - self.patch = Int(components[2]) ?? 0 - self.prereleaseIdentifier = components.count == 4 ? components[3] : nil + + if components.count == 4 { + let prereleaseComponents = components[2].components(separatedBy: "-") + + self.patch = Int(prereleaseComponents[0]) ?? 0 + self.prereleaseIdentifier = "\(prereleaseComponents[1]).\(components[3])" + } else { + self.patch = Int(components[2]) ?? 0 + self.prereleaseIdentifier = nil + } } } diff --git a/templates/swift/tests/Package.mustache b/templates/swift/tests/Package.mustache index bf8c744be4..ff9e0cb1f6 100644 --- a/templates/swift/tests/Package.mustache +++ b/templates/swift/tests/Package.mustache @@ -7,28 +7,26 @@ let package = Package( name: "AlgoliaSearchClientTests", dependencies: [ .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.1")), - .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"), .package(path: "../../../clients/algoliasearch-client-swift"), ], targets: [ + .target(name: "Utils", path: "Tests/Utils"), .testTarget( name: "client", dependencies: [ .product(name: "AnyCodable", package: "AnyCodable"), - .product(name: "SwiftyJSON", package: "SwiftyJSON"),{{#packageList}} + .target(name: "Utils"),{{#packageList}} .product( name: "{{.}}", package: "algoliasearch-client-swift" ),{{/packageList}} - ], - path: "Tests", - sources: ["client", "Utils"] + ] ), .testTarget( name: "requests", dependencies: [ .product(name: "AnyCodable", package: "AnyCodable"), - .product(name: "SwiftyJSON", package: "SwiftyJSON"),{{#packageList}} + .target(name: "Utils"),{{#packageList}} .product( name: "{{.}}", package: "algoliasearch-client-swift" diff --git a/templates/swift/tests/client/suite.mustache b/templates/swift/tests/client/suite.mustache index 0bc355ce81..3b42e5feea 100644 --- a/templates/swift/tests/client/suite.mustache +++ b/templates/swift/tests/client/suite.mustache @@ -1,8 +1,9 @@ import XCTest -import SwiftyJSON + #if canImport(AnyCodable) -import AnyCodable + import AnyCodable #endif +import Utils @testable import Core @testable import {{import}} diff --git a/templates/swift/tests/requests/requests.mustache b/templates/swift/tests/requests/requests.mustache index d0acb09254..f319f59179 100644 --- a/templates/swift/tests/requests/requests.mustache +++ b/templates/swift/tests/requests/requests.mustache @@ -1,8 +1,9 @@ import XCTest -import SwiftyJSON + #if canImport(AnyCodable) import AnyCodable #endif +import Utils @testable import Core @testable import {{import}} @@ -42,11 +43,10 @@ final class {{client}}RequestsTests: XCTestCase { {{#request}} {{#body}} let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) - let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + let echoResponseBodyJSON = try XCTUnwrap(echoResponseBodyData.jsonString) - let comparableJSON = JSON(parseJSON: - "{{#lambda.escapeQuotes}}{{{body}}}{{/lambda.escapeQuotes}}" - ) + let comparableData = "{{#lambda.escapeQuotes}}{{{body}}}{{/lambda.escapeQuotes}}".data(using: .utf8) + let comparableJSON = try XCTUnwrap(comparableData?.jsonString) XCTAssertEqual(echoResponseBodyJSON, comparableJSON) {{/body}} @@ -83,7 +83,7 @@ final class {{client}}RequestsTests: XCTestCase { let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) for header in comparableHeadersMap { - XCTAssertEqual(echoResponseHeaders[header.key], header.value) + XCTAssertEqual(echoResponseHeaders[header.key.capitalized], header.value) } {{/headers}} {{/request}} diff --git a/tests/output/swift/Tests/Utils/Data.swift b/tests/output/swift/Tests/Utils/Data.swift index 88b93a2091..e3390d85d9 100644 --- a/tests/output/swift/Tests/Utils/Data.swift +++ b/tests/output/swift/Tests/Utils/Data.swift @@ -7,7 +7,7 @@ import Foundation -extension Data { +public extension Data { var jsonString: String? { return (try? JSONSerialization.jsonObject(with: self, options: .allowFragments)) .flatMap { From 2230ecbe376c2351a6d2dfed096d8c7e9d00ec01 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Mon, 29 Jan 2024 15:02:44 +0100 Subject: [PATCH 4/7] fix(cts): all tests green --- .../Sources/Core/Common/Credentials.swift | 2 +- .../Core/Networking/HTTP/AlgoliaError.swift | 9 ++++ .../UserAgent/UserAgentController.swift | 2 +- .../codegen/cts/tests/TestsClient.java | 14 +++++++ .../swift/playground/playground/main.swift | 2 +- templates/swift/api.mustache | 21 ++++++++-- templates/swift/client_configuration.mustache | 41 ++++++++++++++----- .../swift/tests/client/createClient.mustache | 4 +- templates/swift/tests/client/method.mustache | 4 +- templates/swift/tests/client/suite.mustache | 14 +++---- templates/swift/tests/paramValue.mustache | 2 +- .../swift/tests/requests/requests.mustache | 8 ++-- .../Tests/Utils/{Data.swift => Utils.swift} | 13 +++++- 13 files changed, 101 insertions(+), 35 deletions(-) rename tests/output/swift/Tests/Utils/{Data.swift => Utils.swift} (62%) diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/Credentials.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/Credentials.swift index 0a4021725e..5fe1c223da 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/Credentials.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/Credentials.swift @@ -9,7 +9,7 @@ import Foundation public protocol Credentials { /// ApplicationID to target. Is passed as a HTTP header. - var applicationID: String { get } + var appId: String { get } /** * APIKey for a given ApplicationID. Is passed as a HTTP header. diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift index 4bbe8435c2..c7ef3690f6 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift @@ -13,6 +13,9 @@ public enum AlgoliaError: Error, LocalizedError { case noReachableHosts(intermediateErrors: [Error]) case missingData case decodingFailure(Error) + case runtimeError(String) + case invalidCredentials(String) + case invalidArgument(String, String) public var errorDescription: String? { switch self { @@ -27,6 +30,12 @@ public enum AlgoliaError: Error, LocalizedError { return "Missing response data" case .decodingFailure: return "Response decoding failed" + case let .runtimeError(error): + return "\(error)" + case let .invalidCredentials(credential): + return "`\(credential)` is missing." + case let .invalidArgument(argument, operationId): + return "Parameter `\(argument)` is required when calling `\(operationId)`." } } } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgentController.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgentController.swift index 0f424641d1..f30c28f981 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgentController.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgentController.swift @@ -13,7 +13,7 @@ public enum UserAgentController { } public internal(set) static var extensions: [UserAgentExtending] = [ - UserAgent.operatingSystem, UserAgent.library, + UserAgent.library, UserAgent.operatingSystem, ] public static var httpHeaderValue: String { diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index 1e3453e2c6..caffb3ae36 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -83,6 +83,20 @@ public void run(Map models, Map } paramsType.enhanceParameters(step.parameters, stepOut, ope); + // Swift is strongly-typed and compiled language, + // it can't have nil object when something is expected + if (language.equals("swift")) { + @SuppressWarnings("unchecked") + var isNotTestable = + step.type != null && + step.type.equals("method") && + ((List>) stepOut.getOrDefault("parametersWithDataType", new ArrayList<>())).stream() + .anyMatch(item -> (boolean) item.getOrDefault("isNullObject", false)); + if (isNotTestable) { + continue; + } + } + if (step.expected.type != null) { switch (step.expected.type) { case "userAgent": diff --git a/playground/swift/playground/playground/main.swift b/playground/swift/playground/playground/main.swift index f9d94714a2..399e3c159b 100644 --- a/playground/swift/playground/playground/main.swift +++ b/playground/swift/playground/playground/main.swift @@ -35,7 +35,7 @@ Task { .init(firstname: "Warren", lastname: "Speach", followers: 42, company: "Norwalk Crmc") ] - let client = SearchClient(applicationID: applicationID, apiKey: apiKey) + let client = SearchClient(appId: applicationID, apiKey: apiKey) for contact in contacts { let saveObjRes = try await client.saveObject(indexName: "contacts", body: contact) diff --git a/templates/swift/api.mustache b/templates/swift/api.mustache index 446624defb..7237440169 100644 --- a/templates/swift/api.mustache +++ b/templates/swift/api.mustache @@ -15,8 +15,8 @@ typealias Client = {{classname}} private var configuration: Configuration private var transporter: Transporter - var applicationID: String { - self.configuration.applicationID + var appId: String { + self.configuration.appId } public init(configuration: Configuration, transporter: Transporter) { @@ -28,8 +28,8 @@ typealias Client = {{classname}} self.init(configuration: configuration, transporter: Transporter(configuration: configuration)) } - public convenience init(applicationID: String, apiKey: String{{#hasRegionalHost}}, region: Region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}{{/hasRegionalHost}}) throws { - self.init(configuration: try Configuration(applicationID: applicationID, apiKey: apiKey{{#hasRegionalHost}}, region: region{{/hasRegionalHost}})) + public convenience init(appId: String, apiKey: String{{#hasRegionalHost}}, region: Region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}{{/hasRegionalHost}}) throws { + self.init(configuration: try Configuration(appId: appId, apiKey: apiKey{{#hasRegionalHost}}, region: region{{/hasRegionalHost}})) } {{#operation}} @@ -105,6 +105,19 @@ typealias Client = {{classname}} {{/isDeprecated}} {{^returnType}}@discardableResult{{/returnType}} {{#vendorExtensions}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func {{operationId}}WithHTTPInfo({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}[{{enumName}}_{{operationId}}]{{/isContainer}}{{^isContainer}}{{enumName}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{#lambda.to-codable}}{{{dataType}}}{{/lambda.to-codable}}{{/isEnum}}{{^required}}? = nil{{/required}}, {{/allParams}}requestOptions userRequestOptions: RequestOptions? = nil) async throws -> Response<{{{returnType}}}{{#returnType}}{{#isResponseOptional}}?{{/isResponseOptional}}{{/returnType}}{{^returnType}}AnyCodable{{/returnType}}> { + {{#pathParams}}{{#isString}}{{#required}}guard !{{{paramName}}}.isEmpty else { + throw AlgoliaError.invalidArgument("{{{paramName}}}", "{{{operationId}}}") + } + + {{/required}}{{/isString}}{{/pathParams}}{{#queryParams}}{{#isString}}{{#required}}guard !{{{paramName}}}.isEmpty else { + throw AlgoliaError.invalidArgument("{{{paramName}}}", "{{{operationId}}}") + } + + {{/required}}{{/isString}}{{/queryParams}}{{#bodyParam}}{{#isFreeFormObject}}{{#required}}guard !{{{paramName}}}.isEmpty else { + throw AlgoliaError.invalidArgument("{{{paramName}}}", "{{{operationId}}}") + } + + {{/required}}{{/isFreeFormObject}}{{/bodyParam}} {{^pathParams}}let{{/pathParams}}{{#pathParams}}{{#-first}}var{{/-first}}{{/pathParams}} resourcePath = "{{{path}}}"{{#pathParams}} let {{paramName}}PreEscape = "\({{#isEnum}}{{paramName}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}}{{^isEnum}}APIHelper.mapValueToPathItem({{paramName}}){{/isEnum}})" let {{paramName}}PostEscape = {{paramName}}PreEscape.addingPercentEncoding(withAllowedCharacters: .{{#x-is-custom-request}}urlPathAllowed{{/x-is-custom-request}}{{^x-is-custom-request}}urlPathAlgoliaAllowed{{/x-is-custom-request}}) ?? "" diff --git a/templates/swift/client_configuration.mustache b/templates/swift/client_configuration.mustache index eff9cafd99..c726e514af 100644 --- a/templates/swift/client_configuration.mustache +++ b/templates/swift/client_configuration.mustache @@ -6,6 +6,8 @@ import Core import AnyCodable #endif +typealias {{#lambda.client-to-name}}{{{client}}}{{/lambda.client-to-name}}ClientConfiguration = Configuration + public struct Configuration: Core.Configuration, Credentials { {{#hasRegionalHost}} @@ -14,7 +16,7 @@ public struct Configuration: Core.Configuration, Credentials { ] {{/hasRegionalHost}} - public let applicationID: String + public let appId: String public let apiKey: String public var writeTimeout: TimeInterval public var readTimeout: TimeInterval @@ -24,7 +26,7 @@ public struct Configuration: Core.Configuration, Credentials { public let batchSize: Int{{/isSearchClient}} - init(applicationID: String, + init(appId: String, apiKey: String,{{#hasRegionalHost}} region: Region{{#fallbackToAliasHost}}? = nil{{/fallbackToAliasHost}},{{/hasRegionalHost}} writeTimeout: TimeInterval = DefaultConfiguration.default.writeTimeout, @@ -32,25 +34,33 @@ public struct Configuration: Core.Configuration, Credentials { logLevel: LogLevel = DefaultConfiguration.default.logLevel, defaultHeaders: [String: String]? = DefaultConfiguration.default.defaultHeaders{{#isSearchClient}}, batchSize: Int = 1000{{/isSearchClient}}) throws { - self.applicationID = applicationID + guard !appId.isEmpty else { + throw AlgoliaError.invalidCredentials("appId") + } + + guard !apiKey.isEmpty else { + throw AlgoliaError.invalidCredentials("apiKey") + } + + self.appId = appId self.apiKey = apiKey self.writeTimeout = writeTimeout self.readTimeout = readTimeout self.logLevel = logLevel self.defaultHeaders = [ - "X-Algolia-Application-Id": applicationID, + "X-Algolia-Application-Id": appId, "X-Algolia-API-Key": apiKey, "Content-Type": "application/json" ].merging(defaultHeaders ?? [:]) { (_, new) in new }{{#isSearchClient}} self.batchSize = batchSize{{/isSearchClient}} - {{^hasRegionalHost}} + {{^uniqueHost}}{{^hasRegionalHost}} func buildHost(_ components: (suffix: String, callType: RetryableHost.CallTypeSupport)) throws -> RetryableHost { - guard let url = URL(string: "https://\(applicationID)\(components.suffix)") else { - throw GenericError(description: "Malformed URL") + guard let url = URL(string: "https://\(appId)\(components.suffix)") else { + throw AlgoliaError.runtimeError("Malformed URL") } return RetryableHost(url: url, callType: components.callType) @@ -68,10 +78,19 @@ public struct Configuration: Core.Configuration, Credentials { ].map(buildHost).shuffled() self.hosts = hosts + commonHosts -{{/hasRegionalHost}} +{{/hasRegionalHost}}{{/uniqueHost}} +{{#uniqueHost}} + guard let url = URL(string: "https://{{{.}}}") else { + throw AlgoliaError.runtimeError("Malformed URL") + } + + self.hosts = [ + .init(url: url) + ] +{{/uniqueHost}} {{#hasRegionalHost}} guard {{#fallbackToAliasHost}}region == nil || {{/fallbackToAliasHost}}authorizedRegions.contains(region{{#fallbackToAliasHost}}!{{/fallbackToAliasHost}}) else { - throw GenericError(description: + throw AlgoliaError.runtimeError( "`region` {{^fallbackToAliasHost}}is required and {{/fallbackToAliasHost}}must be one of the following: \(authorizedRegions.map { $0.rawValue }.joined(separator: ", "))" ) } @@ -80,7 +99,7 @@ public struct Configuration: Core.Configuration, Credentials { if let region = region { {{/fallbackToAliasHost}} guard let url = URL(string: "https://{{{regionalHost}}}".replacingOccurrences(of: "{region}", with: region.rawValue)) else { - throw GenericError(description: "Malformed URL") + throw AlgoliaError.runtimeError("Malformed URL") } self.hosts = [ @@ -89,7 +108,7 @@ public struct Configuration: Core.Configuration, Credentials { {{#fallbackToAliasHost}} } else { guard let url = URL(string: "https://{{{hostWithFallback}}}") else { - throw GenericError(description: "Malformed URL") + throw AlgoliaError.runtimeError("Malformed URL") } self.hosts = [ diff --git a/templates/swift/tests/client/createClient.mustache b/templates/swift/tests/client/createClient.mustache index 7a874efeaa..3b0bedc80d 100644 --- a/templates/swift/tests/client/createClient.mustache +++ b/templates/swift/tests/client/createClient.mustache @@ -1 +1,3 @@ -{{^autoCreateClient}}let client = {{/autoCreateClient}}try {{client}}(applicationID: "{{parametersWithDataTypeMap.appId.value}}", apiKey: "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}, region: {{#parametersWithDataTypeMap.region}}Region(rawValue: "{{parametersWithDataTypeMap.region.value}}"){{/parametersWithDataTypeMap.region}}{{^parametersWithDataTypeMap.region}}nil{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}) \ No newline at end of file +let configuration: {{import}}.Configuration = try {{import}}.Configuration(appId: "{{parametersWithDataTypeMap.appId.value}}", apiKey: "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}, region: {{#parametersWithDataTypeMap.region}}Region(rawValue: "{{parametersWithDataTypeMap.region.value}}"){{/parametersWithDataTypeMap.region}}{{^parametersWithDataTypeMap.region}}nil{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}) +let transporter: Transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) +{{^autoCreateClient}}let client = {{/autoCreateClient}}{{client}}(configuration: configuration, transporter: transporter) \ No newline at end of file diff --git a/templates/swift/tests/client/method.mustache b/templates/swift/tests/client/method.mustache index 04adeae62f..238181d015 100644 --- a/templates/swift/tests/client/method.mustache +++ b/templates/swift/tests/client/method.mustache @@ -1,3 +1,5 @@ -let response = try await client{{#path}}.{{.}}WithHTTPInfo{{/path}}({{#parametersWithDataType}}{{> tests/generateParams }}{{^-last}}, {{/-last}}{{/parametersWithDataType}}) +let response = try await client{{#path}}.{{.}}WithHTTPInfo{{/path}}( +{{#parametersWithDataType}}{{> tests/generateParams }}{{^-last}},{{/-last}} +{{/parametersWithDataType}}) let responseBodyData = try XCTUnwrap(response.bodyData) let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) \ No newline at end of file diff --git a/templates/swift/tests/client/suite.mustache b/templates/swift/tests/client/suite.mustache index 3b42e5feea..08cea367ba 100644 --- a/templates/swift/tests/client/suite.mustache +++ b/templates/swift/tests/client/suite.mustache @@ -10,8 +10,8 @@ import Utils final class {{client}}ClientTests: XCTestCase { - let APPLICATION_ID = "" - let API_KEY = "" + let APPLICATION_ID = "my_application_id" + let API_KEY = "my_api_key" {{#blocksClient}} {{#tests}} @@ -20,9 +20,8 @@ final class {{client}}ClientTests: XCTestCase { */ func test{{#lambda.titlecase}}{{testType}}{{/lambda.titlecase}}Test{{testIndex}}() async throws { {{#autoCreateClient}} - let statusCode: HTTPStatusСode = 200 - let configuration: {{import}}.Configuration = try {{import}}.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) - let transporter: Transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder(statusCode: statusCode)) + let configuration: {{import}}.Configuration = try {{import}}.Configuration(appId: APPLICATION_ID, apiKey: API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) + let transporter: Transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) let client: {{client}} = {{client}}(configuration: configuration, transporter: transporter) {{/autoCreateClient}} @@ -31,7 +30,6 @@ final class {{client}}ClientTests: XCTestCase { do { {{#dynamicTemplate}}{{/dynamicTemplate}} - _ = client XCTFail("Expected an error to be thrown") } catch { XCTAssertEqual(error.localizedDescription, "{{{expectedError}}}") @@ -44,7 +42,7 @@ final class {{client}}ClientTests: XCTestCase { let pattern = "{{#lambda.escapeSlash}}{{{match}}}{{/lambda.escapeSlash}}" let rule = StringRule(pattern: pattern) - let userAgent = try XCTUnwrap(echoResponse.headers?["user-agent"]) + let userAgent = try XCTUnwrap(echoResponse.headers?["User-Agent"]) guard let userAgent = userAgent else { XCTFail("Expected user-agent header") return @@ -58,7 +56,7 @@ final class {{client}}ClientTests: XCTestCase { XCTAssertEqual(TimeInterval({{{match.parametersWithDataTypeMap.responseTimeout.value}}} / 1000), echoResponse.timeout); {{/testTimeouts}} {{#testHost}} - XCTAssertEqual("{{{match}}}", echoResponse.url); + XCTAssertEqual("{{{match}}}", echoResponse.host); {{/testHost}} {{/match}} {{/isError}} diff --git a/templates/swift/tests/paramValue.mustache b/templates/swift/tests/paramValue.mustache index 689b7a1d0a..b29b0e0ac4 100644 --- a/templates/swift/tests/paramValue.mustache +++ b/templates/swift/tests/paramValue.mustache @@ -1 +1 @@ -{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}""{{/isNull}} \ No newline at end of file +{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{^value}}:{{/value}}{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}{{#inClientTest}}{{{objectName}}}(){{/inClientTest}}{{/isNull}} \ No newline at end of file diff --git a/templates/swift/tests/requests/requests.mustache b/templates/swift/tests/requests/requests.mustache index f319f59179..bc3d053e90 100644 --- a/templates/swift/tests/requests/requests.mustache +++ b/templates/swift/tests/requests/requests.mustache @@ -10,10 +10,8 @@ import Utils final class {{client}}RequestsTests: XCTestCase { - typealias StringMapObject = [String: String?] - - let APPLICATION_ID = "" - let API_KEY = "" + let APPLICATION_ID = "my_application_id" + let API_KEY = "my_api_key" {{#blocksRequests}} {{#tests}} @@ -21,7 +19,7 @@ final class {{client}}RequestsTests: XCTestCase { {{testName}} */ func test{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}Test{{testIndex}}() async throws { - let configuration: {{import}}.Configuration = try {{import}}.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) + let configuration: {{import}}.Configuration = try {{import}}.Configuration(appId: APPLICATION_ID, apiKey: API_KEY{{#hasRegionalHost}}, region: Region.{{defaultRegion}}{{/hasRegionalHost}}) let transporter: Transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) let client: {{client}} = {{client}}(configuration: configuration, transporter: transporter) diff --git a/tests/output/swift/Tests/Utils/Data.swift b/tests/output/swift/Tests/Utils/Utils.swift similarity index 62% rename from tests/output/swift/Tests/Utils/Data.swift rename to tests/output/swift/Tests/Utils/Utils.swift index e3390d85d9..911c14280d 100644 --- a/tests/output/swift/Tests/Utils/Data.swift +++ b/tests/output/swift/Tests/Utils/Utils.swift @@ -1,11 +1,22 @@ // -// Data.swift +// Utils.swift // // // Created by Algolia on 26/01/2024. // import Foundation +#if canImport(AnyCodable) + import AnyCodable +#endif + +#if canImport(AnyCodable) + public typealias Object = [String: AnyCodable] +#else + public typealias Object = [String: Any] +#endif + +public typealias StringMapObject = [String: String?] public extension Data { var jsonString: String? { From b506c00f873223720a09b86aeda1390f28a0ed2c Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Mon, 29 Jan 2024 15:57:04 +0100 Subject: [PATCH 5/7] fix(cts): only display error output in the test logs --- scripts/cts/runCts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cts/runCts.ts b/scripts/cts/runCts.ts index cc8646b457..7e9905ddf8 100644 --- a/scripts/cts/runCts.ts +++ b/scripts/cts/runCts.ts @@ -52,7 +52,7 @@ async function runCtsOne(language: string): Promise { await run('sbt test', { cwd, language }); break; case 'swift': - await run('swift test --parallel', { cwd, language }); + await run('swift test -q --parallel', { cwd, language }); break; default: spinner.warn(`skipping unknown language '${language}' to run the CTS`); From 4e7326c3256cc4dbe8a6702ad7a82edfcf4fdccb Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Mon, 29 Jan 2024 16:37:19 +0100 Subject: [PATCH 6/7] fix(cts): remove local build folder to mock CI env + import deps in Utils test folder --- scripts/cts/runCts.ts | 2 +- templates/swift/tests/Package.mustache | 8 +++++++- templates/swift/tests/paramValue.mustache | 2 +- tests/output/swift/Tests/Utils/Utils.swift | 6 ++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/cts/runCts.ts b/scripts/cts/runCts.ts index 7e9905ddf8..c1b1edc611 100644 --- a/scripts/cts/runCts.ts +++ b/scripts/cts/runCts.ts @@ -52,7 +52,7 @@ async function runCtsOne(language: string): Promise { await run('sbt test', { cwd, language }); break; case 'swift': - await run('swift test -q --parallel', { cwd, language }); + await run('rm -rf .build && swift test -q --parallel', { cwd, language }); break; default: spinner.warn(`skipping unknown language '${language}' to run the CTS`); diff --git a/templates/swift/tests/Package.mustache b/templates/swift/tests/Package.mustache index ff9e0cb1f6..1744d2766d 100644 --- a/templates/swift/tests/Package.mustache +++ b/templates/swift/tests/Package.mustache @@ -10,7 +10,13 @@ let package = Package( .package(path: "../../../clients/algoliasearch-client-swift"), ], targets: [ - .target(name: "Utils", path: "Tests/Utils"), + .target( + name: "Utils", + dependencies: [ + .product(name: "AnyCodable", package: "AnyCodable") + ], + path: "Tests/Utils" + ), .testTarget( name: "client", dependencies: [ diff --git a/templates/swift/tests/paramValue.mustache b/templates/swift/tests/paramValue.mustache index b29b0e0ac4..9afcd003cb 100644 --- a/templates/swift/tests/paramValue.mustache +++ b/templates/swift/tests/paramValue.mustache @@ -1 +1 @@ -{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{^value}}:{{/value}}{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}{{#inClientTest}}{{{objectName}}}(){{/inClientTest}}{{/isNull}} \ No newline at end of file +{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{^value}}:{{/value}}{{#value}}{{>tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}{{#inClientTest}}TestNull{{{objectName}}}(){{/inClientTest}}{{/isNull}} \ 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 911c14280d..3f939a0b80 100644 --- a/tests/output/swift/Tests/Utils/Utils.swift +++ b/tests/output/swift/Tests/Utils/Utils.swift @@ -11,11 +11,13 @@ import Foundation #endif #if canImport(AnyCodable) - public typealias Object = [String: AnyCodable] + public typealias TestNullObject = [String: AnyCodable] #else - public typealias Object = [String: Any] + public typealias TestNullObject = [String: Any] #endif +public typealias TestNullString = String + public typealias StringMapObject = [String: String?] public extension Data { From aa99adc983e06a3ef1c83c815dc004bc1a867796 Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Mon, 29 Jan 2024 18:15:12 +0100 Subject: [PATCH 7/7] chore: revert wrong commit --- .../Sources/Core/Helpers/Version.swift | 43 + tests/output/swift/Package.swift | 58 + .../swift/Tests/requests/AbtestingTests.swift | 687 ++++ .../swift/Tests/requests/AnalyticsTests.swift | 1360 ++++++++ .../swift/Tests/requests/IngestionTests.swift | 1388 ++++++++ .../swift/Tests/requests/InsightsTests.swift | 710 ++++ .../Tests/requests/MonitoringTests.swift | 735 ++++ .../Tests/requests/PersonalizationTests.swift | 642 ++++ .../requests/QuerySuggestionsTests.swift | 709 ++++ .../swift/Tests/requests/RecommendTests.swift | 831 +++++ .../swift/Tests/requests/SearchTests.swift | 2997 +++++++++++++++++ 11 files changed, 10160 insertions(+) create mode 100644 clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift create mode 100644 tests/output/swift/Package.swift create mode 100644 tests/output/swift/Tests/requests/AbtestingTests.swift create mode 100644 tests/output/swift/Tests/requests/AnalyticsTests.swift create mode 100644 tests/output/swift/Tests/requests/IngestionTests.swift create mode 100644 tests/output/swift/Tests/requests/InsightsTests.swift create mode 100644 tests/output/swift/Tests/requests/MonitoringTests.swift create mode 100644 tests/output/swift/Tests/requests/PersonalizationTests.swift create mode 100644 tests/output/swift/Tests/requests/QuerySuggestionsTests.swift create mode 100644 tests/output/swift/Tests/requests/RecommendTests.swift create mode 100644 tests/output/swift/Tests/requests/SearchTests.swift diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift new file mode 100644 index 0000000000..a8e53744f6 --- /dev/null +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Version.swift @@ -0,0 +1,43 @@ +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +public struct Version { + public let major: Int + public let minor: Int + public let patch: Int + public let prereleaseIdentifier: String? + + public init(major: Int, minor: Int, patch: Int = 0, prereleaseIdentifier: String? = nil) { + self.major = major + self.minor = minor + self.patch = patch + self.prereleaseIdentifier = prereleaseIdentifier + } + + public init(version: String) { + let components = version.components(separatedBy: ".") + + guard components.count >= 3 else { + fatalError("version is not formatted correctly") + } + + major = Int(components[0]) ?? 0 + minor = Int(components[1]) ?? 0 + patch = Int(components[2]) ?? 0 + prereleaseIdentifier = components.count == 4 ? components[3] : nil + } +} + +extension Version: CustomStringConvertible { + public var description: String { + let main = [major, minor, patch].map(String.init).joined(separator: ".") + if let prereleaseIdentifier = prereleaseIdentifier { + return main + "-\(prereleaseIdentifier)" + } else { + return main + } + } +} + +public extension Version { + static let current: Version = .init(version: "9.0.0-alpha.2") +} diff --git a/tests/output/swift/Package.swift b/tests/output/swift/Package.swift new file mode 100644 index 0000000000..7005e006e7 --- /dev/null +++ b/tests/output/swift/Package.swift @@ -0,0 +1,58 @@ +// swift-tools-version: 5.9 +// + +import PackageDescription + +let package = Package( + name: "AlgoliaSearchClientTests", + dependencies: [ + .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.1")), + .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"), + .package(path: "../../../clients/algoliasearch-client-swift"), + ], + targets: [ + .testTarget( + name: "requests", + dependencies: [ + .product(name: "AnyCodable", package: "AnyCodable"), + .product(name: "SwiftyJSON", package: "SwiftyJSON"), + .product( + name: "Abtesting", + package: "algoliasearch-client-swift" + ), + .product( + name: "Analytics", + package: "algoliasearch-client-swift" + ), + .product( + name: "Ingestion", + package: "algoliasearch-client-swift" + ), + .product( + name: "Insights", + package: "algoliasearch-client-swift" + ), + .product( + name: "Monitoring", + package: "algoliasearch-client-swift" + ), + .product( + name: "Personalization", + package: "algoliasearch-client-swift" + ), + .product( + name: "QuerySuggestions", + package: "algoliasearch-client-swift" + ), + .product( + name: "Recommend", + package: "algoliasearch-client-swift" + ), + .product( + name: "Search", + package: "algoliasearch-client-swift" + ), + ] + ) + ] +) \ No newline at end of file diff --git a/tests/output/swift/Tests/requests/AbtestingTests.swift b/tests/output/swift/Tests/requests/AbtestingTests.swift new file mode 100644 index 0000000000..9fc7cb5956 --- /dev/null +++ b/tests/output/swift/Tests/requests/AbtestingTests.swift @@ -0,0 +1,687 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Abtesting +@testable import Core + +final class AbtestingClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + addABTests with minimal parameters + */ + func testAddABTestsTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.addABTestsWithHTTPInfo(addABTestsRequest: AddABTestsRequest(name: "myABTest", variants: [AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_1", trafficPercentage: 30)), AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_2", trafficPercentage: 50))], endAt: "2022-12-31T00:00:00.000Z"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/2/abtests") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteABTest + */ + func testDeleteABTestTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteABTestWithHTTPInfo(id: 42, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/abtests/42") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getABTest + */ + func testGetABTestTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.getABTestWithHTTPInfo(id: 42, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/abtests/42") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listABTests with minimal parameters + */ + func testListABTestsTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.listABTestsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/abtests") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listABTests with parameters + */ + func testListABTestsTest1() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.listABTestsWithHTTPInfo(offset: 42, limit: 21, indexPrefix: "foo", indexSuffix: "bar", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/abtests") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"offset\":\"42\",\"limit\":\"21\",\"indexPrefix\":\"foo\",\"indexSuffix\":\"bar\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + stopABTest + */ + func testStopABTestTest0() async throws { + let configuration: Abtesting.Configuration = try Abtesting.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.stopABTestWithHTTPInfo(id: 42, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/2/abtests/42/stop") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/AnalyticsTests.swift b/tests/output/swift/Tests/requests/AnalyticsTests.swift new file mode 100644 index 0000000000..b7c1546646 --- /dev/null +++ b/tests/output/swift/Tests/requests/AnalyticsTests.swift @@ -0,0 +1,1360 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Analytics +@testable import Core + +final class AnalyticsClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getAverageClickPosition with minimal parameters + */ + func testGetAverageClickPositionTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getAverageClickPositionWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/averageClickPosition") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getAverageClickPosition with all parameters + */ + func testGetAverageClickPositionTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getAverageClickPositionWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/averageClickPosition") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getClickPositions with minimal parameters + */ + func testGetClickPositionsTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClickPositionsWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/positions") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getClickPositions with all parameters + */ + func testGetClickPositionsTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClickPositionsWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/positions") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getClickThroughRate with minimal parameters + */ + func testGetClickThroughRateTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClickThroughRateWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/clickThroughRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getClickThroughRate with all parameters + */ + func testGetClickThroughRateTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClickThroughRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/clicks/clickThroughRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getConversationRate with minimal parameters + */ + func testGetConversationRateTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getConversationRateWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/conversions/conversionRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getConversationRate with all parameters + */ + func testGetConversationRateTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getConversationRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/conversions/conversionRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getNoClickRate with minimal parameters + */ + func testGetNoClickRateTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getNoClickRateWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noClickRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getNoClickRate with all parameters + */ + func testGetNoClickRateTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getNoClickRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noClickRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getNoResultsRate with minimal parameters + */ + func testGetNoResultsRateTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getNoResultsRateWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noResultRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getNoResultsRate with all parameters + */ + func testGetNoResultsRateTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getNoResultsRateWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noResultRate") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesCount with minimal parameters + */ + func testGetSearchesCountTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesCountWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/count") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesCount with all parameters + */ + func testGetSearchesCountTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesCountWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/count") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesNoClicks with minimal parameters + */ + func testGetSearchesNoClicksTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesNoClicksWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noClicks") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesNoClicks with all parameters + */ + func testGetSearchesNoClicksTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesNoClicksWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noClicks") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesNoResults with minimal parameters + */ + func testGetSearchesNoResultsTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesNoResultsWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noResults") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getSearchesNoResults with all parameters + */ + func testGetSearchesNoResultsTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSearchesNoResultsWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches/noResults") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getStatus with minimal parameters + */ + func testGetStatusTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getStatusWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/status") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopCountries with minimal parameters + */ + func testGetTopCountriesTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopCountriesWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/countries") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopCountries with all parameters + */ + func testGetTopCountriesTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopCountriesWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/countries") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterAttributes with minimal parameters + */ + func testGetTopFilterAttributesTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterAttributesWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterAttributes with all parameters + */ + func testGetTopFilterAttributesTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterAttributesWithHTTPInfo(index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterForAttribute with minimal parameters + */ + func testGetTopFilterForAttributeTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute", index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterForAttribute with minimal parameters and multiple attributes + */ + func testGetTopFilterForAttributeTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute1,myAttribute2", index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute1%2CmyAttribute2") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterForAttribute with all parameters + */ + func testGetTopFilterForAttributeTest2() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute", index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFilterForAttribute with all parameters and multiple attributes + */ + func testGetTopFilterForAttributeTest3() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFilterForAttributeWithHTTPInfo(attribute: "myAttribute1,myAttribute2", index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/myAttribute1%2CmyAttribute2") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFiltersNoResults with minimal parameters + */ + func testGetTopFiltersNoResultsTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFiltersNoResultsWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/noResults") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopFiltersNoResults with all parameters + */ + func testGetTopFiltersNoResultsTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopFiltersNoResultsWithHTTPInfo(index: "index", search: "mySearch", startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/filters/noResults") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopHits with minimal parameters + */ + func testGetTopHitsTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopHitsWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/hits") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopHits with all parameters + */ + func testGetTopHitsTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopHitsWithHTTPInfo(index: "index", search: "mySearch", clickAnalytics: true, startDate: "1999-09-19", endDate: "2001-01-01", limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/hits") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"search\":\"mySearch\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopSearches with minimal parameters + */ + func testGetTopSearchesTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopSearchesWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getTopSearches with all parameters + */ + func testGetTopSearchesTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopSearchesWithHTTPInfo(index: "index", clickAnalytics: true, startDate: "1999-09-19", endDate: "2001-01-01", orderBy: OrderBy.searchCount, direction: Direction.asc, limit: 21, offset: 42, tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/searches") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"orderBy\":\"searchCount\",\"direction\":\"asc\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getUsersCount with minimal parameters + */ + func testGetUsersCountTest0() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getUsersCountWithHTTPInfo(index: "index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/users/count") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + get getUsersCount with all parameters + */ + func testGetUsersCountTest1() async throws { + let configuration: Analytics.Configuration = try Analytics.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AnalyticsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getUsersCountWithHTTPInfo(index: "index", startDate: "1999-09-19", endDate: "2001-01-01", tags: "tag", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/2/users/count") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } +} diff --git a/tests/output/swift/Tests/requests/IngestionTests.swift b/tests/output/swift/Tests/requests/IngestionTests.swift new file mode 100644 index 0000000000..f254f61f18 --- /dev/null +++ b/tests/output/swift/Tests/requests/IngestionTests.swift @@ -0,0 +1,1388 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Ingestion + +final class IngestionClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + createAuthenticationOAuth + */ + func testCreateAuthenticationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createAuthenticationWithHTTPInfo(authenticationCreate: AuthenticationCreate(type: AuthenticationType.oauth, name: "authName", input: AuthInput.authOAuth(AuthOAuth(url: "http://test.oauth", clientId: "myID", clientSecret: "mySecret"))), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"type\":\"oauth\",\"name\":\"authName\",\"input\":{\"url\":\"http://test.oauth\",\"client_id\":\"myID\",\"client_secret\":\"mySecret\"}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/authentications") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createAuthenticationAlgolia + */ + func testCreateAuthenticationTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createAuthenticationWithHTTPInfo(authenticationCreate: AuthenticationCreate(type: AuthenticationType.algolia, name: "authName", input: AuthInput.authAlgolia(AuthAlgolia(appID: "myappID", apiKey: "randomApiKey"))), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"type\":\"algolia\",\"name\":\"authName\",\"input\":{\"appID\":\"myappID\",\"apiKey\":\"randomApiKey\"}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/authentications") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createDestination + */ + func testCreateDestinationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createDestinationWithHTTPInfo(destinationCreate: DestinationCreate(type: DestinationType.search, name: "destinationName", input: DestinationInput.destinationIndexPrefix(DestinationIndexPrefix(indexPrefix: "prefix_")), authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"type\":\"search\",\"name\":\"destinationName\",\"input\":{\"indexPrefix\":\"prefix_\"},\"authenticationID\":\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/destinations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createSource + */ + func testCreateSourceTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createSourceWithHTTPInfo(sourceCreate: SourceCreate(type: SourceType.commercetools, name: "sourceName", input: SourceInput.sourceCommercetools(SourceCommercetools(storeKeys: ["myStore"], locales: ["de"], url: "http://commercetools.com", projectKey: "keyID")), authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"type\":\"commercetools\",\"name\":\"sourceName\",\"input\":{\"storeKeys\":[\"myStore\"],\"locales\":[\"de\"],\"url\":\"http://commercetools.com\",\"projectKey\":\"keyID\"},\"authenticationID\":\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/sources") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createTaskOnDemand + */ + func testCreateTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.onDemandTriggerInput(OnDemandTriggerInput(type: OnDemandTriggerType.onDemand)), action: ActionType.replace), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"onDemand\"},\"action\":\"replace\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/tasks") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createTaskSchedule + */ + func testCreateTaskTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.scheduleTriggerInput(ScheduleTriggerInput(type: ScheduleTriggerType.schedule, cron: "* * * * *")), action: ActionType.replace), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"schedule\",\"cron\":\"* * * * *\"},\"action\":\"replace\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/tasks") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + createTaskSubscription + */ + func testCreateTaskTest2() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.createTaskWithHTTPInfo(taskCreate: TaskCreate(sourceID: "search", destinationID: "destinationName", trigger: TaskCreateTrigger.onDemandTriggerInput(OnDemandTriggerInput(type: OnDemandTriggerType.onDemand)), action: ActionType.replace), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"sourceID\":\"search\",\"destinationID\":\"destinationName\",\"trigger\":{\"type\":\"onDemand\"},\"action\":\"replace\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/tasks") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteAuthentication + */ + func testDeleteAuthenticationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteDestination + */ + func testDeleteDestinationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteSource + */ + func testDeleteSourceTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteTask + */ + func testDeleteTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + disableTask + */ + func testDisableTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.disableTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/disable") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + enableTask + */ + func testEnableTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.enableTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/enable") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getAuthentication + */ + func testGetAuthenticationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getAuthentications + */ + func testGetAuthenticationsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getAuthenticationsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/authentications") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getDestination + */ + func testGetDestinationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getDestinations + */ + func testGetDestinationsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getDestinationsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/destinations") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getDockerSourceStreams + */ + func testGetDockerSourceStreamsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getDockerSourceStreamsWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getEvent + */ + func testGetEventTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getEventWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", eventID: "6c02aeb1-775e-418e-870b-1faccd4b2c0c", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events/6c02aeb1-775e-418e-870b-1faccd4b2c0c") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getEvents + */ + func testGetEventsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getEventsWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getRun + */ + func testGetRunTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRunWithHTTPInfo(runID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getRuns + */ + func testGetRunsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRunsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/runs") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getSource + */ + func testGetSourceTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getSources + */ + func testGetSourcesTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSourcesWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/sources") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getTask + */ + func testGetTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getTasks + */ + func testGetTasksTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTasksWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/tasks") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + runTask + */ + func testRunTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.runTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/run") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchAuthentications + */ + func testSearchAuthenticationsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchAuthenticationsWithHTTPInfo(authenticationSearch: AuthenticationSearch(authenticationIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"authenticationIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/authentications/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchDestinations + */ + func testSearchDestinationsTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchDestinationsWithHTTPInfo(destinationSearch: DestinationSearch(destinationIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"destinationIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/destinations/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchSources + */ + func testSearchSourcesTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSourcesWithHTTPInfo(sourceSearch: SourceSearch(sourceIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"sourceIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/sources/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchTasks + */ + func testSearchTasksTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchTasksWithHTTPInfo(taskSearch: TaskSearch(taskIDs: ["6c02aeb1-775e-418e-870b-1faccd4b2c0f", "947ac9c4-7e58-4c87-b1e7-14a68e99699a"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"taskIDs\":[\"6c02aeb1-775e-418e-870b-1faccd4b2c0f\",\"947ac9c4-7e58-4c87-b1e7-14a68e99699a\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/tasks/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + triggerDockerSourceDiscover + */ + func testTriggerDockerSourceDiscoverTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.triggerDockerSourceDiscoverWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateAuthentication + */ + func testUpdateAuthenticationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateAuthenticationWithHTTPInfo(authenticationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", authenticationUpdate: AuthenticationUpdate(name: "newName"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"name\":\"newName\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.patch) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateDestination + */ + func testUpdateDestinationTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateDestinationWithHTTPInfo(destinationID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", destinationUpdate: DestinationUpdate(name: "newName"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"name\":\"newName\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.patch) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateSource + */ + func testUpdateSourceTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateSourceWithHTTPInfo(sourceID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", sourceUpdate: SourceUpdate(name: "newName"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"name\":\"newName\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.patch) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateTask + */ + func testUpdateTaskTest0() async throws { + let configuration: Ingestion.Configuration = try Ingestion.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = IngestionClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateTaskWithHTTPInfo(taskID: "6c02aeb1-775e-418e-870b-1faccd4b2c0f", taskUpdate: TaskUpdate(enabled: false), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"enabled\":false}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") + XCTAssertEqual(echoResponse.method, HTTPMethod.patch) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/InsightsTests.swift b/tests/output/swift/Tests/requests/InsightsTests.swift new file mode 100644 index 0000000000..2e8a9b1cff --- /dev/null +++ b/tests/output/swift/Tests/requests/InsightsTests.swift @@ -0,0 +1,710 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Insights + +final class InsightsClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteUserToken0 + */ + func testDeleteUserTokenTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteUserTokenWithHTTPInfo(userToken: "test-user-1", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/usertokens/test-user-1") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + pushEvents0 + */ + func testPushEventsTest0() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.clickedObjectIDsAfterSearch(ClickedObjectIDsAfterSearch(eventName: "Product Clicked", eventType: ClickEvent.click, index: "products", objectIDs: ["9780545139700", "9780439784542"], positions: [7, 6], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"events\":[{\"eventType\":\"click\",\"eventName\":\"Product Clicked\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"positions\":[7,6]}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + Many events type + */ + func testPushEventsTest1() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.convertedObjectIDsAfterSearch(ConvertedObjectIDsAfterSearch(eventName: "Product Purchased", eventType: ConversionEvent.conversion, index: "products", objectIDs: ["9780545139700", "9780439784542"], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962))), EventsItems.viewedObjectIDs(ViewedObjectIDs(eventName: "Product Detail Page Viewed", eventType: ViewEvent.view, index: "products", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + ConvertedObjectIDsAfterSearch + */ + func testPushEventsTest2() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.convertedObjectIDsAfterSearch(ConvertedObjectIDsAfterSearch(eventName: "Product Purchased", eventType: ConversionEvent.conversion, index: "products", objectIDs: ["9780545139700", "9780439784542"], queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + ViewedObjectIDs + */ + func testPushEventsTest3() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.viewedObjectIDs(ViewedObjectIDs(eventName: "Product Detail Page Viewed", eventType: ViewEvent.view, index: "products", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"events\":[{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + AddedToCartObjectIDs + */ + func testPushEventsTest4() async throws { + let configuration: Insights.Configuration = try Insights.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = InsightsClient(configuration: configuration, transporter: transporter) + + let response = try await client.pushEventsWithHTTPInfo(insightsEvents: InsightsEvents(events: [EventsItems.addedToCartObjectIDsAfterSearch(AddedToCartObjectIDsAfterSearch(eventName: "Product Added To Cart", eventType: ConversionEvent.conversion, eventSubtype: AddToCartEvent.addToCart, index: "products", queryID: "43b15df305339e827f0ac0bdc5ebcaa7", objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", currency: "USD", objectData: [ObjectDataAfterSearch(price: Price.double(19.99), quantity: 10, discount: Discount.double(2.5)), ObjectDataAfterSearch(price: Price.string("8$"), quantity: 7, discount: Discount.string("30%"))], timestamp: Int64(1_641_290_601_962)))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"events\":[{\"eventType\":\"conversion\",\"eventSubtype\":\"addToCart\",\"eventName\":\"Product Added To Cart\",\"index\":\"products\",\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"objectData\":[{\"price\":19.99,\"quantity\":10,\"discount\":2.5},{\"price\":\"8$\",\"quantity\":7,\"discount\":\"30%\"}],\"currency\":\"USD\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/events") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/MonitoringTests.swift b/tests/output/swift/Tests/requests/MonitoringTests.swift new file mode 100644 index 0000000000..063963b5f4 --- /dev/null +++ b/tests/output/swift/Tests/requests/MonitoringTests.swift @@ -0,0 +1,735 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Monitoring + +final class MonitoringClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + getClusterIncidents + */ + func testGetClusterIncidentsTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClusterIncidentsWithHTTPInfo(clusters: "c1-de", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/incidents/c1-de") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getClusterStatus + */ + func testGetClusterStatusTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getClusterStatusWithHTTPInfo(clusters: "c1-de", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/status/c1-de") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getIncidents + */ + func testGetIncidentsTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getIncidentsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/incidents") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getIndexingTime + */ + func testGetIndexingTimeTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getIndexingTimeWithHTTPInfo(clusters: "c1-de", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexing/c1-de") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getInventory + */ + func testGetInventoryTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getInventoryWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/inventory/servers") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getLatency + */ + func testGetLatencyTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getLatencyWithHTTPInfo(clusters: "c1-de", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/latency/c1-de") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getMetrics + */ + func testGetMetricsTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getMetricsWithHTTPInfo(metric: Metric.avgBuildTime, period: Period.minute, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/infrastructure/avg_build_time/period/minute") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getReachability + */ + func testGetReachabilityTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getReachabilityWithHTTPInfo(clusters: "c1-de", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/reachability/c1-de/probes") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getStatus + */ + func testGetStatusTest0() async throws { + let configuration: Monitoring.Configuration = try Monitoring.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = MonitoringClient(configuration: configuration, transporter: transporter) + + let response = try await client.getStatusWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/status") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/PersonalizationTests.swift b/tests/output/swift/Tests/requests/PersonalizationTests.swift new file mode 100644 index 0000000000..a0b72ddd14 --- /dev/null +++ b/tests/output/swift/Tests/requests/PersonalizationTests.swift @@ -0,0 +1,642 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Personalization + +final class PersonalizationClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + delete deleteUserProfile + */ + func testDeleteUserProfileTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteUserProfileWithHTTPInfo(userToken: "UserToken", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/profiles/UserToken") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get getPersonalizationStrategy + */ + func testGetPersonalizationStrategyTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.getPersonalizationStrategyWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/strategies/personalization") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get getUserTokenProfile + */ + func testGetUserTokenProfileTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.getUserTokenProfileWithHTTPInfo(userToken: "UserToken", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/profiles/personalization/UserToken") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + set setPersonalizationStrategy + */ + func testSetPersonalizationStrategyTest0() async throws { + let configuration: Personalization.Configuration = try Personalization.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = PersonalizationClient(configuration: configuration, transporter: transporter) + + let response = try await client.setPersonalizationStrategyWithHTTPInfo(personalizationStrategyParams: PersonalizationStrategyParams(eventScoring: [EventScoring(score: 42, eventName: "Algolia", eventType: "Event")], facetScoring: [FacetScoring(score: 42, facetName: "Event")], personalizationImpact: 42), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"eventScoring\":[{\"score\":42,\"eventName\":\"Algolia\",\"eventType\":\"Event\"}],\"facetScoring\":[{\"score\":42,\"facetName\":\"Event\"}],\"personalizationImpact\":42}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/strategies/personalization") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift b/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift new file mode 100644 index 0000000000..2e8b464ee8 --- /dev/null +++ b/tests/output/swift/Tests/requests/QuerySuggestionsTests.swift @@ -0,0 +1,709 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import QuerySuggestions + +final class QuerySuggestionsClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + createConfig0 + */ + func testCreateConfigTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.createConfigWithHTTPInfo(querySuggestionsConfigurationWithIndex: QuerySuggestionsConfigurationWithIndex(indexName: "theIndexName", sourceIndices: [SourceIndex(indexName: "testIndex", facets: [Facet(attribute: "test")], generate: [["facetA", "facetB"], ["facetC"]])], languages: Languages.arrayOfString(["french"]), exclude: ["test"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"indexName\":\"theIndexName\",\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attribute\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/configs") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteConfig0 + */ + func testDeleteConfigTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteConfigWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getAllConfigs0 + */ + func testGetAllConfigsTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getAllConfigsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/configs") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getConfig0 + */ + func testGetConfigTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getConfigWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getConfigStatus0 + */ + func testGetConfigStatusTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getConfigStatusWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName/status") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getLogFile0 + */ + func testGetLogFileTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.getLogFileWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/logs/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateConfig0 + */ + func testUpdateConfigTest0() async throws { + let configuration: QuerySuggestions.Configuration = try QuerySuggestions.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY, region: Region.us) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = QuerySuggestionsClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateConfigWithHTTPInfo(indexName: "theIndexName", querySuggestionsConfiguration: QuerySuggestionsConfiguration(sourceIndices: [SourceIndex(indexName: "testIndex", facets: [Facet(attribute: "test")], generate: [["facetA", "facetB"], ["facetC"]])], languages: Languages.arrayOfString(["french"]), exclude: ["test"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attribute\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/configs/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/RecommendTests.swift b/tests/output/swift/Tests/requests/RecommendTests.swift new file mode 100644 index 0000000000..fa08eec4f7 --- /dev/null +++ b/tests/output/swift/Tests/requests/RecommendTests.swift @@ -0,0 +1,831 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Recommend + +final class RecommendClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteRecommendRule0 + */ + func testDeleteRecommendRuleTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteRecommendRuleWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, objectID: "objectID", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/objectID") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getRecommendRule0 + */ + func testGetRecommendRuleTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendRuleWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, objectID: "objectID", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/objectID") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getRecommendStatus0 + */ + func testGetRecommendStatusTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendStatusWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, taskID: Int64(12345), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/task/12345") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get recommendations for recommend model with minimal parameters + */ + func testGetRecommendationsTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName", threshold: 42, model: RecommendationModels.relatedProducts, objectID: "objectID"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get recommendations for recommend model with all parameters + */ + func testGetRecommendationsTest1() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName", threshold: 42, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback")]))))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get recommendations for trending model with minimal parameters + */ + func testGetRecommendationsTest2() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.trendingItemsQuery(TrendingItemsQuery(indexName: "indexName", threshold: 42, model: TrendingItemsModel.trendingItems))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get recommendations for trending model with all parameters + */ + func testGetRecommendationsTest3() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.trendingItemsQuery(TrendingItemsQuery(indexName: "indexName", threshold: 42, maxRecommendations: 10, facetName: "myFacetName", facetValue: "myFacetValue", model: TrendingItemsModel.trendingItems, queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback")]))))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42,\"maxRecommendations\":10,\"facetName\":\"myFacetName\",\"facetValue\":\"myFacetValue\",\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get multiple recommendations with minimal parameters + */ + func testGetRecommendationsTest4() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 21, model: RecommendationModels.relatedProducts, objectID: "objectID1")), RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName2", threshold: 21, model: RecommendationModels.relatedProducts, objectID: "objectID2"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get multiple recommendations with all parameters + */ + func testGetRecommendationsTest5() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 21, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID1", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query1")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback1")])))), RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName2", threshold: 21, maxRecommendations: 10, model: RecommendationModels.relatedProducts, objectID: "objectID2", queryParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("query2")])), fallbackParameters: SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("fallback2")]))))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query1\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback1\"]}},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query2\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback2\"]}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get frequently bought together recommendations + */ + func testGetRecommendationsTest6() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRecommendationsWithHTTPInfo(getRecommendationsParams: GetRecommendationsParams(requests: [RecommendationsRequest.recommendationsQuery(RecommendationsQuery(indexName: "indexName1", threshold: 42, model: RecommendationModels.boughtTogether, objectID: "objectID1"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"bought-together\",\"threshold\":42}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/recommendations") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchRecommendRules0 + */ + func testSearchRecommendRulesTest0() async throws { + let configuration: Recommend.Configuration = try Recommend.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = RecommendClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchRecommendRulesWithHTTPInfo(indexName: "indexName", model: RecommendModels.relatedProducts, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/related-products/recommend/rules/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } +} diff --git a/tests/output/swift/Tests/requests/SearchTests.swift b/tests/output/swift/Tests/requests/SearchTests.swift new file mode 100644 index 0000000000..740dc6c0bd --- /dev/null +++ b/tests/output/swift/Tests/requests/SearchTests.swift @@ -0,0 +1,2997 @@ +import SwiftyJSON +import XCTest +#if canImport(AnyCodable) + import AnyCodable +#endif + +@testable import Core +@testable import Search + +final class SearchClientRequestsTests: XCTestCase { + typealias StringMapObject = [String: String?] + + let APPLICATION_ID = "" + let API_KEY = "" + + /** + addApiKey0 + */ + func testAddApiKeyTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.addApiKeyWithHTTPInfo(apiKey: ApiKey(acl: [Acl.search, Acl.addObject], description: "my new api key", maxHitsPerQuery: 20, maxQueriesPerIPPerHour: 100, validity: 300), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"acl\":[\"search\",\"addObject\"],\"description\":\"my new api key\",\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/keys") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + addOrUpdateObject0 + */ + func testAddOrUpdateObjectTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.addOrUpdateObjectWithHTTPInfo(indexName: "indexName", objectID: "uniqueID", body: ["key": "value"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"key\":\"value\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/uniqueID") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + appendSource0 + */ + func testAppendSourceTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.appendSourceWithHTTPInfo(source: Source(source: "theSource", description: "theDescription"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"source\":\"theSource\",\"description\":\"theDescription\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/security/sources/append") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + assignUserId0 + */ + func testAssignUserIdTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.assignUserIdWithHTTPInfo(xAlgoliaUserID: "userID", assignUserIdParams: AssignUserIdParams(cluster: "theCluster"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"cluster\":\"theCluster\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-user-id\":\"userID\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + allows batch method with `addObject` action + */ + func testBatchTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.addObject, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"addObject\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `clear` action + */ + func testBatchTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.clear, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"clear\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `delete` action + */ + func testBatchTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.delete, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"delete\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `deleteObject` action + */ + func testBatchTest3() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.deleteObject, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"deleteObject\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `partialUpdateObject` action + */ + func testBatchTest4() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.partialUpdateObject, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"partialUpdateObject\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `partialUpdateObjectNoCreate` action + */ + func testBatchTest5() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.partialUpdateObjectNoCreate, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"partialUpdateObjectNoCreate\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allows batch method with `updateObject` action + */ + func testBatchTest6() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchWithHTTPInfo(indexName: "theIndexName", batchWriteParams: BatchWriteParams(requests: [BatchRequest(action: Action.updateObject, body: ["key": "value"])]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"updateObject\",\"body\":{\"key\":\"value\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + batchAssignUserIds0 + */ + func testBatchAssignUserIdsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchAssignUserIdsWithHTTPInfo(xAlgoliaUserID: "userID", batchAssignUserIdsParams: BatchAssignUserIdsParams(cluster: "theCluster", users: ["user1", "user2"]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"cluster\":\"theCluster\",\"users\":[\"user1\",\"user2\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-user-id\":\"userID\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + get batchDictionaryEntries results with minimal parameters + */ + func testBatchDictionaryEntriesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(objectID: "1", language: "en")), BatchDictionaryEntriesRequest(action: DictionaryAction.deleteEntry, body: DictionaryEntry(objectID: "2", language: "fr"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get batchDictionaryEntries results with all parameters + */ + func testBatchDictionaryEntriesTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(clearExistingDictionaryEntries: false, requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(objectID: "1", language: "en", word: "fancy", words: ["believe", "algolia"], decomposition: ["trust", "algolia"], state: DictionaryEntryState.enabled)), BatchDictionaryEntriesRequest(action: DictionaryAction.deleteEntry, body: DictionaryEntry(objectID: "2", language: "fr", word: "humility", words: ["candor", "algolia"], decomposition: ["grit", "algolia"], state: DictionaryEntryState.enabled))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"clearExistingDictionaryEntries\":false,\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\",\"word\":\"fancy\",\"words\":[\"believe\",\"algolia\"],\"decomposition\":[\"trust\",\"algolia\"],\"state\":\"enabled\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\",\"word\":\"humility\",\"words\":[\"candor\",\"algolia\"],\"decomposition\":[\"grit\",\"algolia\"],\"state\":\"enabled\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get batchDictionaryEntries results additional properties + */ + func testBatchDictionaryEntriesTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.batchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, batchDictionaryEntriesParams: BatchDictionaryEntriesParams(requests: [BatchDictionaryEntriesRequest(action: DictionaryAction.addEntry, body: DictionaryEntry(from: ["objectID": "1", "language": "en", "additional": "try me"]))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\",\"additional\":\"try me\"}}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + browse with minimal parameters + */ + func testBrowseTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.browseWithHTTPInfo(indexName: "cts_e2e_browse", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_browse/browse") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + browse with search parameters + */ + func testBrowseTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.browseWithHTTPInfo(indexName: "indexName", browseParams: BrowseParams.browseParamsObject(BrowseParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("tags:algolia")]))), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/browse") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + browse allow a cursor in parameters + */ + func testBrowseTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.browseWithHTTPInfo(indexName: "indexName", browseParams: BrowseParams.browseParamsObject(BrowseParamsObject(cursor: "test")), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"cursor\":\"test\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/browse") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + clearObjects0 + */ + func testClearObjectsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.clearObjectsWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/clear") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + clearRules0 + */ + func testClearRulesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.clearRulesWithHTTPInfo(indexName: "indexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/clear") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + clearSynonyms0 + */ + func testClearSynonymsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.clearSynonymsWithHTTPInfo(indexName: "indexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/clear") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with minimal parameters + */ + func testCustomDeleteTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow del method for a custom path with all parameters + */ + func testCustomDeleteTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customDeleteWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow get method for a custom path with minimal parameters + */ + func testCustomGetTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow get method for a custom path with all parameters + */ + func testCustomGetTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customGetWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow post method for a custom path with minimal parameters + */ + func testCustomPostTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow post method for a custom path with all parameters + */ + func testCustomPostTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPostWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default query parameters + */ + func testCustomPostTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions merges query parameters with default ones + */ + func testCustomPostTest3() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "query2": "myQueryParameter", + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"query2\":\"myQueryParameter\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions can override default headers + */ + func testCustomPostTest4() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions merges headers with default ones + */ + func testCustomPostTest5() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + headers: [ + "x-algolia-api-key": "myApiKey", + ] + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + + let comparableHeaders = try XCTUnwrap("{\"x-algolia-api-key\":\"myApiKey\"}".data(using: .utf8)) + let comparableHeadersMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableHeaders) + + let echoResponseHeaders = try XCTUnwrap(echoResponse.headers) + for header in comparableHeadersMap { + XCTAssertEqual(echoResponseHeaders[header.key], header.value) + } + } + + /** + requestOptions queryParameters accepts booleans + */ + func testCustomPostTest6() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "isItWorking": true, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"isItWorking\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts integers + */ + func testCustomPostTest7() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": 2, + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of string + */ + func testCustomPostTest8() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": ["c", "d"], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"c,d\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of booleans + */ + func testCustomPostTest9() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [true, true, false], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"true,true,false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + requestOptions queryParameters accepts list of integers + */ + func testCustomPostTest10() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let requestOptions = RequestOptions( + queryItems: APIHelper.mapValuesToQueryItems([ + "myParam": [1, 2], + ]) + ) + + let response = try await client.customPostWithHTTPInfo(path: "/test/requestOptions", parameters: ["query": AnyCodable("parameters")], body: ["facet": "filters"], requestOptions: requestOptions) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"facet\":\"filters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/requestOptions") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\",\"myParam\":\"1,2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + allow put method for a custom path with minimal parameters + */ + func testCustomPutTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/minimal", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/minimal") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + allow put method for a custom path with all parameters + */ + func testCustomPutTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.customPutWithHTTPInfo(path: "/test/all", parameters: ["query": AnyCodable("parameters")], body: ["body": "parameters"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"body\":\"parameters\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/test/all") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"query\":\"parameters\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + deleteApiKey0 + */ + func testDeleteApiKeyTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteApiKeyWithHTTPInfo(key: "myTestApiKey", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/keys/myTestApiKey") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteBy0 + */ + func testDeleteByTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteByWithHTTPInfo(indexName: "theIndexName", deleteByParams: DeleteByParams(filters: "brand:brandName"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"filters\":\"brand:brandName\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/deleteByQuery") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteIndex0 + */ + func testDeleteIndexTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteIndexWithHTTPInfo(indexName: "theIndexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteObject0 + */ + func testDeleteObjectTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + delete rule simple case + */ + func testDeleteRuleTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + delete rule with simple characters to encode in objectID + */ + func testDeleteRuleTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteRuleWithHTTPInfo(indexName: "indexName", objectID: "test/with/slash", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/test%2Fwith%2Fslash") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteSource0 + */ + func testDeleteSourceTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteSourceWithHTTPInfo(source: "theSource", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/security/sources/theSource") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + deleteSynonym0 + */ + func testDeleteSynonymTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.deleteSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getApiKey0 + */ + func testGetApiKeyTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getApiKeyWithHTTPInfo(key: "myTestApiKey", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/keys/myTestApiKey") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get getDictionaryLanguages + */ + func testGetDictionaryLanguagesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getDictionaryLanguagesWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/languages") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get getDictionarySettings results + */ + func testGetDictionarySettingsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getDictionarySettingsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getLogs with minimal parameters + */ + func testGetLogsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getLogsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/logs") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getLogs with parameters + */ + func testGetLogsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getLogsWithHTTPInfo(offset: 5, length: 10, indexName: "theIndexName", type: LogType.all, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/logs") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + getObject0 + */ + func testGetObjectTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", attributesToRetrieve: ["attr1", "attr2"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"attributesToRetrieve\":\"attr1,attr2\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + getObjects0 + */ + func testGetObjectsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getObjectsWithHTTPInfo(getObjectsParams: GetObjectsParams(requests: [GetObjectsRequest(attributesToRetrieve: ["attr1", "attr2"], objectID: "uniqueID", indexName: "theIndexName")]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"attributesToRetrieve\":[\"attr1\",\"attr2\"],\"objectID\":\"uniqueID\",\"indexName\":\"theIndexName\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/objects") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getRule0 + */ + func testGetRuleTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getSettings0 + */ + func testGetSettingsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSettingsWithHTTPInfo(indexName: "cts_e2e_settings", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_settings/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getSources0 + */ + func testGetSourcesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSourcesWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/security/sources") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getSynonym0 + */ + func testGetSynonymTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getTask0 + */ + func testGetTaskTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTaskWithHTTPInfo(indexName: "theIndexName", taskID: Int64(123), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/task/123") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getTopUserIds0 + */ + func testGetTopUserIdsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getTopUserIdsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/top") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + getUserId0 + */ + func testGetUserIdTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.getUserIdWithHTTPInfo(userID: "uniqueID", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/uniqueID") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + hasPendingMappings with minimal parameters + */ + func testHasPendingMappingsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.hasPendingMappingsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/pending") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + hasPendingMappings with parameters + */ + func testHasPendingMappingsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.hasPendingMappingsWithHTTPInfo(getClusters: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/pending") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"getClusters\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + listApiKeys0 + */ + func testListApiKeysTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listApiKeysWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/keys") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listClusters0 + */ + func testListClustersTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listClustersWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listIndices with minimal parameters + */ + func testListIndicesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listIndicesWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listIndices with parameters + */ + func testListIndicesTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listIndicesWithHTTPInfo(page: 8, hitsPerPage: 3, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/indexes") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"page\":\"8\",\"hitsPerPage\":\"3\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + listUserIds with minimal parameters + */ + func testListUserIdsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listUserIdsWithHTTPInfo(requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + listUserIds with parameters + */ + func testListUserIdsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.listUserIdsWithHTTPInfo(page: 8, hitsPerPage: 100, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping") + XCTAssertEqual(echoResponse.method, HTTPMethod.get) + + let comparableQueryItems = try XCTUnwrap("{\"page\":\"8\",\"hitsPerPage\":\"100\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + multipleBatch0 + */ + func testMultipleBatchTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.multipleBatchWithHTTPInfo(batchParams: BatchParams(requests: [MultipleBatchRequest(action: Action.addObject, body: ["key": "value"], indexName: "theIndexName")]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"action\":\"addObject\",\"body\":{\"key\":\"value\"},\"indexName\":\"theIndexName\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + operationIndex0 + */ + func testOperationIndexTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.operationIndexWithHTTPInfo(indexName: "theIndexName", operationIndexParams: OperationIndexParams(operation: OperationType.copy, destination: "dest", scope: [ScopeType.rules, ScopeType.settings]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"operation\":\"copy\",\"destination\":\"dest\",\"scope\":[\"rules\",\"settings\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/operation") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + partialUpdateObject0 + */ + func testPartialUpdateObjectTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.partialUpdateObjectWithHTTPInfo(indexName: "theIndexName", objectID: "uniqueID", attributesToUpdate: ["id1": AttributeToUpdate.string("test"), "id2": AttributeToUpdate.builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: "test2"))], createIfNotExists: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"id1\":\"test\",\"id2\":{\"_operation\":\"AddUnique\",\"value\":\"test2\"}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID/partial") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"createIfNotExists\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + removeUserId0 + */ + func testRemoveUserIdTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.removeUserIdWithHTTPInfo(userID: "uniqueID", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + XCTAssertNil(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/uniqueID") + XCTAssertEqual(echoResponse.method, HTTPMethod.delete) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + replaceSources0 + */ + func testReplaceSourcesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.replaceSourcesWithHTTPInfo(source: [Source(source: "theSource", description: "theDescription")], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "[{\"source\":\"theSource\",\"description\":\"theDescription\"}]" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/security/sources") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + restoreApiKey0 + */ + func testRestoreApiKeyTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.restoreApiKeyWithHTTPInfo(key: "myApiKey", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + + XCTAssertEqual(echoResponseBodyData, "{}".data(using: .utf8)) + + XCTAssertEqual(echoResponse.path, "/1/keys/myApiKey/restore") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + saveObject0 + */ + func testSaveObjectTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveObjectWithHTTPInfo(indexName: "theIndexName", body: ["objectID": "id", "test": "val"], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"objectID\":\"id\",\"test\":\"val\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + saveRule with minimal parameters + */ + func testSaveRuleTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", rule: Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains)]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + saveRule with all parameters + */ + func testSaveRuleTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveRuleWithHTTPInfo(indexName: "indexName", objectID: "id1", rule: Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains, alternatives: false, context: "search")], consequence: Consequence(params: ConsequenceParams(filters: "brand:apple", query: ConsequenceQuery.consequenceQueryObject(ConsequenceQueryObject(remove: ["algolia"], edits: [Edit(type: EditType.remove, delete: "abc", insert: "cde"), Edit(type: EditType.replace, delete: "abc", insert: "cde")]))), promote: [Promote.promoteObjectID(PromoteObjectID(objectID: "abc", position: 3)), Promote.promoteObjectIDs(PromoteObjectIDs(objectIDs: ["abc", "def"], position: 1))], filterPromotes: false, hide: [ConsequenceHide(objectID: "321")], userData: ["algolia": "aloglia"]), description: "test", enabled: true, validity: [TimeRange(from: 1_656_670_273, until: 1_656_670_277)]), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\",\"alternatives\":false,\"context\":\"search\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\",\"query\":{\"remove\":[\"algolia\"],\"edits\":[{\"type\":\"remove\",\"delete\":\"abc\",\"insert\":\"cde\"},{\"type\":\"replace\",\"delete\":\"abc\",\"insert\":\"cde\"}]}},\"hide\":[{\"objectID\":\"321\"}],\"filterPromotes\":false,\"userData\":{\"algolia\":\"aloglia\"},\"promote\":[{\"objectID\":\"abc\",\"position\":3},{\"objectIDs\":[\"abc\",\"def\"],\"position\":1}]},\"description\":\"test\",\"enabled\":true,\"validity\":[{\"from\":1656670273,\"until\":1656670277}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + saveRules with minimal parameters + */ + func testSaveRulesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveRulesWithHTTPInfo(indexName: "indexName", rules: [Rule(objectID: "a-rule-id", conditions: [Condition(pattern: "smartphone", anchoring: Anchoring.contains)]), Rule(objectID: "a-second-rule-id", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains)])], requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "[{\"objectID\":\"a-rule-id\",\"conditions\":[{\"pattern\":\"smartphone\",\"anchoring\":\"contains\"}]},{\"objectID\":\"a-second-rule-id\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}]}]" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + saveRules with all parameters + */ + func testSaveRulesTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveRulesWithHTTPInfo(indexName: "indexName", rules: [Rule(objectID: "id1", conditions: [Condition(pattern: "apple", anchoring: Anchoring.contains, alternatives: false, context: "search")], consequence: Consequence(params: ConsequenceParams(filters: "brand:apple", query: ConsequenceQuery.consequenceQueryObject(ConsequenceQueryObject(remove: ["algolia"], edits: [Edit(type: EditType.remove, delete: "abc", insert: "cde"), Edit(type: EditType.replace, delete: "abc", insert: "cde")]))), promote: [Promote.promoteObjectID(PromoteObjectID(objectID: "abc", position: 3)), Promote.promoteObjectIDs(PromoteObjectIDs(objectIDs: ["abc", "def"], position: 1))], filterPromotes: false, hide: [ConsequenceHide(objectID: "321")], userData: ["algolia": "aloglia"]), description: "test", enabled: true, validity: [TimeRange(from: 1_656_670_273, until: 1_656_670_277)])], forwardToReplicas: true, clearExistingRules: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "[{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\",\"alternatives\":false,\"context\":\"search\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\",\"query\":{\"remove\":[\"algolia\"],\"edits\":[{\"type\":\"remove\",\"delete\":\"abc\",\"insert\":\"cde\"},{\"type\":\"replace\",\"delete\":\"abc\",\"insert\":\"cde\"}]}},\"hide\":[{\"objectID\":\"321\"}],\"filterPromotes\":false,\"userData\":{\"algolia\":\"aloglia\"},\"promote\":[{\"objectID\":\"abc\",\"position\":3},{\"objectIDs\":[\"abc\",\"def\"],\"position\":1}]},\"description\":\"test\",\"enabled\":true,\"validity\":[{\"from\":1656670273,\"until\":1656670277}]}]" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + saveSynonym0 + */ + func testSaveSynonymTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveSynonymWithHTTPInfo(indexName: "indexName", objectID: "id1", synonymHit: SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/id1") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + saveSynonyms0 + */ + func testSaveSynonymsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.saveSynonymsWithHTTPInfo(indexName: "indexName", synonymHit: [SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]), SynonymHit(objectID: "id2", type: SynonymType.onewaysynonym, synonyms: ["ephone", "aphone", "yphone"], input: "iphone")], forwardToReplicas: true, replaceExistingSynonyms: false, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "[{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]},{\"objectID\":\"id2\",\"type\":\"onewaysynonym\",\"input\":\"iphone\",\"synonyms\":[\"ephone\",\"aphone\",\"yphone\"]}]" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/batch") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + search for a single hits request with minimal parameters + */ + func testSearchTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(indexName: "cts_e2e_search_empty_index"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"cts_e2e_search_empty_index\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search for a single facet request with minimal parameters + */ + func testSearchTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(facet: "editor", indexName: "cts_e2e_search_facet", type: SearchTypeFacet.facet))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"cts_e2e_search_facet\",\"type\":\"facet\",\"facet\":\"editor\"}],\"strategy\":\"stopIfEnoughMatches\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search for a single hits request with all parameters + */ + func testSearchTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(query: "myQuery", hitsPerPage: 50, indexName: "theIndexName", type: SearchTypeDefault.default))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"theIndexName\",\"query\":\"myQuery\",\"hitsPerPage\":50,\"type\":\"default\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search for a single facet request with all parameters + */ + func testSearchTest3() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(query: "theQuery", maxFacetHits: 50, facet: "theFacet", indexName: "theIndexName", facetQuery: "theFacetQuery", type: SearchTypeFacet.facet))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"theIndexName\",\"type\":\"facet\",\"facet\":\"theFacet\",\"facetQuery\":\"theFacetQuery\",\"query\":\"theQuery\",\"maxFacetHits\":50}],\"strategy\":\"stopIfEnoughMatches\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search for multiple mixed requests in multiple indices with minimal parameters + */ + func testSearchTest4() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(indexName: "theIndexName")), SearchQuery.searchForFacets(SearchForFacets(facet: "theFacet", indexName: "theIndexName2", type: SearchTypeFacet.facet)), SearchQuery.searchForHits(SearchForHits(indexName: "theIndexName", type: SearchTypeDefault.default))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"theIndexName\"},{\"indexName\":\"theIndexName2\",\"type\":\"facet\",\"facet\":\"theFacet\"},{\"indexName\":\"theIndexName\",\"type\":\"default\"}],\"strategy\":\"stopIfEnoughMatches\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search for multiple mixed requests in multiple indices with all parameters + */ + func testSearchTest5() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForFacets(SearchForFacets(query: "theQuery", maxFacetHits: 50, facet: "theFacet", indexName: "theIndexName", facetQuery: "theFacetQuery", type: SearchTypeFacet.facet)), SearchQuery.searchForHits(SearchForHits(query: "myQuery", hitsPerPage: 50, indexName: "theIndexName", type: SearchTypeDefault.default))], strategy: SearchStrategy.stopIfEnoughMatches), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"theIndexName\",\"type\":\"facet\",\"facet\":\"theFacet\",\"facetQuery\":\"theFacetQuery\",\"query\":\"theQuery\",\"maxFacetHits\":50},{\"indexName\":\"theIndexName\",\"query\":\"myQuery\",\"hitsPerPage\":50,\"type\":\"default\"}],\"strategy\":\"stopIfEnoughMatches\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search filters accept all of the possible shapes + */ + func testSearchTest6() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(facetFilters: FacetFilters.string("mySearch:filters"), optionalFilters: OptionalFilters.string("mySearch:filters"), numericFilters: NumericFilters.string("mySearch:filters"), tagFilters: TagFilters.string("mySearch:filters"), reRankingApplyFilter: ReRankingApplyFilter.string("mySearch:filters"), indexName: "theIndexName")), SearchQuery.searchForHits(SearchForHits(facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), optionalFilters: OptionalFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), numericFilters: NumericFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), tagFilters: TagFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), reRankingApplyFilter: ReRankingApplyFilter.arrayOfMixedSearchFilters([MixedSearchFilters.string("mySearch:filters"), MixedSearchFilters.arrayOfString(["mySearch:filters"])]), indexName: "theIndexName"))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"indexName\":\"theIndexName\",\"facetFilters\":\"mySearch:filters\",\"reRankingApplyFilter\":\"mySearch:filters\",\"tagFilters\":\"mySearch:filters\",\"numericFilters\":\"mySearch:filters\",\"optionalFilters\":\"mySearch:filters\"},{\"indexName\":\"theIndexName\",\"facetFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"reRankingApplyFilter\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"tagFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"numericFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]],\"optionalFilters\":[\"mySearch:filters\",[\"mySearch:filters\"]]}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search with all search parameters + */ + func testSearchTest7() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchWithHTTPInfo(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(query: "", similarQuery: "", filters: "", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), optionalFilters: OptionalFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), numericFilters: NumericFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), tagFilters: TagFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), sumOrFiltersScores: true, restrictSearchableAttributes: [""], facets: [""], facetingAfterDistinct: true, page: 0, offset: 0, length: 1, aroundLatLng: "", aroundLatLngViaIP: true, aroundRadius: AroundRadius.aroundRadiusAll(AroundRadiusAll.all), aroundPrecision: AroundPrecision.int(0), minimumAroundRadius: 1, insideBoundingBox: [[47.3165, 4.9665, 47.3424, 5.0201], [40.9234, 2.1185, 38.643, 1.9916]], insidePolygon: [[47.3165, 4.9665, 47.3424, 5.0201, 47.32, 4.9], [40.9234, 2.1185, 38.643, 1.9916, 39.2587, 2.0104]], naturalLanguages: [""], ruleContexts: [""], personalizationImpact: 0, userToken: "", getRankingInfo: true, explain: ["foo", "bar"], synonyms: true, clickAnalytics: true, analytics: true, analyticsTags: [""], percentileComputation: true, enableABTest: true, attributesForFaceting: [""], attributesToRetrieve: [""], ranking: [""], customRanking: [""], relevancyStrictness: 0, attributesToHighlight: [""], attributesToSnippet: [""], highlightPreTag: "", highlightPostTag: "", snippetEllipsisText: "", restrictHighlightAndSnippetArrays: true, hitsPerPage: 1, minWordSizefor1Typo: 0, minWordSizefor2Typos: 0, typoTolerance: TypoTolerance.typoToleranceEnum(TypoToleranceEnum.min), allowTyposOnNumericTokens: true, disableTypoToleranceOnAttributes: [""], ignorePlurals: IgnorePlurals.bool(false), removeStopWords: RemoveStopWords.bool(true), keepDiacriticsOnCharacters: "", queryLanguages: [""], decompoundQuery: true, enableRules: true, enablePersonalization: true, queryType: QueryType.prefixAll, removeWordsIfNoResults: RemoveWordsIfNoResults.allOptional, advancedSyntax: true, optionalWords: [""], disableExactOnAttributes: [""], exactOnSingleWordQuery: ExactOnSingleWordQuery.attribute, alternativesAsExact: [AlternativesAsExact.multiWordsSynonym], advancedSyntaxFeatures: [AdvancedSyntaxFeatures.exactPhrase], distinct: Distinct.int(0), replaceSynonymsInHighlight: true, minProximity: 1, responseFields: [""], maxValuesPerFacet: 0, sortFacetValuesBy: "", attributeCriteriaComputedByMinProximity: true, renderingContent: RenderingContent(facetOrdering: FacetOrdering(facets: Facets(order: ["a", "b"]), values: ["a": Value(order: ["b"], sortRemainingBy: SortRemainingBy.count)])), enableReRanking: true, reRankingApplyFilter: ReRankingApplyFilter.arrayOfMixedSearchFilters([MixedSearchFilters.string("")]), indexName: "theIndexName", type: SearchTypeDefault.default))]), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"requests\":[{\"advancedSyntax\":true,\"advancedSyntaxFeatures\":[\"exactPhrase\"],\"allowTyposOnNumericTokens\":true,\"alternativesAsExact\":[\"multiWordsSynonym\"],\"analytics\":true,\"analyticsTags\":[\"\"],\"aroundLatLng\":\"\",\"aroundLatLngViaIP\":true,\"aroundPrecision\":0,\"aroundRadius\":\"all\",\"attributeCriteriaComputedByMinProximity\":true,\"attributesForFaceting\":[\"\"],\"attributesToHighlight\":[\"\"],\"attributesToRetrieve\":[\"\"],\"attributesToSnippet\":[\"\"],\"clickAnalytics\":true,\"customRanking\":[\"\"],\"decompoundQuery\":true,\"disableExactOnAttributes\":[\"\"],\"disableTypoToleranceOnAttributes\":[\"\"],\"distinct\":0,\"enableABTest\":true,\"enablePersonalization\":true,\"enableReRanking\":true,\"enableRules\":true,\"exactOnSingleWordQuery\":\"attribute\",\"explain\":[\"foo\",\"bar\"],\"facetFilters\":[\"\"],\"facetingAfterDistinct\":true,\"facets\":[\"\"],\"filters\":\"\",\"getRankingInfo\":true,\"highlightPostTag\":\"\",\"highlightPreTag\":\"\",\"hitsPerPage\":1,\"ignorePlurals\":false,\"indexName\":\"theIndexName\",\"insideBoundingBox\":[[47.3165,4.9665,47.3424,5.0201],[40.9234,2.1185,38.643,1.9916]],\"insidePolygon\":[[47.3165,4.9665,47.3424,5.0201,47.32,4.9],[40.9234,2.1185,38.643,1.9916,39.2587,2.0104]],\"keepDiacriticsOnCharacters\":\"\",\"length\":1,\"maxValuesPerFacet\":0,\"minProximity\":1,\"minWordSizefor1Typo\":0,\"minWordSizefor2Typos\":0,\"minimumAroundRadius\":1,\"naturalLanguages\":[\"\"],\"numericFilters\":[\"\"],\"offset\":0,\"optionalFilters\":[\"\"],\"optionalWords\":[\"\"],\"page\":0,\"percentileComputation\":true,\"personalizationImpact\":0,\"query\":\"\",\"queryLanguages\":[\"\"],\"queryType\":\"prefixAll\",\"ranking\":[\"\"],\"reRankingApplyFilter\":[\"\"],\"relevancyStrictness\":0,\"removeStopWords\":true,\"removeWordsIfNoResults\":\"allOptional\",\"renderingContent\":{\"facetOrdering\":{\"facets\":{\"order\":[\"a\",\"b\"]},\"values\":{\"a\":{\"order\":[\"b\"],\"sortRemainingBy\":\"count\"}}}},\"replaceSynonymsInHighlight\":true,\"responseFields\":[\"\"],\"restrictHighlightAndSnippetArrays\":true,\"restrictSearchableAttributes\":[\"\"],\"ruleContexts\":[\"\"],\"similarQuery\":\"\",\"snippetEllipsisText\":\"\",\"sortFacetValuesBy\":\"\",\"sumOrFiltersScores\":true,\"synonyms\":true,\"tagFilters\":[\"\"],\"type\":\"default\",\"typoTolerance\":\"min\",\"userToken\":\"\"}]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/*/queries") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get searchDictionaryEntries results with minimal parameters + */ + func testSearchDictionaryEntriesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, searchDictionaryEntriesParams: SearchDictionaryEntriesParams(query: "foo"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"foo\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get searchDictionaryEntries results with all parameters + */ + func testSearchDictionaryEntriesTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchDictionaryEntriesWithHTTPInfo(dictionaryName: DictionaryType.compounds, searchDictionaryEntriesParams: SearchDictionaryEntriesParams(query: "foo", page: 4, hitsPerPage: 2, language: "fr"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"foo\",\"page\":4,\"hitsPerPage\":2,\"language\":\"fr\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/compounds/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get searchForFacetValues results with minimal parameters + */ + func testSearchForFacetValuesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchForFacetValuesWithHTTPInfo(indexName: "indexName", facetName: "facetName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/facets/facetName/query") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get searchForFacetValues results with all parameters + */ + func testSearchForFacetValuesTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchForFacetValuesWithHTTPInfo(indexName: "indexName", facetName: "facetName", searchForFacetValuesRequest: SearchForFacetValuesRequest(params: "query=foo&facetFilters=['bar']", facetQuery: "foo", maxFacetHits: 42), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"params\":\"query=foo&facetFilters=['bar']\",\"facetQuery\":\"foo\",\"maxFacetHits\":42}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/facets/facetName/query") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchRules0 + */ + func testSearchRulesTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchRulesWithHTTPInfo(indexName: "indexName", searchRulesParams: SearchRulesParams(query: "something"), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"something\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/rules/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search with minimal parameters + */ + func testSearchSingleIndexTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "indexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/query") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search with special characters in indexName + */ + func testSearchSingleIndexTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "cts_e2e_space in index", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_space%20in%20index/query") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + search with searchParams + */ + func testSearchSingleIndexTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSingleIndexWithHTTPInfo(indexName: "indexName", searchParams: SearchParams.searchParamsObject(SearchParamsObject(query: "myQuery", facetFilters: FacetFilters.arrayOfMixedSearchFilters([MixedSearchFilters.string("tags:algolia")]))), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/query") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchSynonyms with minimal parameters + */ + func testSearchSynonymsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSynonymsWithHTTPInfo(indexName: "indexName", requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchSynonyms with all parameters + */ + func testSearchSynonymsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchSynonymsWithHTTPInfo(indexName: "indexName", searchSynonymsParams: SearchSynonymsParams(query: "myQuery", type: SynonymType.altcorrection1, page: 10, hitsPerPage: 10), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"myQuery\",\"type\":\"altcorrection1\",\"page\":10,\"hitsPerPage\":10}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/indexName/synonyms/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + searchUserIds0 + */ + func testSearchUserIdsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.searchUserIdsWithHTTPInfo(searchUserIdsParams: SearchUserIdsParams(query: "test", clusterName: "theClusterName", page: 5, hitsPerPage: 10), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"query\":\"test\",\"clusterName\":\"theClusterName\",\"page\":5,\"hitsPerPage\":10}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/clusters/mapping/search") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get setDictionarySettings results with minimal parameters + */ + func testSetDictionarySettingsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setDictionarySettingsWithHTTPInfo(dictionarySettingsParams: DictionarySettingsParams(disableStandardEntries: StandardEntries(plurals: ["fr": false, "en": false, "ru": true])), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true}}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + get setDictionarySettings results with all parameters + */ + func testSetDictionarySettingsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setDictionarySettingsWithHTTPInfo(dictionarySettingsParams: DictionarySettingsParams(disableStandardEntries: StandardEntries(plurals: ["fr": false, "en": false, "ru": true], stopwords: ["fr": false], compounds: ["ru": true])), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true},\"stopwords\":{\"fr\":false},\"compounds\":{\"ru\":true}}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/dictionaries/*/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + setSettings with minimal parameters + */ + func testSetSettingsTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "cts_e2e_settings", indexSettings: IndexSettings(paginationLimitedTo: 10), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"paginationLimitedTo\":10}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/cts_e2e_settings/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow boolean `typoTolerance` + */ + func testSetSettingsTest1() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(typoTolerance: TypoTolerance.bool(true)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"typoTolerance\":true}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow enum `typoTolerance` + */ + func testSetSettingsTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(typoTolerance: TypoTolerance.typoToleranceEnum(TypoToleranceEnum.min)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"typoTolerance\":\"min\"}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow boolean `ignorePlurals` + */ + func testSetSettingsTest3() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(ignorePlurals: IgnorePlurals.bool(true)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"ignorePlurals\":true}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow list of string `ignorePlurals` + */ + func testSetSettingsTest4() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(ignorePlurals: IgnorePlurals.arrayOfString(["algolia"])), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"ignorePlurals\":[\"algolia\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow boolean `removeStopWords` + */ + func testSetSettingsTest5() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(removeStopWords: RemoveStopWords.bool(true)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"removeStopWords\":true}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow list of string `removeStopWords` + */ + func testSetSettingsTest6() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(removeStopWords: RemoveStopWords.arrayOfString(["algolia"])), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"removeStopWords\":[\"algolia\"]}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow boolean `distinct` + */ + func testSetSettingsTest7() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(distinct: Distinct.bool(true)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"distinct\":true}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow integers for `distinct` + */ + func testSetSettingsTest8() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(distinct: Distinct.int(1)), forwardToReplicas: true, requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"distinct\":1}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + let comparableQueryItems = try XCTUnwrap("{\"forwardToReplicas\":\"true\"}".data(using: .utf8)) + let comparableQueryItemsMap = try CodableHelper.jsonDecoder.decode(StringMapObject.self, from: comparableQueryItems) + + XCTAssertEqual(echoResponse.queryItems, comparableQueryItemsMap) + } + + /** + setSettings allow all `indexSettings` + */ + func testSetSettingsTest9() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.setSettingsWithHTTPInfo(indexName: "theIndexName", indexSettings: IndexSettings(replicas: [""], paginationLimitedTo: 0, unretrievableAttributes: ["foo"], disableTypoToleranceOnWords: ["algolia"], attributesToTransliterate: ["algolia"], camelCaseAttributes: ["algolia"], decompoundedAttributes: ["algolia": "aloglia"], indexLanguages: ["algolia"], disablePrefixOnAttributes: ["algolia"], allowCompressionOfIntegerArray: true, numericAttributesForFiltering: ["algolia"], separatorsToIndex: "bar", searchableAttributes: ["foo"], userData: ["user": "data"], customNormalization: ["algolia": ["aloglia": "aglolia"]], attributeForDistinct: "test", attributesForFaceting: ["algolia"], attributesToRetrieve: ["algolia"], ranking: ["geo"], customRanking: ["algolia"], relevancyStrictness: 10, attributesToHighlight: ["algolia"], attributesToSnippet: ["algolia"], highlightPreTag: "", highlightPostTag: "", snippetEllipsisText: "---", restrictHighlightAndSnippetArrays: true, hitsPerPage: 10, minWordSizefor1Typo: 5, minWordSizefor2Typos: 11, typoTolerance: TypoTolerance.bool(false), allowTyposOnNumericTokens: true, disableTypoToleranceOnAttributes: ["algolia"], ignorePlurals: IgnorePlurals.bool(false), removeStopWords: RemoveStopWords.bool(false), keepDiacriticsOnCharacters: "abc", queryLanguages: ["algolia"], decompoundQuery: false, enableRules: true, enablePersonalization: true, queryType: QueryType.prefixLast, removeWordsIfNoResults: RemoveWordsIfNoResults.lastWords, mode: Mode.neuralSearch, semanticSearch: SemanticSearch(eventSources: ["foo"]), advancedSyntax: true, optionalWords: ["myspace"], disableExactOnAttributes: ["algolia"], exactOnSingleWordQuery: ExactOnSingleWordQuery.attribute, alternativesAsExact: [AlternativesAsExact.singleWordSynonym], advancedSyntaxFeatures: [AdvancedSyntaxFeatures.exactPhrase], distinct: Distinct.int(3), replaceSynonymsInHighlight: true, minProximity: 6, responseFields: ["algolia"], maxFacetHits: 20, maxValuesPerFacet: 30, sortFacetValuesBy: "date", attributeCriteriaComputedByMinProximity: true, renderingContent: RenderingContent(facetOrdering: FacetOrdering(facets: Facets(order: ["a", "b"]), values: ["a": Value(order: ["b"], sortRemainingBy: SortRemainingBy.count)])), enableReRanking: false, reRankingApplyFilter: ReRankingApplyFilter.string("mySearch:filters")), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"advancedSyntax\":true,\"advancedSyntaxFeatures\":[\"exactPhrase\"],\"allowCompressionOfIntegerArray\":true,\"allowTyposOnNumericTokens\":true,\"alternativesAsExact\":[\"singleWordSynonym\"],\"attributeCriteriaComputedByMinProximity\":true,\"attributeForDistinct\":\"test\",\"attributesForFaceting\":[\"algolia\"],\"attributesToHighlight\":[\"algolia\"],\"attributesToRetrieve\":[\"algolia\"],\"attributesToSnippet\":[\"algolia\"],\"attributesToTransliterate\":[\"algolia\"],\"camelCaseAttributes\":[\"algolia\"],\"customNormalization\":{\"algolia\":{\"aloglia\":\"aglolia\"}},\"customRanking\":[\"algolia\"],\"decompoundQuery\":false,\"decompoundedAttributes\":{\"algolia\":\"aloglia\"},\"disableExactOnAttributes\":[\"algolia\"],\"disablePrefixOnAttributes\":[\"algolia\"],\"disableTypoToleranceOnAttributes\":[\"algolia\"],\"disableTypoToleranceOnWords\":[\"algolia\"],\"distinct\":3,\"enablePersonalization\":true,\"enableReRanking\":false,\"enableRules\":true,\"exactOnSingleWordQuery\":\"attribute\",\"highlightPreTag\":\"\",\"highlightPostTag\":\"\",\"hitsPerPage\":10,\"ignorePlurals\":false,\"indexLanguages\":[\"algolia\"],\"keepDiacriticsOnCharacters\":\"abc\",\"maxFacetHits\":20,\"maxValuesPerFacet\":30,\"minProximity\":6,\"minWordSizefor1Typo\":5,\"minWordSizefor2Typos\":11,\"mode\":\"neuralSearch\",\"numericAttributesForFiltering\":[\"algolia\"],\"optionalWords\":[\"myspace\"],\"paginationLimitedTo\":0,\"queryLanguages\":[\"algolia\"],\"queryType\":\"prefixLast\",\"ranking\":[\"geo\"],\"reRankingApplyFilter\":\"mySearch:filters\",\"relevancyStrictness\":10,\"removeStopWords\":false,\"removeWordsIfNoResults\":\"lastWords\",\"renderingContent\":{\"facetOrdering\":{\"facets\":{\"order\":[\"a\",\"b\"]},\"values\":{\"a\":{\"order\":[\"b\"],\"sortRemainingBy\":\"count\"}}}},\"replaceSynonymsInHighlight\":true,\"replicas\":[\"\"],\"responseFields\":[\"algolia\"],\"restrictHighlightAndSnippetArrays\":true,\"searchableAttributes\":[\"foo\"],\"semanticSearch\":{\"eventSources\":[\"foo\"]},\"separatorsToIndex\":\"bar\",\"snippetEllipsisText\":\"---\",\"sortFacetValuesBy\":\"date\",\"typoTolerance\":false,\"unretrievableAttributes\":[\"foo\"],\"userData\":{\"user\":\"data\"}}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/settings") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } + + /** + updateApiKey0 + */ + func testUpdateApiKeyTest0() async throws { + let configuration: Search.Configuration = try Search.Configuration(applicationID: APPLICATION_ID, apiKey: API_KEY) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.updateApiKeyWithHTTPInfo(key: "myApiKey", apiKey: ApiKey(acl: [Acl.search, Acl.addObject], maxHitsPerQuery: 20, maxQueriesPerIPPerHour: 100, validity: 300), requestOptions: nil) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try JSON(data: echoResponseBodyData, options: .fragmentsAllowed) + + let comparableJSON = JSON(parseJSON: + "{\"acl\":[\"search\",\"addObject\"],\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}" + ) + + XCTAssertEqual(echoResponseBodyJSON, comparableJSON) + + XCTAssertEqual(echoResponse.path, "/1/keys/myApiKey") + XCTAssertEqual(echoResponse.method, HTTPMethod.put) + + XCTAssertNil(echoResponse.queryItems) + } +}