fix: add site_admin support to tournament permissions and fix session cache issues
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* Regression tests for the issue where tournament_admin users were redirected to login
|
||||
*/
|
||||
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
||||
import { canManageTournament, ownsTournament, hasRole, getManageableTournaments } from '@/lib/permissions';
|
||||
import { getSession } from '@/lib/auth-simple';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
@@ -44,6 +44,7 @@ const createMockUser = (id: string, email: string, role: string): User => ({
|
||||
// Helper to create mock tournament
|
||||
const createMockTournament = (id: number, ownerId: string | null): Event => ({
|
||||
id,
|
||||
event_id: null,
|
||||
name: 'Test Tournament',
|
||||
description: null,
|
||||
eventDate: new Date(),
|
||||
@@ -163,9 +164,12 @@ describe('Tournament Permissions', () => {
|
||||
describe('getManageableTournaments', () => {
|
||||
test('should return all tournaments for club_admin', async () => {
|
||||
vi.mocked(getSession).mockResolvedValue({
|
||||
user: { id: 'admin-1', email: 'admin@example.com', role: 'club_admin' },
|
||||
user: { id: 'admin-1', email: 'admin@example.com' },
|
||||
session: { token: 'test', expiresAt: new Date() }
|
||||
});
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue(
|
||||
createMockUser('admin-1', 'admin@example.com', 'club_admin')
|
||||
);
|
||||
|
||||
const mockTournaments = [
|
||||
createMockTournament(1, 'user-1'),
|
||||
@@ -185,9 +189,12 @@ describe('Tournament Permissions', () => {
|
||||
|
||||
test('should return only owned tournaments for tournament_admin', async () => {
|
||||
vi.mocked(getSession).mockResolvedValue({
|
||||
user: { id: 'tour-admin-1', email: 'tour@example.com', role: 'tournament_admin' },
|
||||
user: { id: 'tour-admin-1', email: 'tour@example.com' },
|
||||
session: { token: 'test', expiresAt: new Date() }
|
||||
});
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue(
|
||||
createMockUser('tour-admin-1', 'tour@example.com', 'tournament_admin')
|
||||
);
|
||||
|
||||
const mockTournaments = [
|
||||
createMockTournament(1, 'tour-admin-1'),
|
||||
@@ -209,9 +216,12 @@ describe('Tournament Permissions', () => {
|
||||
|
||||
test('should return only non-draft tournaments for players', async () => {
|
||||
vi.mocked(getSession).mockResolvedValue({
|
||||
user: { id: 'player-1', email: 'player@example.com', role: 'player' },
|
||||
user: { id: 'player-1', email: 'player@example.com' },
|
||||
session: { token: 'test', expiresAt: new Date() }
|
||||
});
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue(
|
||||
createMockUser('player-1', 'player@example.com', 'player')
|
||||
);
|
||||
|
||||
const mockTournaments = [
|
||||
createMockTournament(1, 'user-1'),
|
||||
|
||||
Reference in New Issue
Block a user