Skip to content

Commit 16f4cf5

Browse files
refactor: Break out test utilities
1 parent 9893bb7 commit 16f4cf5

3 files changed

Lines changed: 33 additions & 28 deletions

File tree

Tests/GraphQLHummingbirdTests/HTTPTests.swift

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct HTTPTests {
2121
try await client.execute(
2222
uri: "/graphql",
2323
method: .post,
24-
headers: defaultHeaders,
24+
headers: jsonGraphQLHeaders,
2525
body: .init(data: JSONEncoder().encode(GraphQLRequest(query: "{ hello }")))
2626
) { response in
2727
#expect(response.status == .ok)
@@ -65,7 +65,7 @@ struct HTTPTests {
6565
try await client.execute(
6666
uri: "/graphql",
6767
method: .post,
68-
headers: defaultHeaders,
68+
headers: jsonGraphQLHeaders,
6969
body: .init(data: JSONEncoder().encode(GraphQLRequest(
7070
query: "query Greet($name: String) { greet(name: $name) }",
7171
variables: ["name": "Alice"]
@@ -113,7 +113,7 @@ struct HTTPTests {
113113
try await client.execute(
114114
uri: "/graphql",
115115
method: .post,
116-
headers: defaultHeaders,
116+
headers: jsonGraphQLHeaders,
117117
body: .init(data: JSONEncoder().encode(GraphQLRequest(query: "{ contextMessage }")))
118118
) { response in
119119
#expect(response.status == .ok)
@@ -275,7 +275,7 @@ struct HTTPTests {
275275
try await client.execute(
276276
uri: "/graphql?query=%7Bhello%7D",
277277
method: .get,
278-
headers: defaultHeaders
278+
headers: jsonGraphQLHeaders
279279
) { response in
280280
#expect(response.status == .ok)
281281

@@ -302,7 +302,7 @@ struct HTTPTests {
302302
try await client.execute(
303303
uri: "/graphql?query=%7Bhello%7D",
304304
method: .get,
305-
headers: defaultHeaders
305+
headers: jsonGraphQLHeaders
306306
) { response in
307307
#expect(response.status == .methodNotAllowed)
308308
}
@@ -348,25 +348,4 @@ struct HTTPTests {
348348
}
349349
}
350350
}
351-
352-
let defaultHeaders: HTTPFields = [
353-
.accept: MediaType.applicationJsonGraphQL.description,
354-
.contentType: MediaType.applicationJsonGraphQL.description,
355-
]
356-
357-
let helloWorldSchema = try! GraphQLSchema(
358-
query: GraphQLObjectType(
359-
name: "Query",
360-
fields: [
361-
"hello": GraphQLField(
362-
type: GraphQLString,
363-
resolve: { _, _, _, _ in
364-
"World"
365-
}
366-
),
367-
]
368-
)
369-
)
370-
371-
struct EmptyContext: Sendable {}
372351
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import GraphQL
2+
import Hummingbird
3+
4+
let jsonGraphQLHeaders: HTTPFields = [
5+
.accept: MediaType.applicationJsonGraphQL.description,
6+
.contentType: MediaType.applicationJsonGraphQL.description,
7+
]
8+
9+
let jsonHeaders: HTTPFields = [
10+
.accept: MediaType.applicationJson.description,
11+
.contentType: MediaType.applicationJson.description,
12+
]
13+
14+
let helloWorldSchema = try! GraphQLSchema(
15+
query: GraphQLObjectType(
16+
name: "Query",
17+
fields: [
18+
"hello": GraphQLField(
19+
type: GraphQLString,
20+
resolve: { _, _, _, _ in
21+
"World"
22+
}
23+
),
24+
]
25+
)
26+
)
27+
28+
struct EmptyContext: Sendable {}

Tests/GraphQLHummingbirdTests/WebSocketTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ struct WebSocketTests {
206206
}
207207
}
208208

209-
struct EmptyContext: Sendable {}
210-
211209
struct TestWebSocketContext: WebSocketRequestContext, RequestContext {
212210
typealias GraphQLContext = EmptyContext
213211
var coreContext: Hummingbird.CoreRequestContextStorage

0 commit comments

Comments
 (0)