-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client configuration): default headers not applied (#839)
- Loading branch information
1 parent
50369ab
commit f7745ae
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Tests/AlgoliaSearchClientTests/Unit/CustomClientConfigurationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// CustomClientConfigurationTests.swift | ||
// | ||
// | ||
// Created by Vladislav Fitc on 27/11/2023. | ||
// | ||
|
||
import Foundation | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import AlgoliaSearchClient | ||
|
||
class CustomClientConfigurationTests: XCTestCase { | ||
|
||
func testCustomHeaders() throws { | ||
let configuration = SearchConfiguration(applicationID: "undefined", apiKey: "undefined") | ||
.set(\.defaultHeaders, to: ["default-header": "default-header-value"]) | ||
|
||
let requester = TestRequester() | ||
|
||
let client = SearchClient(configuration: configuration, | ||
requester: requester) | ||
|
||
let exp = expectation(description: "method call") | ||
|
||
requester.onRequest = { request in | ||
let headers = request.allHTTPHeaderFields ?? [:] | ||
XCTAssert(headers.contains(where: { $0.key == "default-header" && $0.value == "default-header-value" })) | ||
XCTAssert((request.allHTTPHeaderFields ?? [:]).contains(where: { $0.key == "another-header" && $0.value == "another-value" })) | ||
exp.fulfill() | ||
} | ||
|
||
let queries: [MultiSearchQuery] = [ | ||
.hitsSearch(.init(indexName: "some-index", query: "search")) | ||
] | ||
|
||
let requestOptions = RequestOptions(headers: ["another-header": "another-value"]) | ||
|
||
client.search(queries: queries, requestOptions: requestOptions) { _ in } | ||
|
||
waitForExpectations(timeout: 5) | ||
|
||
} | ||
|
||
} |