Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter url to be a variable and optional under configuration path #21

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/CheckoutNetwork/ConfigurationModels/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

/// Shared interface for generating an url from your structure grouping your endpoints
public protocol NetworkPath {
/// URL to be used for creation of a network request
func url() -> URL

/// URL to be used for creation of a network request
var url: URL? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public struct RequestConfiguration {
mimeType: MIMEType = .JSON,
decodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) throws {
// Validate URL can be broken down to components for formatting
guard var components = URLComponents(url: path.url(), resolvingAgainstBaseURL: true) else {
guard let url = path.url,
var components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
throw CheckoutNetworkError.invalidURL
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/CheckoutNetworkTests/CheckoutNetworkClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let testResponseCode = 300

let expectedData = "nothing".data(using: .utf8)
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
okhan-okbay-cko marked this conversation as resolved.
Show resolved Hide resolved
statusCode: 300,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -142,7 +142,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let client = CheckoutNetworkClient(session: fakeSession)
let testConfig = try! RequestConfiguration(path: FakePath.testServices)

let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -171,7 +171,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let testConfig = try! RequestConfiguration(path: FakePath.testServices)

let expectedData = Data()
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -205,7 +205,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let fakeObjectString = String(data: fakeObjectEncoded, encoding: .utf8)!
// Make id key invalid for decoding
fakeObjectEncoded = fakeObjectString.replacingOccurrences(of: "d", with: "").data(using: .utf8)!
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -236,7 +236,7 @@ final class CheckoutNetworkClientTests: XCTestCase {

let fakeObject = FakeObject(id: UUID().uuidString)
let fakeObjectEncoded = try! JSONEncoder().encode(fakeObject)
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -289,7 +289,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let testResponseCode = 300

let expectedData = "nothing".data(using: .utf8)
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 300,
httpVersion: nil,
headerFields: nil)
Expand Down Expand Up @@ -335,7 +335,7 @@ final class CheckoutNetworkClientTests: XCTestCase {

let fakeObject = FakeObject(id: UUID().uuidString)
let fakeObjectEncoded = try! JSONEncoder().encode(fakeObject)
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand All @@ -358,7 +358,7 @@ final class CheckoutNetworkClientTests: XCTestCase {
let client = CheckoutNetworkClient(session: fakeSession)
let testConfig = try! RequestConfiguration(path: FakePath.testServices)

let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url(),
let expectedResponse = HTTPURLResponse(url: FakePath.testServices.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CheckoutNetworkTests/Helpers/FakePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum FakePath: NetworkPath {

case testServices

func url() -> URL {
var url: URL? {
switch self {
case .testServices: return URL(string: "https://google-not.now")!
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/CheckoutNetworkTests/RequestConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class RequestConfigurationTests: XCTestCase {
let config = try! RequestConfiguration(path: testPath)
let request = config.request

XCTAssertEqual(request.url, testPath.url())
XCTAssertEqual(request.url, testPath.url)
XCTAssertEqual(request.httpMethod, HTTPMethod.get.rawValue)
XCTAssertNil(request.httpBody)
XCTAssertEqual(request.allHTTPHeaderFields, [:])
Expand All @@ -29,7 +29,7 @@ final class RequestConfigurationTests: XCTestCase {
mimeType: testMime)
let request = config.request

XCTAssertEqual(request.url, testPath.url())
XCTAssertEqual(request.url, testPath.url)
XCTAssertEqual(request.httpMethod, HTTPMethod.get.rawValue)
XCTAssertNil(request.httpBody)
XCTAssertEqual(request.allHTTPHeaderFields, [:])
Expand All @@ -44,7 +44,7 @@ final class RequestConfigurationTests: XCTestCase {
mimeType: testMime)
let request = config.request

XCTAssertEqual(request.url, testPath.url())
XCTAssertEqual(request.url, testPath.url)
XCTAssertEqual(request.httpMethod, HTTPMethod.get.rawValue)
XCTAssertEqual(request.httpBody, testData)
XCTAssertEqual(request.allHTTPHeaderFields, [MIMEType.key: testMime.rawValue])
Expand Down
Loading