Skip to content

Commit

Permalink
feat: accept full locale as search param
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst committed Feb 21, 2025
1 parent 4bd4f11 commit fd31c67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ const pathParamsSchema = v.object({

const searchParamsSchema = v.object({
format: v.optional(v.picklist(["html", "markdown", "xhtml"]), "html"),
locale: v.optional(v.picklist(locales), "en"),
locale: v.optional(
v.pipe(
v.string(),
v.transform((input) => new Intl.Locale(input).language),
v.picklist(locales),
),
"en",
),
});

server.get("/:serviceId", async (req, res, next) => {
Expand Down
12 changes: 11 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ describe("imprint endpoint GET /:service-id", () => {
});
});

it("should respond with german markdown when ?locale=de&format=de query params are set", () => {
it("should respond with german text when ?locale=de-AT query param is set", () => {
const serviceId = 21966;
return request(server)
.get(`/${String(serviceId)}/?locale=de-AT`)
.expect(200)
.then((response) => {
assert.match(response.text, /<h2>Offenlegung/);
});
});

it("should respond with german markdown when ?locale=de&format=markdown query params are set", () => {
const serviceId = 21966;
return request(server)
.get(`/${String(serviceId)}/?locale=de&format=markdown`)
Expand Down

0 comments on commit fd31c67

Please sign in to comment.