Skip to content

Commit

Permalink
Update tests to use empty response where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmichel committed Jan 7, 2024
1 parent 22bdd1e commit af57e84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 18 additions & 0 deletions Sources/_Helpers/Response.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

extension URLResponse {
// Windows and Linux don't have the ability to empty initialize a URLResponse like `URLReponse()` so
// We provide a function that can give us the right value on an platform.
public static func empty() -> URLResponse {
#if os(Windows) || os(Linux)
URLResponse(url: .init(string: "https://supabase.com")!, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
#else
URLResponse()
#endif
}
}

8 changes: 1 addition & 7 deletions Tests/AuthTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class RequestsTests: XCTestCase {
let sut = makeSUT(fetch: { request in
let authorizationHeader = request.allHTTPHeaderFields?["Authorization"]
XCTAssertEqual(authorizationHeader, "bearer accesstoken")
return (json(named: "user"), HTTPURLResponse.empty())
return (json(named: "user"), HTTPURLResponse())
})

let currentDate = Date()
Expand Down Expand Up @@ -436,9 +436,3 @@ final class RequestsTests: XCTestCase {
)
}
}

extension URLResponse {
static func empty() -> URLResponse {
URLResponse(url: .init(string: "https://arc.net")!, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
}
}

0 comments on commit af57e84

Please sign in to comment.