Skip to content

Commit 688c3b3

Browse files
committed
fix Test
1 parent caf063d commit 688c3b3

File tree

7 files changed

+31
-99
lines changed

7 files changed

+31
-99
lines changed

Tests/FunctionsTests/FunctionInvokeOptionsTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import XCTest
55
final class FunctionInvokeOptionsTests: XCTestCase {
66
func test_initWithStringBody() {
77
let options = FunctionInvokeOptions(body: "string value")
8-
XCTAssertEqual(options.headers["Content-Type"], "text/plain")
8+
XCTAssertEqual(options.headers[.contentType], "text/plain")
99
XCTAssertNotNil(options.body)
1010
}
1111

1212
func test_initWithDataBody() {
1313
let options = FunctionInvokeOptions(body: "binary value".data(using: .utf8)!)
14-
XCTAssertEqual(options.headers["Content-Type"], "application/octet-stream")
14+
XCTAssertEqual(options.headers[.contentType], "application/octet-stream")
1515
XCTAssertNotNil(options.body)
1616
}
1717

@@ -20,7 +20,7 @@ final class FunctionInvokeOptionsTests: XCTestCase {
2020
let value: String
2121
}
2222
let options = FunctionInvokeOptions(body: Body(value: "value"))
23-
XCTAssertEqual(options.headers["Content-Type"], "application/json")
23+
XCTAssertEqual(options.headers[.contentType], "application/json")
2424
XCTAssertNotNil(options.body)
2525
}
2626

@@ -31,7 +31,7 @@ final class FunctionInvokeOptionsTests: XCTestCase {
3131
headers: ["Content-Type": contentType],
3232
body: "binary value".data(using: .utf8)!
3333
)
34-
XCTAssertEqual(options.headers["Content-Type"], contentType)
34+
XCTAssertEqual(options.headers[.contentType], contentType)
3535
XCTAssertNotNil(options.body)
3636
}
3737
}

Tests/FunctionsTests/FunctionsClientTests.swift

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ConcurrencyExtras
22
@testable import Functions
33
import Helpers
4+
import HTTPTypes
45
import TestHelpers
56
import XCTest
67

@@ -22,8 +23,8 @@ final class FunctionsClientTests: XCTestCase {
2223
)
2324
XCTAssertEqual(client.region, "sa-east-1")
2425

25-
XCTAssertEqual(client.headers["Apikey"], apiKey)
26-
XCTAssertNotNil(client.headers["X-Client-Info"])
26+
XCTAssertEqual(client.headers[.init("Apikey")!], apiKey)
27+
XCTAssertNotNil(client.headers[.init("X-Client-Info")!])
2728
}
2829

2930
func testInvoke() async throws {
@@ -53,9 +54,9 @@ final class FunctionsClientTests: XCTestCase {
5354

5455
XCTAssertEqual(request?.url, url)
5556
XCTAssertEqual(request?.method, .post)
56-
XCTAssertEqual(request?.headers["Apikey"], apiKey)
57-
XCTAssertEqual(request?.headers["X-Custom-Key"], "value")
58-
XCTAssertEqual(request?.headers["X-Client-Info"], "functions-swift/\(Functions.version)")
57+
XCTAssertEqual(request?.headers[.init("Apikey")!], apiKey)
58+
XCTAssertEqual(request?.headers[.init("X-Custom-Key")!], "value")
59+
XCTAssertEqual(request?.headers[.init("X-Client-Info")!], "functions-swift/\(Functions.version)")
5960
}
6061

6162
func testInvokeWithCustomMethod() async throws {
@@ -109,7 +110,7 @@ final class FunctionsClientTests: XCTestCase {
109110
try await sut.invoke("hello-world")
110111

111112
let request = await http.receivedRequests.last
112-
XCTAssertEqual(request?.headers["x-region"], "ca-central-1")
113+
XCTAssertEqual(request?.headers[.xRegion], "ca-central-1")
113114
}
114115

115116
func testInvokeWithRegion() async throws {
@@ -126,7 +127,7 @@ final class FunctionsClientTests: XCTestCase {
126127
try await sut.invoke("hello-world", options: .init(region: .caCentral1))
127128

128129
let request = await http.receivedRequests.last
129-
XCTAssertEqual(request?.headers["x-region"], "ca-central-1")
130+
XCTAssertEqual(request?.headers[.xRegion], "ca-central-1")
130131
}
131132

132133
func testInvokeWithoutRegion() async throws {
@@ -143,7 +144,7 @@ final class FunctionsClientTests: XCTestCase {
143144
try await sut.invoke("hello-world")
144145

145146
let request = await http.receivedRequests.last
146-
XCTAssertNil(request?.headers["x-region"])
147+
XCTAssertNil(request?.headers[.xRegion])
147148
}
148149

149150
func testInvoke_shouldThrow_URLError_badServerResponse() async {
@@ -190,7 +191,7 @@ final class FunctionsClientTests: XCTestCase {
190191
http: HTTPClientMock().any { _ in
191192
try .stub(
192193
body: Empty(),
193-
headers: ["x-relay-error": "true"]
194+
headers: [.xRelayError: "true"]
194195
)
195196
}
196197
)
@@ -206,16 +207,16 @@ final class FunctionsClientTests: XCTestCase {
206207

207208
func test_setAuth() {
208209
sut.setAuth(token: "access.token")
209-
XCTAssertEqual(sut.headers["Authorization"], "Bearer access.token")
210+
XCTAssertEqual(sut.headers[.authorization], "Bearer access.token")
210211
}
211212
}
212213

213-
extension HTTPResponse {
214+
extension Helpers.HTTPResponse {
214215
static func stub(
215216
body: any Encodable,
216217
statusCode: Int = 200,
217-
headers: HTTPHeaders = .init()
218-
) throws -> HTTPResponse {
218+
headers: HTTPFields = .init()
219+
) throws -> Helpers.HTTPResponse {
219220
let data = try JSONEncoder().encode(body)
220221
let response = HTTPURLResponse(
221222
url: URL(string: "http://127.0.0.1")!,

Tests/HelpersTests/HTTPHeadersTests.swift

-71
This file was deleted.

Tests/IntegrationTests/Potsgrest/PostgrestResourceEmbeddingTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ final class PostgrestResourceEmbeddingTests: XCTestCase {
7070
.eq("messages.channel_id", value: 1)
7171
.execute().value as AnyJSON
7272

73-
assertInlineSnapshot(of: res, as: .json) {
73+
assertInlineSnapshot(of: { res }, as: .json) {
7474
"""
7575
[
7676
{
@@ -110,7 +110,7 @@ final class PostgrestResourceEmbeddingTests: XCTestCase {
110110
.or("channel_id.eq.2,message.eq.Hello World 👋", referencedTable: "messages")
111111
.execute().value as AnyJSON
112112

113-
assertInlineSnapshot(of: res, as: .json) {
113+
assertInlineSnapshot(of: { res }, as: .json) {
114114
"""
115115
[
116116
{
@@ -299,7 +299,7 @@ final class PostgrestResourceEmbeddingTests: XCTestCase {
299299
.limit(1, referencedTable: "messages")
300300
.execute().value as AnyJSON
301301

302-
assertInlineSnapshot(of: res, as: .json) {
302+
assertInlineSnapshot(of: { res }, as: .json) {
303303
"""
304304
[
305305
{
@@ -339,7 +339,7 @@ final class PostgrestResourceEmbeddingTests: XCTestCase {
339339
.range(from: 1, to: 1, referencedTable: "messages")
340340
.execute().value as AnyJSON
341341

342-
assertInlineSnapshot(of: res, as: .json) {
342+
assertInlineSnapshot(of: { res }, as: .json) {
343343
"""
344344
[
345345
{

Tests/PostgRESTTests/PostgrestBuilderTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ final class PostgrestBuilderTests: XCTestCase {
1313

1414
func testCustomHeaderOnAPerCallBasis() throws {
1515
let postgrest1 = PostgrestClient(url: url, headers: ["apikey": "foo"], logger: nil)
16-
let postgrest2 = try postgrest1.rpc("void_func").setHeader(name: "apikey", value: "bar")
16+
let postgrest2 = try postgrest1.rpc("void_func").setHeader(name: .init("apikey")!, value: "bar")
1717

1818
// Original client object isn't affected
19-
XCTAssertEqual(postgrest1.from("users").select().mutableState.request.headers["apikey"], "foo")
19+
XCTAssertEqual(postgrest1.from("users").select().mutableState.request.headers[.init("apikey")!], "foo")
2020
// Derived client object uses new header value
21-
XCTAssertEqual(postgrest2.mutableState.request.headers["apikey"], "bar")
21+
XCTAssertEqual(postgrest2.mutableState.request.headers[.init("apikey")!], "bar")
2222
}
2323
}

Tests/RealtimeTests/RealtimeTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ final class RealtimeTests: XCTestCase {
265265
expectNoDifference(
266266
request?.headers,
267267
[
268-
"content-type": "application/json",
269-
"apikey": "anon.api.key",
270-
"authorization": "Bearer anon.api.key",
268+
.contentType: "application/json",
269+
.apiKey: "anon.api.key",
270+
.authorization: "Bearer anon.api.key",
271271
]
272272
)
273273

Tests/SupabaseTests/SupabaseClientTests.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ final class SupabaseClientTests: XCTestCase {
7878
XCTAssertEqual(realtimeURL.absoluteString, "https://project-ref.supabase.co/realtime/v1")
7979

8080
let realtimeOptions = client.realtimeV2.options
81-
let expectedRealtimeHeader = client._headers.merged(with: ["custom_realtime_header_key": "custom_realtime_header_value"])
81+
let expectedRealtimeHeader = client._headers.merging(with: [
82+
.init("custom_realtime_header_key")!: "custom_realtime_header_value"]
83+
)
8284
expectNoDifference(realtimeOptions.headers, expectedRealtimeHeader)
8385
XCTAssertIdentical(realtimeOptions.logger as? Logger, logger)
8486

0 commit comments

Comments
 (0)