Fix inconsistent line endings across all project files for cross-environment consistency. Add complete unit test suite covering core utilities, API routes, and server services. Add Playwright E2E test setup with smoke, auth, and agent API tests. Update all project configuration files to match standardized formatting. Fix MCP API error handling to properly propagate HTTP status codes and use correct JSON-RPC error codes. Add VSCode workspace configuration, extensions, and example MCP config files. Update .gitignore to exclude new test and build artifacts.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
|
|
// Mock the pocketbase module so getAdminPocketBase doesn't try to open a socket.
|
|
const authWithPassword = vi.fn().mockResolvedValue({ token: "mock-token" });
|
|
vi.mock("pocketbase", () => {
|
|
// Must be a class (or function) because the production code does `new PocketBase(url)`.
|
|
const FakePocketBase = vi.fn().mockImplementation(function () {
|
|
return {
|
|
collection: () => ({
|
|
authWithPassword,
|
|
}),
|
|
};
|
|
});
|
|
return { default: FakePocketBase };
|
|
});
|
|
|
|
import { getAdminPocketBase } from "./pocketbase-admin";
|
|
|
|
describe("getAdminPocketBase", () => {
|
|
const ORIGINAL_EMAIL = process.env.PB_ADMIN_EMAIL;
|
|
const ORIGINAL_PASSWORD = process.env.PB_ADMIN_PASSWORD;
|
|
|
|
beforeEach(() => {
|
|
process.env.PB_ADMIN_EMAIL = "admin@example.com";
|
|
process.env.PB_ADMIN_PASSWORD = "secret";
|
|
authWithPassword.mockClear();
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (ORIGINAL_EMAIL === undefined) delete process.env.PB_ADMIN_EMAIL;
|
|
else process.env.PB_ADMIN_EMAIL = ORIGINAL_EMAIL;
|
|
if (ORIGINAL_PASSWORD === undefined) delete process.env.PB_ADMIN_PASSWORD;
|
|
else process.env.PB_ADMIN_PASSWORD = ORIGINAL_PASSWORD;
|
|
});
|
|
|
|
it("returns a PocketBase instance and authenticates with the admin credentials", async () => {
|
|
const pb = await getAdminPocketBase();
|
|
expect(pb).toBeDefined();
|
|
expect(authWithPassword).toHaveBeenCalledWith("admin@example.com", "secret");
|
|
});
|
|
|
|
it("throws a clear error when admin env vars are missing", async () => {
|
|
delete process.env.PB_ADMIN_EMAIL;
|
|
delete process.env.PB_ADMIN_PASSWORD;
|
|
await expect(getAdminPocketBase()).rejects.toThrow(
|
|
/PB_ADMIN_EMAIL and PB_ADMIN_PASSWORD are required/
|
|
);
|
|
});
|
|
});
|