@@ -10,7 +10,7 @@ final class AppTests: XCTestCase {
10
10
}
11
11
12
12
func setupAppForTesting( hookKey: String ? = nil ) async throws -> Application {
13
- let app = Application ( . testing)
13
+ let app = try await Application . make ( . testing)
14
14
let configuration = try ParseServerConfiguration ( app: app,
15
15
hostName: " hostName " ,
16
16
port: 8080 ,
@@ -35,49 +35,52 @@ final class AppTests: XCTestCase {
35
35
return app
36
36
}
37
37
38
- func testConfigRequiresKeys( ) throws {
39
- let app = Application ( . testing)
40
- defer { app. shutdown ( ) }
38
+ func testConfigRequiresKeys( ) async throws {
39
+ let app = try await Application . make ( . testing)
41
40
XCTAssertThrowsError ( try ParseServerConfiguration ( app: app) )
41
+ try await app. asyncShutdown ( )
42
42
}
43
43
44
- func testAllowInitConfigOnce( ) throws {
45
- let app = Application ( . testing)
46
- defer { app. shutdown ( ) }
44
+ func testAllowInitConfigOnce( ) async throws {
45
+ let app = try await Application . make ( . testing)
47
46
let configuration = try ParseServerConfiguration ( app: app,
48
47
hostName: " hostName " ,
49
48
port: 8080 ,
50
49
applicationId: " applicationId " ,
51
50
primaryKey: " primaryKey " ,
52
51
parseServerURLString: " primaryKey " )
53
52
XCTAssertNoThrow ( try setConfiguration ( configuration) )
53
+ try await app. asyncShutdown ( )
54
54
}
55
55
56
56
func testDoNotInitConfigTwice( ) async throws {
57
57
let app = try await setupAppForTesting ( )
58
- defer { app. shutdown ( ) }
59
58
let configuration = try ParseServerConfiguration ( app: app,
60
59
hostName: " hostName " ,
61
60
port: 8080 ,
62
61
applicationId: " applicationId " ,
63
62
primaryKey: " primaryKey " ,
64
63
parseServerURLString: " primaryKey " )
65
64
XCTAssertThrowsError ( try setConfiguration ( configuration) )
65
+ try await app. asyncShutdown ( )
66
66
}
67
67
68
68
func testFooBar( ) async throws {
69
69
let app = try await setupAppForTesting ( )
70
- defer { app. shutdown ( ) }
71
70
72
- try app. test ( . GET, " foo " , afterResponse: { res in
71
+ try await app. test (
72
+ . GET,
73
+ " foo "
74
+ ) { res async throws in
73
75
XCTAssertEqual ( res. status, . ok)
74
76
XCTAssertEqual ( res. body. string, " foo bar " )
75
- } )
77
+ }
78
+
79
+ try await app. asyncShutdown ( )
76
80
}
77
81
78
82
func testCheckServerHealth( ) async throws {
79
83
let app = try await setupAppForTesting ( )
80
- defer { app. shutdown ( ) }
81
84
82
85
XCTAssertGreaterThan ( configuration. parseServerURLStrings. count, 0 )
83
86
do {
@@ -86,6 +89,7 @@ final class AppTests: XCTestCase {
86
89
} catch {
87
90
XCTAssertTrue ( error. localizedDescription. contains ( " Unable to connect " ) )
88
91
}
92
+ try await app. asyncShutdown ( )
89
93
}
90
94
91
95
func testGetParseServerURLs( ) async throws {
@@ -106,7 +110,6 @@ final class AppTests: XCTestCase {
106
110
107
111
func testDeleteHooks( ) async throws {
108
112
let app = try await setupAppForTesting ( )
109
- defer { app. shutdown ( ) }
110
113
111
114
let urlString = " https://parse.com/parse "
112
115
guard let url = URL ( string: urlString) else {
@@ -132,31 +135,39 @@ final class AppTests: XCTestCase {
132
135
let currentTriggers2 = await configuration. hooks. getTriggers ( )
133
136
XCTAssertEqual ( currentFunctions2. count, 0 )
134
137
XCTAssertEqual ( currentTriggers2. count, 0 )
138
+ try await app. asyncShutdown ( )
135
139
}
136
140
137
141
func testFunctionWebhookKeyNotEqual( ) async throws {
138
142
let app = try await setupAppForTesting ( hookKey: " wow " )
139
- defer { app. shutdown ( ) }
140
143
141
- try app. test ( . POST, " hello " , afterResponse: { res in
144
+ try await app. test (
145
+ . POST,
146
+ " hello "
147
+ ) { res async throws in
142
148
XCTAssertEqual ( res. status, . ok)
143
149
XCTAssertTrue ( res. body. string. contains ( " Webhook keys " ) )
144
- } )
150
+ }
151
+
152
+ try await app. asyncShutdown ( )
145
153
}
146
154
147
155
func testTriggerWebhookKeyNotEqual( ) async throws {
148
156
let app = try await setupAppForTesting ( hookKey: " wow " )
149
- defer { app. shutdown ( ) }
150
157
151
- try app. test ( . POST, " score/save/before " , afterResponse: { res in
158
+ try await app. test (
159
+ . POST,
160
+ " score/save/before "
161
+ ) { res async throws in
152
162
XCTAssertEqual ( res. status, . ok)
153
163
XCTAssertTrue ( res. body. string. contains ( " Webhook keys " ) )
154
- } )
164
+ }
165
+
166
+ try await app. asyncShutdown ( )
155
167
}
156
168
157
169
func testMatchServerURLString( ) async throws {
158
170
let app = try await setupAppForTesting ( )
159
- defer { app. shutdown ( ) }
160
171
let urlString = " https://parse.com/parse "
161
172
let uri = URI ( stringLiteral: urlString)
162
173
let serverString = try serverURLString ( uri, parseServerURLStrings: [ urlString] )
@@ -171,21 +182,22 @@ final class AppTests: XCTestCase {
171
182
let serverString3 = try serverURLString ( uri,
172
183
parseServerURLStrings: configuration. parseServerURLStrings)
173
184
XCTAssertEqual ( serverString3, configuration. parseServerURLStrings. first)
185
+
186
+ try await app. asyncShutdown ( )
174
187
}
175
188
176
189
func testMatchServerURLStringThrowsError( ) async throws {
177
190
let app = try await setupAppForTesting ( )
178
191
Parse . configuration. parseServerURLStrings. removeAll ( )
179
- defer { app. shutdown ( ) }
180
192
let urlString = " https://parse.com/parse "
181
193
let uri = URI ( stringLiteral: urlString)
182
194
XCTAssertThrowsError ( try serverURLString ( uri,
183
195
parseServerURLStrings: configuration. parseServerURLStrings) )
196
+ try await app. asyncShutdown ( )
184
197
}
185
198
186
199
func testParseHookOptions( ) async throws {
187
200
let app = try await setupAppForTesting ( )
188
- defer { app. shutdown ( ) }
189
201
let installationId = " naw "
190
202
let urlString = " https://parse.com/parse "
191
203
Parse . configuration. parseServerURLStrings. append ( urlString)
@@ -208,6 +220,7 @@ final class AppTests: XCTestCase {
208
220
XCTAssertEqual ( options2. count, 2 )
209
221
XCTAssertTrue ( installationOption2. debugDescription. contains ( installationId) )
210
222
XCTAssertTrue ( serverURLOption. debugDescription. contains ( " \" \( urlString) \" " ) )
223
+ try await app. asyncShutdown ( )
211
224
}
212
225
213
226
func testHooksFunctions( ) async throws {
0 commit comments