Kept the prototype out of search engines in the Website service.

This commit is contained in:
javier committed 2026-09-21 17:36:39 +02:00
1 parent 359fe0d6ac
commit 326299fc35
12 files changed
+232 -44

No files matched your search

@@ -0,0 +1,43 @@
import Hummingbird
import HummingbirdTesting
import Infrastructure
import Testing
@testable import WebsiteLibrary
@Suite(
"NoIndexMiddleware middleware",
.tags(.type)
)
struct NoIndexMiddlewareTests {
// MARK: Functional tests
@Test
func `marks what is served, what redirects, and what fails`() async throws {
let router = Router(context: WebsiteRequestContext.self)
router.add(middleware: NoIndexMiddleware())
router.get("/page") { _, _ in "A page" }
router.get("/moved") { _, _ in Response.redirect(to: "/page") }
router.get("/forbidden") { _, _ -> String in throw HTTPError(.forbidden) }
router.get("/marked") { _, _ in
Response(status: .ok, headers: [.robotsTag: "noindex"])
}
try await Application(router: router).test(.router) { client in
for (uri, status) in [("/page", HTTPResponse.Status.ok), ("/moved", .seeOther), ("/forbidden", .forbidden), ("/missing", .notFound)] {
try await client.execute(uri: uri, method: .get) { response in
#expect(response.status == status)
#expect(response.headers[.robotsTag] == "noindex, nofollow")
}
}
// One mark, not two: a response that came marked is marked over.
try await client.execute(uri: "/marked", method: .get) { response in
#expect(response.headers[values: .robotsTag] == ["noindex, nofollow"])
}
}
}
}