-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some Request.Configuration properties not being applied (#47)
* #46: Set properties on URLRequest from Request.Configuration * #46: URLRequest.NetworkServiceType.avStreaming does not exist in FoundationNetworking platforms
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Tests/RelaxTests/Request/Properties/ConfigurationTests.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,67 @@ | ||
// | ||
// ConfigurationTests.swift | ||
// | ||
// | ||
// Created by Thomas De Leon on 1/25/24. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import Relax | ||
|
||
final class ConfigurationTests: XCTestCase { | ||
let testURL = URL(string: "https://example.com/")! | ||
private func check(_ request: Request, against expected: Request.Configuration) { | ||
XCTAssertEqual(request.configuration, expected) | ||
|
||
let urlRequest = request.urlRequest | ||
|
||
XCTAssertEqual(urlRequest.allowsCellularAccess, expected.allowsCellularAccess) | ||
XCTAssertEqual(urlRequest.cachePolicy, expected.cachePolicy) | ||
XCTAssertEqual(urlRequest.httpShouldUsePipelining, expected.httpShouldUsePipelining) | ||
XCTAssertEqual(urlRequest.networkServiceType, expected.networkServiceType) | ||
XCTAssertEqual(urlRequest.timeoutInterval, expected.timeoutInterval) | ||
XCTAssertEqual(urlRequest.httpShouldHandleCookies, expected.httpShouldHandleCookies) | ||
|
||
#if !canImport(FoundationNetworking) | ||
XCTAssertEqual(urlRequest.allowsConstrainedNetworkAccess, expected.allowsConstrainedNetworkAccess) | ||
XCTAssertEqual(urlRequest.allowsExpensiveNetworkAccess, expected.allowsExpensiveNetworkAccess) | ||
#endif | ||
} | ||
|
||
func testDefaultConfiguration() throws { | ||
let request = Request(.get, url: testURL) | ||
check(request, against: .default) | ||
} | ||
|
||
func testConfiguration() throws { | ||
#if canImport(FoundationNetworking) | ||
let configuration = Request.Configuration( | ||
allowsCellularAccess: false, | ||
cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, | ||
httpShouldUsePipelining: true, | ||
networkServiceType: .video, | ||
timeoutInterval: 1, | ||
httpShouldHandleCookies: false, | ||
parseHTTPStatusErrors: true, | ||
appendTraillingSlashToPath: true | ||
) | ||
#else | ||
let configuration = Request.Configuration( | ||
allowsCellularAccess: false, | ||
cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, | ||
httpShouldUsePipelining: true, | ||
networkServiceType: .video, | ||
timeoutInterval: 1, | ||
httpShouldHandleCookies: false, | ||
allowsConstrainedNetworkAccess: false, | ||
allowsExpensiveNetworkAccess: false, | ||
parseHTTPStatusErrors: true, | ||
appendTraillingSlashToPath: true | ||
) | ||
#endif | ||
|
||
let request = Request(.get, url: testURL, configuration: configuration) | ||
check(request, against: configuration) | ||
} | ||
} |