Skip to content

Commit

Permalink
Fix APIEndpoint path
Browse files Browse the repository at this point in the history
  • Loading branch information
pawello2222 committed May 20, 2024
1 parent 24d92e4 commit dbccbb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/PhantomKitAPI/API/APIEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public protocol APIEndpoint {

extension APIEndpoint {
public func urlRequest() throws -> URLRequest {
guard let url = URL(string: baseURL)?.appending(component: path) else {
guard let url = URL(string: baseURL)?.appending(path: path) else {
throw APIError.invalidURL
}
return try URLRequest(url: url).applying {
Expand Down
12 changes: 12 additions & 0 deletions Tests/PhantomKitAPITests/APIEndpoint+Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ extension APIEndpointTests {
XCTAssertEqual(request.httpBody, .test)
}

func test_urlRequest_longPath() throws {
let endpoint: APIEndpoint = TestAPIEndpoint(
baseURL: "https://api.example.com",
path: "/test/a/s/v",
method: .get
)

let request = try endpoint.urlRequest()

XCTAssertEqual(request.url?.absoluteString, "https://api.example.com/test/a/s/v")
}

func test_urlRequest_invalidURL() throws {
let endpoint: APIEndpoint = TestAPIEndpoint(
baseURL: "$xyz://api.example.com",
Expand Down

0 comments on commit dbccbb5

Please sign in to comment.