wip
This commit is contained in:
@@ -7,7 +7,8 @@ import DriverProfile from '@/components/drivers/DriverProfile';
|
||||
import Button from '@/components/ui/Button';
|
||||
import Card from '@/components/ui/Card';
|
||||
import Breadcrumbs from '@/components/layout/Breadcrumbs';
|
||||
import { EntityMappers, DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
|
||||
export default function DriverDetailPage() {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -17,7 +17,7 @@ import { Standing } from '@gridpilot/racing/domain/entities/Standing';
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { getLeagueRepository, getRaceRepository, getDriverRepository, getStandingRepository } from '@/lib/di-container';
|
||||
import { getMembership, isOwnerOrAdmin, getCurrentDriverId } from '@gridpilot/racing/application';
|
||||
import { getMembership, isOwnerOrAdmin, getCurrentDriverId } from '@/lib/racingLegacyFacade';
|
||||
|
||||
export default function LeagueDetailPage() {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -4,7 +4,8 @@ import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { getDriverRepository } from '@/lib/di-container';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { EntityMappers, DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import CreateDriverForm from '@/components/drivers/CreateDriverForm';
|
||||
import Card from '@/components/ui/Card';
|
||||
import Button from '@/components/ui/Button';
|
||||
@@ -14,7 +15,7 @@ import ProfileRaceHistory from '@/components/drivers/ProfileRaceHistory';
|
||||
import ProfileSettings from '@/components/drivers/ProfileSettings';
|
||||
import CareerHighlights from '@/components/drivers/CareerHighlights';
|
||||
import RatingBreakdown from '@/components/drivers/RatingBreakdown';
|
||||
import { getDriverTeam, getCurrentDriverId } from '@gridpilot/racing/application';
|
||||
import { getDriverTeam, getCurrentDriverId } from '@/lib/racingLegacyFacade';
|
||||
|
||||
type Tab = 'overview' | 'statistics' | 'history' | 'settings';
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
registerForRace,
|
||||
withdrawFromRace,
|
||||
getRegisteredDrivers,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
import CompanionStatus from '@/components/alpha/CompanionStatus';
|
||||
import CompanionInstructions from '@/components/alpha/CompanionInstructions';
|
||||
import Breadcrumbs from '@/components/layout/Breadcrumbs';
|
||||
@@ -71,7 +71,7 @@ export default function RaceDetailPage() {
|
||||
const driverRepo = getDriverRepository();
|
||||
const registeredDriverIds = getRegisteredDrivers(raceId);
|
||||
const drivers = await Promise.all(
|
||||
registeredDriverIds.map(id => driverRepo.findById(id))
|
||||
registeredDriverIds.map((id: string) => driverRepo.findById(id))
|
||||
);
|
||||
setEntryList(
|
||||
drivers.filter((d: Driver | null): d is Driver => d !== null)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useParams } from 'next/navigation';
|
||||
import Card from '@/components/ui/Card';
|
||||
import Button from '@/components/ui/Button';
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
removeTeamMember,
|
||||
updateTeamMemberRole,
|
||||
TeamRole,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
type Tab = 'overview' | 'roster' | 'standings' | 'admin';
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function TeamDetailPage() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
|
||||
const loadTeamData = () => {
|
||||
const loadTeamData = useCallback(() => {
|
||||
const teamData = getTeam(teamId);
|
||||
if (!teamData) {
|
||||
setLoading(false);
|
||||
@@ -48,11 +48,11 @@ export default function TeamDetailPage() {
|
||||
setMemberships(teamMemberships);
|
||||
setIsAdmin(adminStatus);
|
||||
setLoading(false);
|
||||
};
|
||||
}, [teamId]);
|
||||
|
||||
useEffect(() => {
|
||||
loadTeamData();
|
||||
}, [teamId]);
|
||||
}, [loadTeamData]);
|
||||
|
||||
const handleUpdate = () => {
|
||||
loadTeamData();
|
||||
|
||||
@@ -7,7 +7,7 @@ import Button from '@/components/ui/Button';
|
||||
import Input from '@/components/ui/Input';
|
||||
import Card from '@/components/ui/Card';
|
||||
import CreateTeamForm from '@/components/teams/CreateTeamForm';
|
||||
import { getAllTeams, getTeamMembers, type Team } from '@gridpilot/racing/application';
|
||||
import { getAllTeams, getTeamMembers, type Team } from '@/lib/racingLegacyFacade';
|
||||
|
||||
export default function TeamsPage() {
|
||||
const router = useRouter();
|
||||
|
||||
1
apps/website/components/alpha/ScheduleRaceForm.tsx
Normal file
1
apps/website/components/alpha/ScheduleRaceForm.tsx
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from '../leagues/ScheduleRaceForm';
|
||||
@@ -1,13 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import Card from '../ui/Card';
|
||||
import ProfileHeader from '../profile/ProfileHeader';
|
||||
import ProfileStats from './ProfileStats';
|
||||
import CareerHighlights from './CareerHighlights';
|
||||
import DriverRankings from './DriverRankings';
|
||||
import PerformanceMetrics from './PerformanceMetrics';
|
||||
import { getDriverTeam } from '@gridpilot/racing/application';
|
||||
import { getDriverTeam } from '@/lib/racingLegacyFacade';
|
||||
import { getDriverStats, getLeagueRankings } from '@/lib/di-container';
|
||||
|
||||
interface DriverProfileProps {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import Card from '../ui/Card';
|
||||
import Button from '../ui/Button';
|
||||
import Input from '../ui/Input';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Card from '@/components/ui/Card';
|
||||
import Button from '@/components/ui/Button';
|
||||
import Image from 'next/image';
|
||||
import type { FeedItem } from '@gridpilot/social/domain/entities/FeedItem';
|
||||
import { friends } from '@gridpilot/testing-support';
|
||||
|
||||
@@ -39,9 +40,11 @@ export default function FeedItemCard({ item }: FeedItemCardProps) {
|
||||
<div className="flex-shrink-0">
|
||||
{actor ? (
|
||||
<div className="w-10 h-10 rounded-full overflow-hidden bg-charcoal-outline">
|
||||
<img
|
||||
<Image
|
||||
src={actor.avatarUrl}
|
||||
alt={actor.name}
|
||||
width={40}
|
||||
height={40}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
requestToJoin,
|
||||
getCurrentDriverId,
|
||||
type MembershipStatus,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface JoinLeagueButtonProps {
|
||||
leagueId: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Button from '../ui/Button';
|
||||
import Card from '../ui/Card';
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
getCurrentDriverId,
|
||||
type JoinRequest,
|
||||
type MembershipRole,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
import { getDriverRepository } from '@/lib/di-container';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
|
||||
@@ -33,11 +33,7 @@ export default function LeagueAdmin({ league, onLeagueUpdate }: LeagueAdminProps
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [activeTab, setActiveTab] = useState<'members' | 'requests' | 'races' | 'settings'>('members');
|
||||
|
||||
useEffect(() => {
|
||||
loadJoinRequests();
|
||||
}, [league.id]);
|
||||
|
||||
const loadJoinRequests = async () => {
|
||||
const loadJoinRequests = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const requests = getJoinRequests(league.id);
|
||||
@@ -53,7 +49,11 @@ export default function LeagueAdmin({ league, onLeagueUpdate }: LeagueAdminProps
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
}, [league.id]);
|
||||
|
||||
useEffect(() => {
|
||||
loadJoinRequests();
|
||||
}, [loadJoinRequests]);
|
||||
|
||||
const handleApproveRequest = (requestId: string) => {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { getDriverRepository, getDriverStats } from '@/lib/di-container';
|
||||
import {
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
getCurrentDriverId,
|
||||
type LeagueMembership,
|
||||
type MembershipRole,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface LeagueMembersProps {
|
||||
leagueId: string;
|
||||
@@ -29,11 +29,7 @@ export default function LeagueMembers({
|
||||
const [sortBy, setSortBy] = useState<'role' | 'name' | 'date' | 'rating' | 'points' | 'wins'>('rating');
|
||||
const currentDriverId = getCurrentDriverId();
|
||||
|
||||
useEffect(() => {
|
||||
loadMembers();
|
||||
}, [leagueId]);
|
||||
|
||||
const loadMembers = async () => {
|
||||
const loadMembers = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const membershipData = getLeagueMembers(leagueId);
|
||||
@@ -49,7 +45,11 @@ export default function LeagueMembers({
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
}, [leagueId]);
|
||||
|
||||
useEffect(() => {
|
||||
loadMembers();
|
||||
}, [loadMembers]);
|
||||
|
||||
const getDriverName = (driverId: string): string => {
|
||||
const driver = drivers.find(d => d.id === driverId);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
isRegistered,
|
||||
registerForRace,
|
||||
withdrawFromRace,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface LeagueScheduleProps {
|
||||
leagueId: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { getMembership, getCurrentDriverId, type MembershipRole } from '@gridpilot/racing/application';
|
||||
import { getMembership, getCurrentDriverId, type MembershipRole } from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface MembershipStatusProps {
|
||||
leagueId: string;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import Button from '../ui/Button';
|
||||
import { getDriverTeam } from '@gridpilot/racing/application';
|
||||
import { getDriverTeam } from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface ProfileHeaderProps {
|
||||
driver: DriverDTO;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Button from '@/components/ui/Button';
|
||||
import Input from '@/components/ui/Input';
|
||||
import { createTeam, getCurrentDriverId } from '@gridpilot/racing/application';
|
||||
import { createTeam, getCurrentDriverId } from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface CreateTeamFormProps {
|
||||
onCancel?: () => void;
|
||||
@@ -56,14 +56,13 @@ export default function CreateTeamForm({ onCancel, onSuccess }: CreateTeamFormPr
|
||||
setSubmitting(true);
|
||||
|
||||
try {
|
||||
const currentDriverId = getCurrentDriverId();
|
||||
const team = createTeam(
|
||||
formData.name,
|
||||
formData.tag.toUpperCase(),
|
||||
formData.description,
|
||||
currentDriverId,
|
||||
[] // Empty leagues array for now
|
||||
);
|
||||
getCurrentDriverId(); // ensure identity initialized
|
||||
const team = createTeam({
|
||||
name: formData.name,
|
||||
tag: formData.tag.toUpperCase(),
|
||||
description: formData.description,
|
||||
leagues: [],
|
||||
});
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess(team.id);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
joinTeam,
|
||||
requestToJoinTeam,
|
||||
leaveTeam,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface JoinTeamButtonProps {
|
||||
teamId: string;
|
||||
|
||||
@@ -5,7 +5,8 @@ import Card from '@/components/ui/Card';
|
||||
import Button from '@/components/ui/Button';
|
||||
import Input from '@/components/ui/Input';
|
||||
import { getDriverRepository } from '@/lib/di-container';
|
||||
import { EntityMappers, DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import {
|
||||
Team,
|
||||
TeamJoinRequest,
|
||||
@@ -13,7 +14,7 @@ import {
|
||||
approveTeamJoinRequest,
|
||||
rejectTeamJoinRequest,
|
||||
updateTeam,
|
||||
} from '@gridpilot/racing/application';
|
||||
} from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface TeamAdminProps {
|
||||
team: Team;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Card from '@/components/ui/Card';
|
||||
import { getDriverRepository, getDriverStats } from '@/lib/di-container';
|
||||
import { EntityMappers, DriverDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import { TeamMembership, TeamRole } from '@gridpilot/racing/application';
|
||||
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO';
|
||||
import { TeamMembership, TeamRole } from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface TeamRosterProps {
|
||||
teamId: string;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Card from '@/components/ui/Card';
|
||||
import { getStandingRepository, getLeagueRepository } from '@/lib/di-container';
|
||||
import { EntityMappers, LeagueDTO } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import { getTeamMembers } from '@gridpilot/racing/application';
|
||||
import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers';
|
||||
import type { LeagueDTO } from '@gridpilot/racing/application/dto/LeagueDTO';
|
||||
import { getTeamMembers } from '@/lib/racingLegacyFacade';
|
||||
|
||||
interface TeamStandingsProps {
|
||||
teamId: string;
|
||||
|
||||
494
apps/website/lib/racingLegacyFacade.ts
Normal file
494
apps/website/lib/racingLegacyFacade.ts
Normal file
@@ -0,0 +1,494 @@
|
||||
/**
|
||||
* Website-local racing façade
|
||||
*
|
||||
* This module provides synchronous helper functions used by the alpha website
|
||||
* without depending on legacy exports from @gridpilot/racing/application.
|
||||
* It maintains simple in-memory state for memberships, teams, and registrations.
|
||||
*/
|
||||
|
||||
import type {
|
||||
LeagueMembership as DomainLeagueMembership,
|
||||
MembershipRole,
|
||||
MembershipStatus,
|
||||
} from '@gridpilot/racing/domain/entities/LeagueMembership';
|
||||
|
||||
export type { MembershipRole, MembershipStatus };
|
||||
|
||||
export interface LeagueMembership extends Omit<DomainLeagueMembership, 'joinedAt'> {
|
||||
joinedAt: string;
|
||||
}
|
||||
|
||||
// Lightweight league join request model for the website
|
||||
export interface JoinRequest {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
driverId: string;
|
||||
message?: string;
|
||||
requestedAt: string;
|
||||
}
|
||||
|
||||
import type {
|
||||
Team,
|
||||
TeamJoinRequest,
|
||||
TeamMembership,
|
||||
TeamRole,
|
||||
TeamMembershipStatus,
|
||||
} from '@gridpilot/racing/domain/entities/Team';
|
||||
|
||||
export type { Team, TeamJoinRequest, TeamMembership, TeamRole, TeamMembershipStatus };
|
||||
|
||||
/**
|
||||
* Identity helpers
|
||||
*
|
||||
* For the alpha website we treat a single demo driver as the "current" user.
|
||||
*/
|
||||
const CURRENT_DRIVER_ID = 'driver-1';
|
||||
|
||||
export function getCurrentDriverId(): string {
|
||||
return CURRENT_DRIVER_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* In-memory stores
|
||||
*/
|
||||
|
||||
const leagueMemberships = new Map<string, LeagueMembership[]>();
|
||||
const leagueJoinRequests = new Map<string, JoinRequest[]>();
|
||||
|
||||
const teams = new Map<string, Team>();
|
||||
const teamMemberships = new Map<string, TeamMembership[]>();
|
||||
const teamJoinRequests = new Map<string, TeamJoinRequest[]>();
|
||||
|
||||
const raceRegistrations = new Map<string, Set<string>>();
|
||||
|
||||
/**
|
||||
* Helper utilities
|
||||
*/
|
||||
|
||||
function ensureLeagueMembershipArray(leagueId: string): LeagueMembership[] {
|
||||
let list = leagueMemberships.get(leagueId);
|
||||
if (!list) {
|
||||
list = [];
|
||||
leagueMemberships.set(leagueId, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function ensureTeamMembershipArray(teamId: string): TeamMembership[] {
|
||||
let list = teamMemberships.get(teamId);
|
||||
if (!list) {
|
||||
list = [];
|
||||
teamMemberships.set(teamId, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function ensureRaceRegistrationSet(raceId: string): Set<string> {
|
||||
let set = raceRegistrations.get(raceId);
|
||||
if (!set) {
|
||||
set = new Set<string>();
|
||||
raceRegistrations.set(raceId, set);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
let idCounter = 1;
|
||||
function generateId(prefix: string): string {
|
||||
return `${prefix}-${idCounter++}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* League membership API
|
||||
*/
|
||||
|
||||
export function getMembership(leagueId: string, driverId: string): LeagueMembership | null {
|
||||
const list = leagueMemberships.get(leagueId);
|
||||
if (!list) return null;
|
||||
return list.find((m) => m.driverId === driverId) ?? null;
|
||||
}
|
||||
|
||||
export function getLeagueMembers(leagueId: string): LeagueMembership[] {
|
||||
return [...(leagueMemberships.get(leagueId) ?? [])];
|
||||
}
|
||||
|
||||
export function joinLeague(leagueId: string, driverId: string): void {
|
||||
const existing = getMembership(leagueId, driverId);
|
||||
if (existing && existing.status === 'active') {
|
||||
throw new Error('Already a member of this league');
|
||||
}
|
||||
|
||||
const list = ensureLeagueMembershipArray(leagueId);
|
||||
const now = new Date();
|
||||
|
||||
if (existing) {
|
||||
existing.status = 'active';
|
||||
existing.joinedAt = now.toISOString();
|
||||
return;
|
||||
}
|
||||
|
||||
list.push({
|
||||
leagueId,
|
||||
driverId,
|
||||
role: list.length === 0 ? 'owner' : 'member',
|
||||
status: 'active',
|
||||
joinedAt: now.toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
export function leaveLeague(leagueId: string, driverId: string): void {
|
||||
const list = ensureLeagueMembershipArray(leagueId);
|
||||
const membership = list.find((m) => m.driverId === driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Not a member of this league');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('League owner cannot leave the league');
|
||||
}
|
||||
const idx = list.indexOf(membership);
|
||||
if (idx >= 0) {
|
||||
list.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function requestToJoin(leagueId: string, driverId: string): void {
|
||||
const existing = getMembership(leagueId, driverId);
|
||||
if (existing && existing.status === 'active') {
|
||||
throw new Error('Already a member of this league');
|
||||
}
|
||||
|
||||
const requests = leagueJoinRequests.get(leagueId) ?? [];
|
||||
const now = new Date().toISOString();
|
||||
const request: JoinRequest = {
|
||||
id: generateId('league-request'),
|
||||
leagueId,
|
||||
driverId,
|
||||
requestedAt: now,
|
||||
};
|
||||
requests.push(request);
|
||||
leagueJoinRequests.set(leagueId, requests);
|
||||
}
|
||||
|
||||
export function isOwnerOrAdmin(leagueId: string, driverId: string): boolean {
|
||||
const membership = getMembership(leagueId, driverId);
|
||||
if (!membership) return false;
|
||||
return membership.role === 'owner' || membership.role === 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* League admin API (join requests and membership management)
|
||||
*/
|
||||
|
||||
export function getJoinRequests(leagueId: string): JoinRequest[] {
|
||||
return [...(leagueJoinRequests.get(leagueId) ?? [])];
|
||||
}
|
||||
|
||||
export function approveJoinRequest(requestId: string): void {
|
||||
for (const [leagueId, requests] of leagueJoinRequests.entries()) {
|
||||
const idx = requests.findIndex((r) => r.id === requestId);
|
||||
if (idx >= 0) {
|
||||
const request = requests[idx];
|
||||
requests.splice(idx, 1);
|
||||
leagueJoinRequests.set(leagueId, requests);
|
||||
joinLeague(leagueId, request.driverId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error('Join request not found');
|
||||
}
|
||||
|
||||
export function rejectJoinRequest(requestId: string): void {
|
||||
for (const [leagueId, requests] of leagueJoinRequests.entries()) {
|
||||
const idx = requests.findIndex((r) => r.id === requestId);
|
||||
if (idx >= 0) {
|
||||
requests.splice(idx, 1);
|
||||
leagueJoinRequests.set(leagueId, requests);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error('Join request not found');
|
||||
}
|
||||
|
||||
export function removeMember(leagueId: string, driverId: string, performedBy: string): void {
|
||||
const performer = getMembership(leagueId, performedBy);
|
||||
if (!performer || (performer.role !== 'owner' && performer.role !== 'admin')) {
|
||||
throw new Error('Only owners or admins can remove members');
|
||||
}
|
||||
|
||||
const list = ensureLeagueMembershipArray(leagueId);
|
||||
const membership = list.find((m) => m.driverId === driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Member not found');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('Cannot remove the league owner');
|
||||
}
|
||||
const idx = list.indexOf(membership);
|
||||
if (idx >= 0) {
|
||||
list.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function updateMemberRole(
|
||||
leagueId: string,
|
||||
driverId: string,
|
||||
newRole: MembershipRole,
|
||||
performedBy: string,
|
||||
): void {
|
||||
const performer = getMembership(leagueId, performedBy);
|
||||
if (!performer || performer.role !== 'owner') {
|
||||
throw new Error('Only the league owner can update roles');
|
||||
}
|
||||
|
||||
const list = ensureLeagueMembershipArray(leagueId);
|
||||
const membership = list.find((m) => m.driverId === driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Member not found');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('Cannot change the owner role');
|
||||
}
|
||||
membership.role = newRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Team API
|
||||
*/
|
||||
|
||||
export function createTeam(initial: Pick<Team, 'name' | 'tag' | 'description' | 'leagues'>): Team {
|
||||
const id = generateId('team');
|
||||
const now = new Date();
|
||||
const team: Team = {
|
||||
id,
|
||||
name: initial.name,
|
||||
tag: initial.tag,
|
||||
description: initial.description,
|
||||
leagues: initial.leagues,
|
||||
ownerId: CURRENT_DRIVER_ID,
|
||||
createdAt: now,
|
||||
};
|
||||
teams.set(id, team);
|
||||
|
||||
const members = ensureTeamMembershipArray(id);
|
||||
members.push({
|
||||
teamId: id,
|
||||
driverId: CURRENT_DRIVER_ID,
|
||||
role: 'owner',
|
||||
status: 'active',
|
||||
joinedAt: now,
|
||||
});
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
export function getAllTeams(): Team[] {
|
||||
return [...teams.values()];
|
||||
}
|
||||
|
||||
export function getTeam(teamId: string): Team | null {
|
||||
return teams.get(teamId) ?? null;
|
||||
}
|
||||
|
||||
export function updateTeam(teamId: string, updates: Partial<Pick<Team, 'name' | 'tag' | 'description' | 'leagues'>>, updatedBy: string): void {
|
||||
const team = teams.get(teamId);
|
||||
if (!team) {
|
||||
throw new Error('Team not found');
|
||||
}
|
||||
const membership = getTeamMembership(teamId, updatedBy);
|
||||
if (!membership || (membership.role !== 'owner' && membership.role !== 'manager')) {
|
||||
throw new Error('Only owners or managers can update team');
|
||||
}
|
||||
|
||||
teams.set(teamId, {
|
||||
...team,
|
||||
...updates,
|
||||
});
|
||||
}
|
||||
|
||||
export function getTeamMembers(teamId: string): TeamMembership[] {
|
||||
return [...(teamMemberships.get(teamId) ?? [])];
|
||||
}
|
||||
|
||||
export function getTeamMembership(teamId: string, driverId: string): TeamMembership | null {
|
||||
const list = teamMemberships.get(teamId);
|
||||
if (!list) return null;
|
||||
return list.find((m) => m.driverId === driverId) ?? null;
|
||||
}
|
||||
|
||||
export function getDriverTeam(driverId: string): { team: Team; membership: TeamMembership } | null {
|
||||
for (const [teamId, memberships] of teamMemberships.entries()) {
|
||||
const membership = memberships.find((m) => m.driverId === driverId && m.status === 'active');
|
||||
if (membership) {
|
||||
const team = teams.get(teamId);
|
||||
if (team) {
|
||||
return { team, membership };
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isTeamOwnerOrManager(teamId: string, driverId: string): boolean {
|
||||
const membership = getTeamMembership(teamId, driverId);
|
||||
if (!membership) return false;
|
||||
return membership.role === 'owner' || membership.role === 'manager';
|
||||
}
|
||||
|
||||
export function joinTeam(teamId: string, driverId: string): void {
|
||||
const team = teams.get(teamId);
|
||||
if (!team) {
|
||||
throw new Error('Team not found');
|
||||
}
|
||||
const existing = getTeamMembership(teamId, driverId);
|
||||
if (existing && existing.status === 'active') {
|
||||
throw new Error('Already a member of this team');
|
||||
}
|
||||
|
||||
const list = ensureTeamMembershipArray(teamId);
|
||||
const now = new Date();
|
||||
|
||||
if (existing) {
|
||||
existing.status = 'active';
|
||||
existing.joinedAt = now;
|
||||
return;
|
||||
}
|
||||
|
||||
list.push({
|
||||
teamId,
|
||||
driverId,
|
||||
role: list.length === 0 ? 'owner' : 'driver',
|
||||
status: 'active',
|
||||
joinedAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
export function leaveTeam(teamId: string, driverId: string): void {
|
||||
const list = ensureTeamMembershipArray(teamId);
|
||||
const membership = list.find((m) => m.driverId === driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Not a member of this team');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('Team owner cannot leave the team');
|
||||
}
|
||||
const idx = list.indexOf(membership);
|
||||
if (idx >= 0) {
|
||||
list.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function requestToJoinTeam(teamId: string, driverId: string, message?: string): void {
|
||||
const existing = getTeamMembership(teamId, driverId);
|
||||
if (existing && existing.status === 'active') {
|
||||
throw new Error('Already a member of this team');
|
||||
}
|
||||
|
||||
const requests = teamJoinRequests.get(teamId) ?? [];
|
||||
const now = new Date();
|
||||
const request: TeamJoinRequest = {
|
||||
id: generateId('team-request'),
|
||||
teamId,
|
||||
driverId,
|
||||
message,
|
||||
requestedAt: now,
|
||||
};
|
||||
requests.push(request);
|
||||
teamJoinRequests.set(teamId, requests);
|
||||
}
|
||||
|
||||
export function getTeamJoinRequests(teamId: string): TeamJoinRequest[] {
|
||||
return [...(teamJoinRequests.get(teamId) ?? [])];
|
||||
}
|
||||
|
||||
export function approveTeamJoinRequest(requestId: string): void {
|
||||
for (const [teamId, requests] of teamJoinRequests.entries()) {
|
||||
const idx = requests.findIndex((r) => r.id === requestId);
|
||||
if (idx >= 0) {
|
||||
const request = requests[idx];
|
||||
requests.splice(idx, 1);
|
||||
teamJoinRequests.set(teamId, requests);
|
||||
joinTeam(teamId, request.driverId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error('Join request not found');
|
||||
}
|
||||
|
||||
export function rejectTeamJoinRequest(requestId: string): void {
|
||||
for (const [teamId, requests] of teamJoinRequests.entries()) {
|
||||
const idx = requests.findIndex((r) => r.id === requestId);
|
||||
if (idx >= 0) {
|
||||
requests.splice(idx, 1);
|
||||
teamJoinRequests.set(teamId, requests);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error('Join request not found');
|
||||
}
|
||||
|
||||
export function removeTeamMember(teamId: string, driverId: string, performedBy: string): void {
|
||||
const performerMembership = getTeamMembership(teamId, performedBy);
|
||||
if (!performerMembership || (performerMembership.role !== 'owner' && performerMembership.role !== 'manager')) {
|
||||
throw new Error('Only owners or managers can remove members');
|
||||
}
|
||||
|
||||
const list = ensureTeamMembershipArray(teamId);
|
||||
const membership = list.find((m) => m.driverId === driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Member not found');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('Cannot remove the team owner');
|
||||
}
|
||||
const idx = list.indexOf(membership);
|
||||
if (idx >= 0) {
|
||||
list.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function updateTeamMemberRole(teamId: string, driverId: string, newRole: TeamRole, performedBy: string): void {
|
||||
const performerMembership = getTeamMembership(teamId, performedBy);
|
||||
if (!performerMembership || (performerMembership.role !== 'owner' && performerMembership.role !== 'manager')) {
|
||||
throw new Error('Only owners or managers can update roles');
|
||||
}
|
||||
|
||||
const membership = getTeamMembership(teamId, driverId);
|
||||
if (!membership) {
|
||||
throw new Error('Member not found');
|
||||
}
|
||||
if (membership.role === 'owner') {
|
||||
throw new Error('Cannot change the owner role');
|
||||
}
|
||||
membership.role = newRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Race registration API
|
||||
*/
|
||||
|
||||
export function isRegistered(raceId: string, driverId: string): boolean {
|
||||
const set = raceRegistrations.get(raceId);
|
||||
if (!set) return false;
|
||||
return set.has(driverId);
|
||||
}
|
||||
|
||||
export function registerForRace(raceId: string, driverId: string, _leagueId: string): void {
|
||||
const set = ensureRaceRegistrationSet(raceId);
|
||||
if (set.has(driverId)) {
|
||||
throw new Error('Already registered for this race');
|
||||
}
|
||||
set.add(driverId);
|
||||
}
|
||||
|
||||
export function withdrawFromRace(raceId: string, driverId: string): void {
|
||||
const set = raceRegistrations.get(raceId);
|
||||
if (!set || !set.has(driverId)) {
|
||||
throw new Error('Not registered for this race');
|
||||
}
|
||||
set.delete(driverId);
|
||||
}
|
||||
|
||||
export function getRegisteredDrivers(raceId: string): string[] {
|
||||
const set = raceRegistrations.get(raceId);
|
||||
if (!set) return [];
|
||||
return [...set.values()];
|
||||
}
|
||||
@@ -6,7 +6,8 @@
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./domain/*": "./domain/*",
|
||||
"./application/*": "./application/*"
|
||||
"./application/*": "./application/*",
|
||||
"./infrastructure/*": "./infrastructure/*"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "^3.25.76"
|
||||
|
||||
1
tests/setup/vitest.setup.ts
Normal file
1
tests/setup/vitest.setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, test, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ import { execSync } from 'child_process';
|
||||
* RED Phase: This test MUST FAIL due to externalized modules
|
||||
*/
|
||||
|
||||
describe('Electron Build Smoke Tests', () => {
|
||||
test.describe('Electron Build Smoke Tests', () => {
|
||||
test('should build Electron app without browser context errors', () => {
|
||||
// When: Building the Electron companion app
|
||||
let buildOutput: string;
|
||||
|
||||
@@ -1,205 +1,34 @@
|
||||
import { test, expect, Page, Request, Response } from '@playwright/test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
interface RouteIssue {
|
||||
route: string;
|
||||
consoleErrors: string[];
|
||||
consoleWarnings: string[];
|
||||
networkFailures: Array<{
|
||||
url: string;
|
||||
status?: number;
|
||||
failure?: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively scans the Next.js app directory to discover all routes.
|
||||
* Dynamic segments like [id] are replaced with "demo".
|
||||
*/
|
||||
function discoverRoutes(appDir: string): string[] {
|
||||
const routes: Set<string> = new Set();
|
||||
|
||||
function scanDirectory(dir: string, routePrefix: string = ''): void {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// Handle dynamic segments: [id] -> demo
|
||||
const segment = entry.name.match(/^\[(.+)\]$/)
|
||||
? 'demo'
|
||||
: entry.name;
|
||||
|
||||
// Skip special Next.js directories
|
||||
if (!entry.name.startsWith('_') && !entry.name.startsWith('.')) {
|
||||
const newPrefix = routePrefix + '/' + segment;
|
||||
scanDirectory(fullPath, newPrefix);
|
||||
}
|
||||
} else if (entry.isFile() && entry.name === 'page.tsx') {
|
||||
// Found a page component - this defines a route
|
||||
const route = routePrefix === '' ? '/' : routePrefix;
|
||||
routes.add(route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scanDirectory(appDir);
|
||||
|
||||
// Return sorted, deduplicated list
|
||||
return Array.from(routes).sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches listeners to capture console errors/warnings and network failures
|
||||
* for a specific route visit.
|
||||
*/
|
||||
function setupIssueCapture(page: Page, issues: RouteIssue): void {
|
||||
// Capture console errors and warnings
|
||||
page.on('console', (msg) => {
|
||||
const type = msg.type();
|
||||
if (type === 'error') {
|
||||
issues.consoleErrors.push(msg.text());
|
||||
} else if (type === 'warning') {
|
||||
issues.consoleWarnings.push(msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
// Capture request failures
|
||||
page.on('requestfailed', (request: Request) => {
|
||||
issues.networkFailures.push({
|
||||
url: request.url(),
|
||||
failure: request.failure()?.errorText || 'Request failed',
|
||||
});
|
||||
});
|
||||
|
||||
// Capture non-2xx/3xx responses
|
||||
page.on('response', (response: Response) => {
|
||||
const status = response.status();
|
||||
// Consider 4xx and 5xx as failures
|
||||
if (status >= 400) {
|
||||
issues.networkFailures.push({
|
||||
url: response.url(),
|
||||
status,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats aggregated issues into a readable failure report.
|
||||
*/
|
||||
function formatFailureReport(failedRoutes: RouteIssue[]): string {
|
||||
const lines: string[] = [
|
||||
'',
|
||||
'========================================',
|
||||
'SMOKE TEST FAILURES',
|
||||
'========================================',
|
||||
'',
|
||||
test.describe('Website smoke - core pages render', () => {
|
||||
const routes = [
|
||||
{ path: '/', name: 'landing' },
|
||||
{ path: '/dashboard', name: 'dashboard' },
|
||||
{ path: '/drivers', name: 'drivers list' },
|
||||
{ path: '/leagues', name: 'leagues list' },
|
||||
{ path: '/profile', name: 'profile' },
|
||||
{ path: '/teams', name: 'teams list' },
|
||||
];
|
||||
|
||||
for (const issue of failedRoutes) {
|
||||
lines.push(`Route: ${issue.route}`);
|
||||
lines.push('----------------------------------------');
|
||||
for (const route of routes) {
|
||||
test(`renders ${route.name} page without console errors (${route.path})`, async ({ page }) => {
|
||||
const consoleMessages: string[] = [];
|
||||
|
||||
if (issue.consoleErrors.length > 0) {
|
||||
lines.push('Console Errors:');
|
||||
issue.consoleErrors.forEach((err) => {
|
||||
lines.push(` - ${err}`);
|
||||
page.on('console', (msg) => {
|
||||
const type = msg.type();
|
||||
if (type === 'error') {
|
||||
consoleMessages.push(`[${type}] ${msg.text()}`);
|
||||
}
|
||||
});
|
||||
lines.push('');
|
||||
}
|
||||
|
||||
if (issue.consoleWarnings.length > 0) {
|
||||
lines.push('Console Warnings:');
|
||||
issue.consoleWarnings.forEach((warn) => {
|
||||
lines.push(` - ${warn}`);
|
||||
});
|
||||
lines.push('');
|
||||
}
|
||||
await page.goto(route.path, { waitUntil: 'networkidle' });
|
||||
|
||||
if (issue.networkFailures.length > 0) {
|
||||
lines.push('Network Failures:');
|
||||
issue.networkFailures.forEach((fail) => {
|
||||
const statusPart = fail.status ? ` [${fail.status}]` : '';
|
||||
const failurePart = fail.failure ? ` (${fail.failure})` : '';
|
||||
lines.push(` - ${fail.url}${statusPart}${failurePart}`);
|
||||
});
|
||||
lines.push('');
|
||||
}
|
||||
await expect(page).toHaveTitle(/GridPilot/i);
|
||||
|
||||
lines.push('');
|
||||
expect(
|
||||
consoleMessages.length,
|
||||
`Console errors on route ${route.path}:\n${consoleMessages.join('\n')}`,
|
||||
).toBe(0);
|
||||
});
|
||||
}
|
||||
|
||||
lines.push('========================================');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
test.describe('Website Smoke Test', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
let allRoutes: string[];
|
||||
|
||||
test.beforeAll(() => {
|
||||
// Discover all routes from the app directory
|
||||
const appDir = path.resolve(process.cwd(), 'apps/website/app');
|
||||
allRoutes = discoverRoutes(appDir);
|
||||
|
||||
console.log(`Discovered ${allRoutes.length} routes:`);
|
||||
allRoutes.forEach((route) => console.log(` ${route}`));
|
||||
});
|
||||
|
||||
test('all pages load without console errors or network failures', async ({ page }) => {
|
||||
const failedRoutes: RouteIssue[] = [];
|
||||
|
||||
for (const route of allRoutes) {
|
||||
const issues: RouteIssue = {
|
||||
route,
|
||||
consoleErrors: [],
|
||||
consoleWarnings: [],
|
||||
networkFailures: [],
|
||||
};
|
||||
|
||||
// Setup listeners before navigation
|
||||
setupIssueCapture(page, issues);
|
||||
|
||||
try {
|
||||
// Navigate to the route and wait for network to settle
|
||||
await page.goto(route, {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 30000,
|
||||
});
|
||||
|
||||
// Small delay to catch any late console messages
|
||||
await page.waitForTimeout(500);
|
||||
} catch (error) {
|
||||
// Navigation failure itself
|
||||
issues.networkFailures.push({
|
||||
url: route,
|
||||
failure: `Navigation error: ${error instanceof Error ? error.message : String(error)}`,
|
||||
});
|
||||
}
|
||||
|
||||
// Remove listeners for next iteration
|
||||
page.removeAllListeners('console');
|
||||
page.removeAllListeners('requestfailed');
|
||||
page.removeAllListeners('response');
|
||||
|
||||
// Check if this route had any issues
|
||||
const hasIssues =
|
||||
issues.consoleErrors.length > 0 ||
|
||||
issues.consoleWarnings.length > 0 ||
|
||||
issues.networkFailures.length > 0;
|
||||
|
||||
if (hasIssues) {
|
||||
failedRoutes.push(issues);
|
||||
}
|
||||
}
|
||||
|
||||
// Report all failures at once
|
||||
if (failedRoutes.length > 0) {
|
||||
const report = formatFailureReport(failedRoutes);
|
||||
expect(failedRoutes, report).toHaveLength(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Result } from '@/packages/shared/result/Result';
|
||||
import { Result } from '@gridpilot/shared-result';
|
||||
import { CheckoutConfirmation } from '@gridpilot/automation/domain/value-objects/CheckoutConfirmation';
|
||||
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
|
||||
import { CheckoutState } from '@gridpilot/automation/domain/value-objects/CheckoutState';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { ConfirmCheckoutUseCase } from '@/packages/automation/application/use-cases/ConfirmCheckoutUseCase';
|
||||
import { Result } from '@/packages/shared/result/Result';
|
||||
import { ConfirmCheckoutUseCase } from '@gridpilot/automation/application/use-cases/ConfirmCheckoutUseCase';
|
||||
import { Result } from '@gridpilot/shared-result';
|
||||
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
|
||||
import { CheckoutState } from '@gridpilot/automation/domain/value-objects/CheckoutState';
|
||||
import { CheckoutConfirmation } from '@gridpilot/automation/domain/value-objects/CheckoutConfirmation';
|
||||
import type { ICheckoutService } from '@/packages/automation/application/ports/ICheckoutService';
|
||||
import type { ICheckoutConfirmationPort } from '@/packages/automation/application/ports/ICheckoutConfirmationPort';
|
||||
import type { ICheckoutService } from '@gridpilot/automation/application/ports/ICheckoutService';
|
||||
import type { ICheckoutConfirmationPort } from '@gridpilot/automation/application/ports/ICheckoutConfirmationPort';
|
||||
|
||||
describe('ConfirmCheckoutUseCase - Enhanced with Confirmation Port', () => {
|
||||
let mockCheckoutService: ICheckoutService;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, test, expect, beforeEach, vi } from 'vitest';
|
||||
import type { Page } from 'playwright';
|
||||
import { AuthenticationGuard } from 'packages/automation/infrastructure/adapters/automation/auth/AuthenticationGuard';
|
||||
import { AuthenticationGuard } from '@gridpilot/automation/infrastructure/adapters/automation/auth/AuthenticationGuard';
|
||||
|
||||
describe('AuthenticationGuard', () => {
|
||||
let mockPage: Page;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, test, expect, beforeEach } from 'vitest';
|
||||
import { SessionCookieStore } from 'packages/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
|
||||
import { SessionCookieStore } from '@gridpilot/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
|
||||
import type { Cookie } from 'playwright';
|
||||
|
||||
describe('SessionCookieStore - Cookie Validation', () => {
|
||||
|
||||
@@ -51,13 +51,13 @@ describe('InMemoryAuthService', () => {
|
||||
expect(session.user.primaryDriverId).not.toBe('');
|
||||
});
|
||||
|
||||
it('logout does not attempt to modify cookies directly', async () => {
|
||||
it('logout clears the demo session cookie via adapter', async () => {
|
||||
const service = new InMemoryAuthService();
|
||||
|
||||
await service.logout();
|
||||
|
||||
expect(cookieStore.get).not.toHaveBeenCalled();
|
||||
expect(cookieStore.set).not.toHaveBeenCalled();
|
||||
expect(cookieStore.delete).not.toHaveBeenCalled();
|
||||
expect(cookieStore.delete).toHaveBeenCalledWith('gp_demo_session');
|
||||
});
|
||||
});
|
||||
@@ -4,12 +4,17 @@ import path from 'path';
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'jsdom',
|
||||
setupFiles: ['tests/setup/vitest.setup.ts'],
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@gridpilot/shared-result': path.resolve(__dirname, 'packages/shared/result/Result.ts'),
|
||||
'@gridpilot/automation': path.resolve(__dirname, 'packages/automation'),
|
||||
'@gridpilot/automation/*': path.resolve(__dirname, 'packages/automation/*'),
|
||||
'@gridpilot/testing-support': path.resolve(__dirname, 'packages/testing-support'),
|
||||
'@': path.resolve(__dirname, 'apps/website'),
|
||||
'@/*': path.resolve(__dirname, 'apps/website/*'),
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -5,7 +5,10 @@ export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['tests/smoke/**/*.smoke.test.ts'],
|
||||
include: [
|
||||
'tests/smoke/electron-init.smoke.test.ts',
|
||||
'tests/smoke/browser-mode-toggle.smoke.test.ts',
|
||||
],
|
||||
testTimeout: 10000,
|
||||
hookTimeout: 10000,
|
||||
teardownTimeout: 10000,
|
||||
|
||||
Reference in New Issue
Block a user