Updated the LocalizationMiddleware middleware in the Infrastructure package to read explicit language requests.

This commit is contained in:
2026-08-30 19:03:52 +02:00
parent 6c75d5e743
commit 79cfb42fbb
3 changed files with 67 additions and 6 deletions
@@ -25,6 +25,9 @@ struct LocalizationMiddlewareTests {
router.get("language") { _, context in
context.language
}
router.get("de/language") { _, context in
context.language
}
return router
}())
@@ -69,4 +72,44 @@ struct LocalizationMiddlewareTests {
}
}
@Test
func `honours a supported lang query parameter over the header`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/language?lang=de",
method: .get,
headers: [.acceptLanguage: "en"]
) { response in
#expect(String(buffer: response.body) == "de")
}
}
}
/// A language's whole URL prefix answers in its language, so its not-found page does too.
@Test
func `pins the language a leading path segment names over the header`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/de/language",
method: .get,
headers: [.acceptLanguage: "en"]
) { response in
#expect(String(buffer: response.body) == "de")
}
}
}
@Test
func `negotiates the header when the lang query parameter is unsupported`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/language?lang=fr",
method: .get,
headers: [.acceptLanguage: "de"]
) { response in
#expect(String(buffer: response.body) == "de")
}
}
}
}