const __vite_ssr_import_0__ = await __vite_ssr_import__("/@fs/C:/Users/Admin/AppData/Local/npm-cache/_npx/69c381f8ad94b576/node_modules/vitest/dist/index.js", {"importedNames":["afterEach","describe","expect","it","vi"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("/web/src/shared/api/auth.ts", {"importedNames":["csrfToken","notifyIfUnauthorized","setUnauthorizedHandler","withCsrf"]});


(0,__vite_ssr_import_0__.afterEach)(() => {
	(0,__vite_ssr_import_1__.setUnauthorizedHandler)(null);
	document.cookie = "vc_csrf=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
});
(0,__vite_ssr_import_0__.describe)("csrfToken", () => {
	(0,__vite_ssr_import_0__.it)("finds the token among other cookies and decodes it", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.csrfToken)("a=1; vc_csrf=tok%2Fen; b=2")).toBe("tok/en");
	});
	(0,__vite_ssr_import_0__.it)("is empty when signed out", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.csrfToken)("a=1; b=2")).toBe("");
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.csrfToken)("")).toBe("");
	});
});
(0,__vite_ssr_import_0__.describe)("withCsrf", () => {
	const post = () => new Request("http://localhost/api/v1/engine:start", { method: "POST" });
	(0,__vite_ssr_import_0__.it)("adds the header to state-changing requests only", () => {
		document.cookie = "vc_csrf=abc; path=/";
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.withCsrf)(post()).headers.get("X-CSRF-Token")).toBe("abc");
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.withCsrf)(new Request("http://localhost/api/v1/clips")).headers.get("X-CSRF-Token")).toBeNull();
	});
	(0,__vite_ssr_import_0__.it)("sends nothing without a token", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.withCsrf)(post()).headers.get("X-CSRF-Token")).toBeNull();
	});
});
(0,__vite_ssr_import_0__.describe)("notifyIfUnauthorized", () => {
	const request = (path) => new Request(`http://localhost${path}`);
	(0,__vite_ssr_import_0__.it)("tells the app when the session ended", () => {
		const handler = __vite_ssr_import_0__.vi.fn();
		(0,__vite_ssr_import_1__.setUnauthorizedHandler)(handler);
		(0,__vite_ssr_import_1__.notifyIfUnauthorized)(request("/api/v1/clips"), new Response(null, { status: 401 }));
		(0,__vite_ssr_import_0__.expect)(handler).toHaveBeenCalledTimes(1);
	});
	(0,__vite_ssr_import_0__.it)("ignores other statuses and a wrong password at sign-in", () => {
		const handler = __vite_ssr_import_0__.vi.fn();
		(0,__vite_ssr_import_1__.setUnauthorizedHandler)(handler);
		(0,__vite_ssr_import_1__.notifyIfUnauthorized)(request("/api/v1/clips"), new Response(null, { status: 500 }));
		(0,__vite_ssr_import_1__.notifyIfUnauthorized)(request("/api/v1/auth/login"), new Response(null, { status: 401 }));
		(0,__vite_ssr_import_0__.expect)(handler).not.toHaveBeenCalled();
	});
});

//# vitestCache=W3siZmlsZSI6IjEiLCJpZCI6IjEiLCJpbXBvcnRzIjoiMiIsIm1hcHBpbmdzIjpmYWxzZSwiZGVwcyI6IjMiLCJkeW5hbWljRGVwcyI6IjQiLCJzdGF0aWNNb2NrcyI6bnVsbCwiaGFzQ292ZXJhZ2VEYXRhIjpmYWxzZX0sIkQ6L0dpdEh1Yi9WaWNlQ3V0L3dlYi9zcmMvc2hhcmVkL2FwaS9hdXRoLnRlc3QudHMiLHsidXJscyI6IjUiLCJpZHMiOiI2In0sWyI3IiwiOCJdLFtdLFsiNyIsIjgiXSx7fSwiL0Bmcy9DOi9Vc2Vycy9BZG1pbi9BcHBEYXRhL0xvY2FsL25wbS1jYWNoZS9fbnB4LzY5YzM4MWY4YWQ5NGI1NzYvbm9kZV9tb2R1bGVzL3ZpdGVzdC9kaXN0L2luZGV4LmpzIiwiL3dlYi9zcmMvc2hhcmVkL2FwaS9hdXRoLnRzIl0=
//# vitestSourceMap={"version":3,"mappings":"AAAA;AAEA;;;AAEA,0CAAgB;C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AC,CAAC;EAClF,+CAAqB,QAAQ,oBAAoB,GAAG,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC;EACvF,iCAAO,OAAO,CAAC,CAAC,IAAI,iBAAiB;CACvC,CAAC;AACH,CAAC","names":[],"ignoreList":[],"sources":["auth.test.ts"],"sourcesContent":["import { afterEach, describe, expect, it, vi } from \"vitest\";\n\nimport { csrfToken, notifyIfUnauthorized, setUnauthorizedHandler, withCsrf } from \"./auth\";\n\nafterEach(() => {\n  setUnauthorizedHandler(null);\n  document.cookie = \"vc_csrf=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/\";\n});\n\ndescribe(\"csrfToken\", () => {\n  it(\"finds the token among other cookies and decodes it\", () => {\n    expect(csrfToken(\"a=1; vc_csrf=tok%2Fen; b=2\")).toBe(\"tok/en\");\n  });\n\n  it(\"is empty when signed out\", () => {\n    expect(csrfToken(\"a=1; b=2\")).toBe(\"\");\n    expect(csrfToken(\"\")).toBe(\"\");\n  });\n});\n\ndescribe(\"withCsrf\", () => {\n  const post = () => new Request(\"http://localhost/api/v1/engine:start\", { method: \"POST\" });\n\n  it(\"adds the header to state-changing requests only\", () => {\n    document.cookie = \"vc_csrf=abc; path=/\";\n    expect(withCsrf(post()).headers.get(\"X-CSRF-Token\")).toBe(\"abc\");\n    expect(withCsrf(new Request(\"http://localhost/api/v1/clips\")).headers.get(\"X-CSRF-Token\")).toBeNull();\n  });\n\n  it(\"sends nothing without a token\", () => {\n    expect(withCsrf(post()).headers.get(\"X-CSRF-Token\")).toBeNull();\n  });\n});\n\ndescribe(\"notifyIfUnauthorized\", () => {\n  const request = (path: string) => new Request(`http://localhost${path}`);\n\n  it(\"tells the app when the session ended\", () => {\n    const handler = vi.fn();\n    setUnauthorizedHandler(handler);\n    notifyIfUnauthorized(request(\"/api/v1/clips\"), new Response(null, { status: 401 }));\n    expect(handler).toHaveBeenCalledTimes(1);\n  });\n\n  it(\"ignores other statuses and a wrong password at sign-in\", () => {\n    const handler = vi.fn();\n    setUnauthorizedHandler(handler);\n    notifyIfUnauthorized(request(\"/api/v1/clips\"), new Response(null, { status: 500 }));\n    notifyIfUnauthorized(request(\"/api/v1/auth/login\"), new Response(null, { status: 401 }));\n    expect(handler).not.toHaveBeenCalled();\n  });\n});\n"],"file":"/web/src/shared/api/auth.test.ts"}