Skip to content

Build your personal knowledge base with Trilium Notes

test: model Express request getter in logout spec (closes #11183)

dajiaohuangc42123ebf691
diff --git a/apps/server/src/routes/error_handlers.spec.ts b/apps/server/src/routes/error_handlers.spec.ts
index 7d319fe241..387b79374c 100644
--- a/apps/server/src/routes/error_handlers.spec.ts
+++ b/apps/server/src/routes/error_handlers.spec.ts
@@ -7,24 +7,22 @@ import {
} from "./error_handlers.js";
describe("isLogoutFormNavigation", () => {
+ const request = (accept: string) => ({
+ method: "POST",
+ path: "/logout",
+ headers: { accept },
+ is: () => "application/x-www-form-urlencoded",
+ get: (header: string) => header.toLowerCase() === "accept" ? accept : undefined
+ });
+
it("recognizes HTML form posts to logout", () => {
- const req = {
- method: "POST",
- path: "/logout",
- headers: { accept: "text/html,application/xhtml+xml" },
- is: () => "application/x-www-form-urlencoded"
- };
+ const req = request("text/html,application/xhtml+xml");
expect(isLogoutFormNavigation(req as never)).toBe(true);
});
it("does not classify API requests as navigations", () => {
- const req = {
- method: "POST",
- path: "/logout",
- headers: { accept: "application/json" },
- is: () => "application/x-www-form-urlencoded"
- };
+ const req = request("application/json");
expect(isLogoutFormNavigation(req as never)).toBe(false);
});