Move functions to outer scope for clarity (S7721)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 01:01:29 +08:00
parent 5942c9ff51
commit e522bd0796
2 changed files with 44 additions and 36 deletions

View File

@@ -7,6 +7,32 @@ import { describe, it, expect, beforeEach } from "vitest";
import { decodeReturnTo } from "@/utils/returnToEncoding";
import { evaluateAuthNavigation } from "@/router/authGuard";
// Run the real auth guard decision logic from src/router/authGuard.ts
async function runGuard(to, options = {}) {
const { refreshSucceeds = true } = options;
return evaluateAuthNavigation(to, {
getCookie: (name) => {
const cookieArr = document.cookie.split(";");
for (const cookie of cookieArr) {
const c = cookie.trim();
if (c.startsWith(`${name}=`)) {
return c.slice(name.length + 1);
}
}
return null;
},
refreshSession: async () => {
if (!refreshSucceeds) {
throw new Error("refresh failed");
}
},
setLoginMarker: () => {
document.cookie = "isLuciaLoggedIn=true";
},
encodeReturnTo: (path) => btoa(path),
});
}
describe("router beforeEach guard logic", () => {
beforeEach(() => {
// Clear cookies
@@ -18,32 +44,6 @@ describe("router beforeEach guard logic", () => {
});
});
// Run the real auth guard decision logic from src/router/authGuard.ts
async function runGuard(to, options = {}) {
const { refreshSucceeds = true } = options;
return evaluateAuthNavigation(to, {
getCookie: (name) => {
const cookieArr = document.cookie.split(";");
for (const cookie of cookieArr) {
const c = cookie.trim();
if (c.startsWith(`${name}=`)) {
return c.slice(name.length + 1);
}
}
return null;
},
refreshSession: async () => {
if (!refreshSucceeds) {
throw new Error("refresh failed");
}
},
setLoginMarker: () => {
document.cookie = "isLuciaLoggedIn=true";
},
encodeReturnTo: (path) => btoa(path),
});
}
it("redirects logged-in user from Login to Files", () => {
document.cookie = "isLuciaLoggedIn=true";
document.cookie = "luciaToken=token";