mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 19:15:44 +01:00
fix: resolve Prettier markdown code block parsing errors
- Fix syntax errors in skills markdown files (.github/skills, .opencode/skills) - Change typescript to tsx for code blocks with JSX - Replace ellipsis (...) in array examples with valid syntax - Separate CSS from TypeScript into distinct code blocks - Convert JavaScript object examples to valid JSON in docs - Fix enum definitions with proper comma separation
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { NextRequest } from "next/server";
|
||||
import { hash } from "bcryptjs";
|
||||
|
||||
// Mock getServerSession
|
||||
const mockGetServerSession = vi.fn();
|
||||
vi.mock("next-auth", () => ({
|
||||
getServerSession: () => mockGetServerSession(),
|
||||
// Mock neonAuth from lib/auth/server
|
||||
const mockNeonAuth = vi.fn();
|
||||
vi.mock("../../lib/auth/server", () => ({
|
||||
neonAuth: () => mockNeonAuth(),
|
||||
getAuthenticatedPlatformUser: () => mockNeonAuth(),
|
||||
hasPlatformAccess: vi.fn(() => true),
|
||||
isPlatformRole: vi.fn((role: string) =>
|
||||
["PLATFORM_SUPER_ADMIN", "PLATFORM_ADMIN", "PLATFORM_SUPPORT"].includes(
|
||||
role
|
||||
)
|
||||
),
|
||||
}));
|
||||
|
||||
// Mock database
|
||||
@@ -42,7 +47,7 @@ describe("Platform API Endpoints", () => {
|
||||
|
||||
describe("Authentication Requirements", () => {
|
||||
it("should require platform authentication", async () => {
|
||||
mockGetServerSession.mockResolvedValue(null);
|
||||
mockNeonAuth.mockResolvedValue({ user: null });
|
||||
|
||||
// Test that endpoints check for authentication
|
||||
const endpoints = [
|
||||
@@ -55,26 +60,28 @@ describe("Platform API Endpoints", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should require platform user flag", () => {
|
||||
const regularUserSession = {
|
||||
user: {
|
||||
email: "regular@user.com",
|
||||
isPlatformUser: false,
|
||||
},
|
||||
expires: new Date().toISOString(),
|
||||
it("should require platform user role", () => {
|
||||
const regularUser = {
|
||||
id: "1",
|
||||
email: "regular@user.com",
|
||||
role: "USER",
|
||||
companyId: "company-123",
|
||||
};
|
||||
|
||||
const platformUserSession = {
|
||||
user: {
|
||||
email: "admin@notso.ai",
|
||||
isPlatformUser: true,
|
||||
platformRole: "SUPER_ADMIN",
|
||||
},
|
||||
expires: new Date().toISOString(),
|
||||
const platformUser = {
|
||||
id: "2",
|
||||
email: "admin@notso.ai",
|
||||
role: "PLATFORM_SUPER_ADMIN",
|
||||
companyId: null,
|
||||
};
|
||||
|
||||
expect(regularUserSession.user.isPlatformUser).toBe(false);
|
||||
expect(platformUserSession.user.isPlatformUser).toBe(true);
|
||||
const isPlatformRole = (role: string) =>
|
||||
["PLATFORM_SUPER_ADMIN", "PLATFORM_ADMIN", "PLATFORM_SUPPORT"].includes(
|
||||
role
|
||||
);
|
||||
|
||||
expect(isPlatformRole(regularUser.role)).toBe(false);
|
||||
expect(isPlatformRole(platformUser.role)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -117,11 +124,10 @@ describe("Platform API Endpoints", () => {
|
||||
expect(result[0]._count).toHaveProperty("users");
|
||||
});
|
||||
|
||||
it("should create company with admin user", async () => {
|
||||
it("should create company with admin user placeholder", async () => {
|
||||
const newCompany = {
|
||||
id: "123",
|
||||
name: "New Company",
|
||||
email: "admin@newcompany.com",
|
||||
status: "ACTIVE",
|
||||
maxUsers: 10,
|
||||
createdAt: new Date(),
|
||||
@@ -132,13 +138,12 @@ describe("Platform API Endpoints", () => {
|
||||
id: "456",
|
||||
email: "admin@newcompany.com",
|
||||
name: "Admin User",
|
||||
hashedPassword: "hashed_password",
|
||||
role: "ADMIN",
|
||||
companyId: "123",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
invitedBy: null,
|
||||
invitedAt: null,
|
||||
invitedBy: "platform@notso.ai",
|
||||
invitedAt: new Date(),
|
||||
};
|
||||
|
||||
mockDb.company.create.mockResolvedValue({
|
||||
@@ -149,13 +154,13 @@ describe("Platform API Endpoints", () => {
|
||||
const result = await mockDb.company.create({
|
||||
data: {
|
||||
name: "New Company",
|
||||
email: "admin@newcompany.com",
|
||||
users: {
|
||||
create: {
|
||||
email: "admin@newcompany.com",
|
||||
name: "Admin User",
|
||||
hashedPassword: "hashed_password",
|
||||
role: "ADMIN",
|
||||
invitedBy: "platform@notso.ai",
|
||||
invitedAt: new Date(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -7,16 +7,21 @@ import { axe, toHaveNoViolations } from "jest-axe";
|
||||
import { ThemeProvider } from "@/components/theme-provider";
|
||||
import UserManagementPage from "@/app/dashboard/users/page";
|
||||
import SessionViewPage from "@/app/dashboard/sessions/[id]/page";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useParams } from "next/navigation";
|
||||
|
||||
// Extend Jest matchers
|
||||
expect.extend(toHaveNoViolations);
|
||||
|
||||
// Mock auth client
|
||||
const mockUseSession = vi.fn();
|
||||
vi.mock("@/lib/auth/client", () => ({
|
||||
authClient: {
|
||||
useSession: () => mockUseSession(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("next-auth/react");
|
||||
vi.mock("next/navigation");
|
||||
const mockUseSession = vi.mocked(useSession);
|
||||
const mockUseParams = vi.mocked(useParams);
|
||||
|
||||
// Mock fetch
|
||||
@@ -39,8 +44,8 @@ describe("Accessibility Tests", () => {
|
||||
describe("User Management Page Accessibility", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -183,8 +188,8 @@ describe("Accessibility Tests", () => {
|
||||
describe("Basic Accessibility Compliance", () => {
|
||||
it("should have basic accessibility features", async () => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -214,8 +219,8 @@ describe("Accessibility Tests", () => {
|
||||
describe("Interactive Elements", () => {
|
||||
it("should have focusable interactive elements", async () => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -246,8 +251,8 @@ describe("Accessibility Tests", () => {
|
||||
describe("Dark Mode Accessibility", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
|
||||
@@ -189,9 +189,8 @@ describe("Environment Management", () => {
|
||||
process.env.SESSION_PROCESSING_CONCURRENCY = "8";
|
||||
|
||||
vi.resetModules();
|
||||
const { getSchedulerConfig: freshGetSchedulerConfig } = await import(
|
||||
"../../lib/env"
|
||||
);
|
||||
const { getSchedulerConfig: freshGetSchedulerConfig } =
|
||||
await import("../../lib/env");
|
||||
|
||||
const config = freshGetSchedulerConfig();
|
||||
|
||||
@@ -210,9 +209,8 @@ describe("Environment Management", () => {
|
||||
delete process.env.IMPORT_PROCESSING_INTERVAL;
|
||||
|
||||
vi.resetModules();
|
||||
const { getSchedulerConfig: freshGetSchedulerConfig } = await import(
|
||||
"../../lib/env"
|
||||
);
|
||||
const { getSchedulerConfig: freshGetSchedulerConfig } =
|
||||
await import("../../lib/env");
|
||||
|
||||
const config = freshGetSchedulerConfig();
|
||||
|
||||
|
||||
@@ -3,16 +3,21 @@
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useParams } from "next/navigation";
|
||||
import UserManagementPage from "@/app/dashboard/users/page";
|
||||
import SessionViewPage from "@/app/dashboard/sessions/[id]/page";
|
||||
import ModernDonutChart from "@/components/charts/donut-chart";
|
||||
|
||||
// Mock auth client
|
||||
const mockUseSession = vi.fn();
|
||||
vi.mock("@/lib/auth/client", () => ({
|
||||
authClient: {
|
||||
useSession: () => mockUseSession(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("next-auth/react");
|
||||
vi.mock("next/navigation");
|
||||
const mockUseSession = vi.mocked(useSession);
|
||||
const mockUseParams = vi.mocked(useParams);
|
||||
|
||||
// Mock fetch
|
||||
@@ -22,8 +27,8 @@ describe("Keyboard Navigation Tests", () => {
|
||||
describe("User Management Page Keyboard Navigation", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -189,8 +194,8 @@ describe("Keyboard Navigation Tests", () => {
|
||||
describe("Session Details Page Keyboard Navigation", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
mockUseParams.mockReturnValue({
|
||||
@@ -346,8 +351,8 @@ describe("Keyboard Navigation Tests", () => {
|
||||
describe("Focus Management", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -427,8 +432,8 @@ describe("Keyboard Navigation Tests", () => {
|
||||
describe("Screen Reader Support", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
@@ -456,7 +461,7 @@ describe("Keyboard Navigation Tests", () => {
|
||||
// Test loading state announcement
|
||||
mockUseSession.mockReturnValue({
|
||||
data: null,
|
||||
status: "loading",
|
||||
isPending: true,
|
||||
});
|
||||
|
||||
render(<UserManagementPage />);
|
||||
@@ -507,8 +512,8 @@ describe("Keyboard Navigation Tests", () => {
|
||||
});
|
||||
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
// Mock modules before imports
|
||||
vi.mock("next-auth/react", () => ({
|
||||
useSession: vi.fn(),
|
||||
SessionProvider: ({ children }: { children: React.ReactNode }) => children,
|
||||
// Mock auth client
|
||||
vi.mock("../../lib/auth/client", () => ({
|
||||
authClient: {
|
||||
useSession: vi.fn(() => ({
|
||||
data: { session: null, user: null },
|
||||
isPending: false,
|
||||
})),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
@@ -22,30 +26,37 @@ describe("Platform Dashboard", () => {
|
||||
|
||||
describe("Authentication", () => {
|
||||
it("should require platform user authentication", () => {
|
||||
// Test that the dashboard checks for platform user authentication
|
||||
const mockSession = {
|
||||
user: {
|
||||
email: "admin@notso.ai",
|
||||
isPlatformUser: true,
|
||||
platformRole: "SUPER_ADMIN",
|
||||
},
|
||||
expires: new Date().toISOString(),
|
||||
// Test that the dashboard checks for platform user role
|
||||
const platformUser = {
|
||||
id: "1",
|
||||
email: "admin@notso.ai",
|
||||
role: "PLATFORM_SUPER_ADMIN",
|
||||
companyId: null,
|
||||
};
|
||||
|
||||
expect(mockSession.user.isPlatformUser).toBe(true);
|
||||
expect(mockSession.user.platformRole).toBeTruthy();
|
||||
const isPlatformRole = (role: string) =>
|
||||
["PLATFORM_SUPER_ADMIN", "PLATFORM_ADMIN", "PLATFORM_SUPPORT"].includes(
|
||||
role
|
||||
);
|
||||
|
||||
expect(isPlatformRole(platformUser.role)).toBe(true);
|
||||
expect(platformUser.companyId).toBeNull();
|
||||
});
|
||||
|
||||
it("should not allow regular users", () => {
|
||||
const mockSession = {
|
||||
user: {
|
||||
email: "regular@user.com",
|
||||
isPlatformUser: false,
|
||||
},
|
||||
expires: new Date().toISOString(),
|
||||
const regularUser = {
|
||||
id: "2",
|
||||
email: "regular@user.com",
|
||||
role: "USER",
|
||||
companyId: "company-123",
|
||||
};
|
||||
|
||||
expect(mockSession.user.isPlatformUser).toBe(false);
|
||||
const isPlatformRole = (role: string) =>
|
||||
["PLATFORM_SUPER_ADMIN", "PLATFORM_ADMIN", "PLATFORM_SUPPORT"].includes(
|
||||
role
|
||||
);
|
||||
|
||||
expect(isPlatformRole(regularUser.role)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,20 +104,21 @@ describe("Platform Dashboard", () => {
|
||||
describe("Platform Roles", () => {
|
||||
it("should support all platform roles", () => {
|
||||
const roles = [
|
||||
{ role: "SUPER_ADMIN", canEdit: true },
|
||||
{ role: "ADMIN", canEdit: true },
|
||||
{ role: "SUPPORT", canEdit: false },
|
||||
{ role: "PLATFORM_SUPER_ADMIN", canEdit: true },
|
||||
{ role: "PLATFORM_ADMIN", canEdit: true },
|
||||
{ role: "PLATFORM_SUPPORT", canEdit: false },
|
||||
];
|
||||
|
||||
roles.forEach(({ role, canEdit }) => {
|
||||
const user = {
|
||||
id: "1",
|
||||
email: `${role.toLowerCase()}@notso.ai`,
|
||||
isPlatformUser: true,
|
||||
platformRole: role,
|
||||
role: role,
|
||||
companyId: null,
|
||||
};
|
||||
|
||||
expect(user.platformRole).toBe(role);
|
||||
if (role === "SUPER_ADMIN" || role === "ADMIN") {
|
||||
expect(user.role).toBe(role);
|
||||
if (role === "PLATFORM_SUPER_ADMIN" || role === "PLATFORM_ADMIN") {
|
||||
expect(canEdit).toBe(true);
|
||||
} else {
|
||||
expect(canEdit).toBe(false);
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import UserManagementPage from "@/app/dashboard/users/page";
|
||||
|
||||
// Mock next-auth
|
||||
vi.mock("next-auth/react");
|
||||
const mockUseSession = vi.mocked(useSession);
|
||||
// Mock auth client
|
||||
const mockUseSession = vi.fn();
|
||||
vi.mock("@/lib/auth/client", () => ({
|
||||
authClient: {
|
||||
useSession: () => mockUseSession(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock fetch
|
||||
const mockFetch = vi.fn();
|
||||
@@ -33,8 +36,13 @@ describe("UserManagementPage", () => {
|
||||
describe("Access Control", () => {
|
||||
it("should deny access for non-admin users", async () => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "USER" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "user@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
// Mock API to return user role
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ role: "USER", companyId: "123" }),
|
||||
});
|
||||
|
||||
render(<UserManagementPage />);
|
||||
@@ -47,8 +55,8 @@ describe("UserManagementPage", () => {
|
||||
|
||||
it("should allow access for admin users", async () => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
|
||||
render(<UserManagementPage />);
|
||||
@@ -61,7 +69,7 @@ describe("UserManagementPage", () => {
|
||||
it("should show loading state while checking authentication", () => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: null,
|
||||
status: "loading",
|
||||
isPending: true,
|
||||
});
|
||||
|
||||
render(<UserManagementPage />);
|
||||
@@ -73,8 +81,8 @@ describe("UserManagementPage", () => {
|
||||
describe("User List Display", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,8 +136,8 @@ describe("UserManagementPage", () => {
|
||||
describe("User Invitation Form", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -260,8 +268,8 @@ describe("UserManagementPage", () => {
|
||||
describe("Form Validation", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,8 +305,8 @@ describe("UserManagementPage", () => {
|
||||
describe("Accessibility", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -339,8 +347,8 @@ describe("UserManagementPage", () => {
|
||||
describe("Error Handling", () => {
|
||||
beforeEach(() => {
|
||||
mockUseSession.mockReturnValue({
|
||||
data: { user: { role: "ADMIN" } },
|
||||
status: "authenticated",
|
||||
data: { session: { id: "1" }, user: { email: "admin@example.com" } },
|
||||
isPending: false,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user