-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(storage): increase code coverage (#650)
* test(storage): increase code coverage * add more tests * add tests * more tests
- Loading branch information
Showing
19 changed files
with
1,494 additions
and
65 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Codable.swift | ||
// Supabase | ||
// | ||
// Created by Guilherme Souza on 20/01/25. | ||
// | ||
|
||
import ConcurrencyExtras | ||
import Foundation | ||
|
||
extension JSONDecoder { | ||
private static let supportedDateFormatters: [UncheckedSendable<ISO8601DateFormatter>] = [ | ||
ISO8601DateFormatter.iso8601WithFractionalSeconds, | ||
ISO8601DateFormatter.iso8601, | ||
] | ||
|
||
/// Default `JSONDecoder` for decoding types from Supabase. | ||
package static let `default`: JSONDecoder = { | ||
let decoder = JSONDecoder() | ||
decoder.dateDecodingStrategy = .custom { decoder in | ||
let container = try decoder.singleValueContainer() | ||
let string = try container.decode(String.self) | ||
|
||
for formatter in supportedDateFormatters { | ||
if let date = formatter.value.date(from: string) { | ||
return date | ||
} | ||
} | ||
|
||
throw DecodingError.dataCorruptedError( | ||
in: container, debugDescription: "Invalid date format: \(string)" | ||
) | ||
} | ||
return decoder | ||
}() | ||
} |
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 |
---|---|---|
@@ -1,37 +1,70 @@ | ||
import HTTPTypes | ||
|
||
package extension HTTPFields { | ||
init(_ dictionary: [String: String]) { | ||
extension HTTPFields { | ||
package init(_ dictionary: [String: String]) { | ||
self.init(dictionary.map { .init(name: .init($0.key)!, value: $0.value) }) | ||
} | ||
var dictionary: [String: String] { | ||
|
||
package var dictionary: [String: String] { | ||
let keyValues = self.map { | ||
($0.name.rawName, $0.value) | ||
} | ||
|
||
return .init(keyValues, uniquingKeysWith: { $1 }) | ||
} | ||
mutating func merge(with other: Self) { | ||
|
||
package mutating func merge(with other: Self) { | ||
for field in other { | ||
self[field.name] = field.value | ||
} | ||
} | ||
func merging(with other: Self) -> Self { | ||
|
||
package func merging(with other: Self) -> Self { | ||
var copy = self | ||
|
||
for field in other { | ||
copy[field.name] = field.value | ||
} | ||
|
||
return copy | ||
} | ||
|
||
/// Append or update a value in header. | ||
/// | ||
/// Example: | ||
/// ```swift | ||
/// var headers: HTTPFields = [ | ||
/// "Prefer": "count=exact,return=representation" | ||
/// ] | ||
/// | ||
/// headers.appendOrUpdate(.prefer, value: "return=minimal") | ||
/// #expect(headers == ["Prefer": "count=exact,return=minimal"] | ||
/// ``` | ||
package mutating func appendOrUpdate( | ||
_ name: HTTPField.Name, | ||
value: String, | ||
separator: String = "," | ||
) { | ||
if let currentValue = self[name] { | ||
var components = currentValue.components(separatedBy: separator) | ||
|
||
if let key = value.split(separator: "=").first, | ||
let index = components.firstIndex(where: { $0.hasPrefix("\(key)=") }) | ||
{ | ||
components[index] = value | ||
} else { | ||
components.append(value) | ||
} | ||
|
||
self[name] = components.joined(separator: separator) | ||
} else { | ||
self[name] = value | ||
} | ||
} | ||
} | ||
|
||
package extension HTTPField.Name { | ||
static let xClientInfo = HTTPField.Name("X-Client-Info")! | ||
static let xRegion = HTTPField.Name("x-region")! | ||
static let xRelayError = HTTPField.Name("x-relay-error")! | ||
extension HTTPField.Name { | ||
package static let xClientInfo = HTTPField.Name("X-Client-Info")! | ||
package static let xRegion = HTTPField.Name("x-region")! | ||
package static let xRelayError = HTTPField.Name("x-relay-error")! | ||
} |
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
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
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
Oops, something went wrong.