Files
ccn/Services/Website/Tests/Library/Cases/Public/Middlewares/LocalizationMiddlewareTests.swift
T
javier 79ecf311f4 Local environment configuration support for the Website service (#19)
This PR contains the work done to amend the `.env.local` handling for the Website service, plus other small fixes.

Reviewed-on: rock-n-code/loud-amsterdam#19
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2026-07-19 02:28:05 +00:00

56 lines
1.3 KiB
Swift

import HTTPTypes
import Hummingbird
import HummingbirdTesting
import NIOCore
import Testing
@testable import WebsiteLibrary
@Suite("LocalizationMiddleware middleware", .tags(.middleware))
struct LocalizationMiddlewareTests {
// MARK: Constants
private let app: Application = .init(router: {
let router = Router(context: WebsiteRequestContext.self)
router.addMiddleware {
LocalizationMiddleware()
}
router.get("language") { _, context in
context.language
}
return router
}())
// MARK: Functional tests
@Test
func `negotiates a supported language from the header`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/language",
method: .get,
headers: [.acceptLanguage: "en-US,en;q=0.9"]
) { response in
#expect(String(buffer: response.body) == "en")
}
}
}
@Test
func `falls back to the default without a header`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/language",
method: .get
) { response in
#expect(String(buffer: response.body) == "en")
}
}
}
}