Skip to content

Commit 434022c

Browse files
committed
Add test that all routes are mounted during configuration.
1 parent e5249b9 commit 434022c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Tests/AppTests/AppTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,42 @@ final class AppTests: XCTestCase {
3232
XCTAssertEqual(res.status, HTTPStatus.ok)
3333
}
3434
}
35+
36+
func test_routesAreMounted() throws {
37+
let app = try testApp()
38+
defer { app.shutdown() }
39+
40+
app.middleware.use(JSONAPIErrorMiddleware())
41+
42+
try addRoutes(app, hobbled: true)
43+
44+
let expectedRoutes = [
45+
["POST", "openapi_sources"],
46+
["GET", "openapi_sources"],
47+
["GET", "openapi_sources", ":id"],
48+
49+
["POST", "api_test_properties"],
50+
["GET", "api_test_properties"],
51+
["GET", "api_test_properties", ":id"],
52+
53+
["POST", "api_tests"],
54+
["GET", "api_tests"],
55+
["GET", "api_tests", ":id"],
56+
["GET", "api_tests", ":id", "files"],
57+
["GET", "api_tests", ":id", "logs"],
58+
59+
["GET", "api_test_messages", ":id"],
60+
61+
["GET", "watch"],
62+
63+
["GET", "docs"]
64+
]
65+
66+
for path in expectedRoutes {
67+
XCTAssert(app.routes.all.contains { route in [route.method.rawValue] + route.path.map(\.description) == path })
68+
}
69+
70+
// protect against adding routes without adding them to the test
71+
XCTAssertEqual(app.routes.all.count, expectedRoutes.count)
72+
}
3573
}

0 commit comments

Comments
 (0)