Skip to content

Commit 198e2dc

Browse files
committed
Convert RoutesTests
1 parent c4667ab commit 198e2dc

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

Tests/AppTests/RoutesTests.swift

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,94 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import Foundation
16+
1517
@testable import App
1618

1719
import Dependencies
18-
import XCTVapor
20+
import Testing
1921

2022

21-
final class RoutesTests: AppTestCase {
23+
@Suite struct RoutesTests {
2224

23-
func test_documentation_images() async throws {
25+
@Test func documentation_images() async throws {
2426
try await withDependencies {
2527
$0.environment.awsDocsBucket = { "docs-bucket" }
2628
$0.httpClient.fetchDocumentation = App.HTTPClient.echoURL()
2729
} operation: {
28-
// MUT
29-
try await app.test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in
30-
// validation
31-
XCTAssertEqual(res.status, .ok)
32-
XCTAssertEqual(res.content.contentType?.description, "application/octet-stream")
33-
XCTAssertEqual(res.body.asString(), "/foo/bar/1.2.3/images/baz.png")
34-
}
35-
try await app.test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in
36-
// validation
37-
XCTAssertEqual(res.status, .ok)
38-
XCTAssertEqual(res.content.contentType?.description, "application/octet-stream")
39-
XCTAssertEqual(res.body.asString(), "/foo/bar/1.2.3/images/BAZ.png")
30+
try await withApp { app in
31+
// MUT
32+
try await app.test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in
33+
// validation
34+
#expect(res.status == .ok)
35+
#expect(res.content.contentType?.description == "application/octet-stream")
36+
#expect(res.body.asString() == "/foo/bar/1.2.3/images/baz.png")
37+
}
38+
try await app.test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in
39+
// validation
40+
#expect(res.status == .ok)
41+
#expect(res.content.contentType?.description == "application/octet-stream")
42+
#expect(res.body.asString() == "/foo/bar/1.2.3/images/BAZ.png")
43+
}
4044
}
4145
}
4246
}
4347

44-
func test_documentation_img() async throws {
48+
@Test func documentation_img() async throws {
4549
try await withDependencies {
4650
$0.environment.awsDocsBucket = { "docs-bucket" }
4751
$0.httpClient.fetchDocumentation = { @Sendable _ in .ok }
4852
} operation: {
49-
// MUT
50-
try await app.test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in
51-
// validation
52-
XCTAssertEqual(res.status, .ok)
53+
try await withApp { app in
54+
// MUT
55+
try await app.test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in
56+
// validation
57+
#expect(res.status == .ok)
58+
}
5359
}
5460
}
5561
}
5662

57-
func test_documentation_videos() async throws {
63+
@Test func documentation_videos() async throws {
5864
try await withDependencies {
5965
$0.environment.awsDocsBucket = { "docs-bucket" }
6066
$0.httpClient.fetchDocumentation = { @Sendable _ in .ok }
6167
} operation: {
62-
// MUT
63-
try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in
64-
// validation
65-
XCTAssertEqual(res.status, .ok)
68+
try await withApp { app in
69+
// MUT
70+
try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in
71+
// validation
72+
#expect(res.status == .ok)
73+
}
6674
}
6775
}
6876
}
6977

70-
func test_openapi() async throws {
71-
try await app.test(.GET, "openapi/openapi.json") { res async in
72-
XCTAssertEqual(res.status, .ok)
73-
struct Response: Codable, Equatable {
74-
var info: Info
75-
struct Info: Codable, Equatable {
76-
var title: String
78+
@Test func openapi() async throws {
79+
try await withApp { app in
80+
try await app.test(.GET, "openapi/openapi.json") { res async throws in
81+
#expect(res.status == .ok)
82+
struct Response: Codable, Equatable {
83+
var info: Info
84+
struct Info: Codable, Equatable {
85+
var title: String
86+
}
7787
}
88+
let decoded = try JSONDecoder().decode(Response.self, from: res.body)
89+
#expect(decoded == Response(info: .init(title: "Swift Package Index API")))
7890
}
79-
XCTAssertEqualJSON(res.body.asString(), Response(info: .init(title: "Swift Package Index API")))
8091
}
8192
}
8293

83-
func test_maintenanceMessage() throws {
84-
try withDependencies {
94+
@Test func maintenanceMessage() async throws {
95+
try await withDependencies {
8596
$0.environment.dbId = { nil }
8697
$0.environment.maintenanceMessage = { "MAINTENANCE_MESSAGE" }
8798
} operation: {
88-
89-
try app.test(.GET, "/") { res in
90-
XCTAssertContains(res.body.string, "MAINTENANCE_MESSAGE")
99+
try await withApp { app in
100+
try await app.test(.GET, "/") { res async in
101+
#expect(res.body.string.contains("MAINTENANCE_MESSAGE"))
102+
}
91103
}
92104
}
93105
}

0 commit comments

Comments
 (0)