wip
This commit is contained in:
@@ -14,7 +14,12 @@ describe('Companion UI - hosted workflow via fixture-backed real stack', () => {
|
||||
beforeAll(async () => {
|
||||
originalEnv = process.env.NODE_ENV;
|
||||
originalFixtureFlag = process.env.COMPANION_FIXTURE_HOSTED;
|
||||
process.env.NODE_ENV = 'test';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'test',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
process.env.COMPANION_FIXTURE_HOSTED = '1';
|
||||
|
||||
DIContainer.resetInstance();
|
||||
@@ -32,7 +37,12 @@ describe('Companion UI - hosted workflow via fixture-backed real stack', () => {
|
||||
|
||||
afterAll(async () => {
|
||||
await container.shutdown();
|
||||
process.env.NODE_ENV = originalEnv;
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: originalEnv,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
process.env.COMPANION_FIXTURE_HOSTED = originalFixtureFlag;
|
||||
});
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ describeMaybe('Real-site hosted session – Race Information step (members.iraci
|
||||
'03-race-information.json',
|
||||
);
|
||||
const raw = await fs.readFile(fixturePath, 'utf8');
|
||||
const items = JSON.parse(raw) as unknown[];
|
||||
const items = JSON.parse(raw) as Array<{ i: string; t: string }>;
|
||||
const sidebarItem =
|
||||
items.find(
|
||||
(i) =>
|
||||
@@ -103,7 +103,7 @@ describeMaybe('Real-site hosted session – Race Information step (members.iraci
|
||||
typeof i.t === 'string',
|
||||
) ?? null;
|
||||
if (sidebarItem) {
|
||||
fixtureSidebarText = sidebarItem.t as string;
|
||||
fixtureSidebarText = sidebarItem.t;
|
||||
}
|
||||
} catch {
|
||||
fixtureSidebarText = null;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll } from 'vitest';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import type { LoggerPort } from '@gridpilot/automation/application/ports/LoggerPort';
|
||||
import type { LogContext } from '@gridpilot/automation/application/ports/LoggerContext';
|
||||
|
||||
/**
|
||||
* Integration tests for Browser Mode in PlaywrightAutomationAdapter - GREEN PHASE
|
||||
@@ -27,7 +29,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.NODE_ENV;
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: undefined,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -53,7 +60,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
afterAll(() => {
|
||||
if (unhandledRejectionHandler) {
|
||||
process.removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
(process as any).removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
unhandledRejectionHandler = null;
|
||||
}
|
||||
});
|
||||
@@ -72,7 +79,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
describe('Headless Mode Launch (NODE_ENV=production/test)', () => {
|
||||
it('should launch browser with headless: true when NODE_ENV=production', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'production',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -80,8 +92,8 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'mock',
|
||||
});
|
||||
|
||||
}, undefined, undefined);
|
||||
|
||||
const result = await adapter.connect();
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
@@ -91,7 +103,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should launch browser with headless: true when NODE_ENV=test', async () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'test',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -99,8 +116,8 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'mock',
|
||||
});
|
||||
|
||||
}, undefined, undefined);
|
||||
|
||||
const result = await adapter.connect();
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
@@ -110,7 +127,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should default to headless when NODE_ENV is not set', async () => {
|
||||
delete process.env.NODE_ENV;
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: undefined,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -118,8 +140,8 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'mock',
|
||||
});
|
||||
|
||||
}, undefined, undefined);
|
||||
|
||||
await adapter.connect();
|
||||
|
||||
expect(adapter.getBrowserMode()).toBe('headless');
|
||||
@@ -134,7 +156,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should report NODE_ENV as source in production mode', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'production',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -142,7 +169,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'mock',
|
||||
});
|
||||
}, undefined, undefined);
|
||||
|
||||
await adapter.connect();
|
||||
|
||||
@@ -150,7 +177,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should report NODE_ENV as source in test mode', async () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'test',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -158,7 +190,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'mock',
|
||||
});
|
||||
}, undefined);
|
||||
|
||||
await adapter.connect();
|
||||
|
||||
@@ -173,22 +205,26 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should log browser mode configuration with NODE_ENV source in production', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
|
||||
const logSpy: Array<{ level: string; message: string; context?: Record<string, unknown> }> = [];
|
||||
type LoggerLike = {
|
||||
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
info: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
error: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
child: () => LoggerLike;
|
||||
debug: (message: string, context?: Record<string, unknown>) => void;
|
||||
info: (message: string, context?: Record<string, unknown>) => void;
|
||||
warn: (message: string, context?: Record<string, unknown>) => void;
|
||||
error: (message: string, error?: Error, context?: Record<string, unknown>) => void;
|
||||
fatal: (message: string, error?: Error, context?: Record<string, unknown>) => void;
|
||||
child: (context: Record<string, unknown>) => LoggerLike;
|
||||
flush: () => Promise<void>;
|
||||
};
|
||||
const mockLogger: LoggerLike = {
|
||||
debug: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'debug', message: msg, context: ctx }),
|
||||
info: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'info', message: msg, context: ctx }),
|
||||
warn: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'warn', message: msg, context: ctx }),
|
||||
error: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'error', message: msg, context: ctx }),
|
||||
child: () => mockLogger,
|
||||
debug: (message: string, context?: Record<string, unknown>) => logSpy.push({ level: 'debug', message, ...(context ? { context } : {}) }),
|
||||
info: (message: string, context?: Record<string, unknown>) => logSpy.push({ level: 'info', message, ...(context ? { context } : {}) }),
|
||||
warn: (message: string, context?: Record<string, unknown>) => logSpy.push({ level: 'warn', message, ...(context ? { context } : {}) }),
|
||||
error: (message: string, error?: Error, context?: Record<string, unknown>) => logSpy.push({ level: 'error', message, ...(context ? { context } : {}) }),
|
||||
fatal: (message: string, error?: Error, context?: Record<string, unknown>) => logSpy.push({ level: 'fatal', message, ...(context ? { context } : {}) }),
|
||||
child: (context: Record<string, unknown>) => mockLogger,
|
||||
flush: () => Promise.resolve(),
|
||||
};
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
@@ -215,7 +251,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
describe('Persistent Context', () => {
|
||||
it('should apply browser mode to persistent browser context', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'production',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
@@ -226,8 +267,8 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
mode: 'real',
|
||||
userDataDir,
|
||||
});
|
||||
|
||||
}, undefined, undefined);
|
||||
|
||||
await adapter.connect();
|
||||
|
||||
expect(adapter.getBrowserMode()).toBe('headless');
|
||||
@@ -242,7 +283,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
describe('Runtime loader re-read instrumentation (test-only)', () => {
|
||||
it('reads mode from injected loader and passes headless flag to launcher accordingly', async () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
Object.defineProperty(process.env, 'NODE_ENV', {
|
||||
value: 'development',
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
const { PlaywrightAutomationAdapter } = await import(
|
||||
'packages/automation/infrastructure/adapters/automation'
|
||||
);
|
||||
@@ -293,7 +339,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
const r1 = await adapter.connect();
|
||||
expect(r1.success).toBe(true);
|
||||
expect(launches.length).toBeGreaterThan(0);
|
||||
expect(launches[0].opts.headless).toBe(false);
|
||||
expect((launches[0] as any).opts.headless).toBe(false);
|
||||
|
||||
// Disconnect and change loader to headless
|
||||
await adapter.disconnect();
|
||||
@@ -305,10 +351,10 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
// The second recorded launch may be at index 1 if both calls used the same launcher path
|
||||
const secondLaunch = launches.slice(1).find(l => l.type === 'launch' || l.type === 'launchPersistent');
|
||||
expect(secondLaunch).toBeDefined();
|
||||
expect(secondLaunch!.opts.headless).toBe(true);
|
||||
expect(secondLaunch!.opts?.headless).toBe(true);
|
||||
|
||||
// Cleanup test hook
|
||||
AdapterWithTestLauncher.testLauncher = undefined;
|
||||
(AdapterWithTestLauncher as any).testLauncher = undefined;
|
||||
await adapter.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ import { FixtureServer, getAllStepFixtureMappings, PlaywrightAutomationAdapter }
|
||||
declare const getComputedStyle: any;
|
||||
declare const document: any;
|
||||
|
||||
const logger = console as any;
|
||||
|
||||
describe('FixtureServer integration', () => {
|
||||
let server: FixtureServer;
|
||||
let adapter: PlaywrightAutomationAdapter;
|
||||
@@ -22,7 +24,7 @@ describe('FixtureServer integration', () => {
|
||||
headless: true,
|
||||
timeout: 5000,
|
||||
baseUrl,
|
||||
});
|
||||
}, logger);
|
||||
|
||||
const connectResult = await adapter.connect();
|
||||
expect(connectResult.success).toBe(true);
|
||||
@@ -86,7 +88,7 @@ describe('FixtureServer integration', () => {
|
||||
const disconnectedAdapter = new PlaywrightAutomationAdapter({
|
||||
headless: true,
|
||||
timeout: 1000,
|
||||
});
|
||||
}, logger);
|
||||
|
||||
const navResult = await disconnectedAdapter.navigateToPage('http://localhost:9999');
|
||||
expect(navResult.success).toBe(false);
|
||||
@@ -105,7 +107,7 @@ describe('FixtureServer integration', () => {
|
||||
it('reports connected state correctly', async () => {
|
||||
expect(adapter.isConnected()).toBe(true);
|
||||
|
||||
const newAdapter = new PlaywrightAutomationAdapter({ headless: true });
|
||||
const newAdapter = new PlaywrightAutomationAdapter({ headless: true }, logger);
|
||||
expect(newAdapter.isConnected()).toBe(false);
|
||||
|
||||
await newAdapter.connect();
|
||||
|
||||
@@ -287,7 +287,7 @@ describe('InMemorySessionRepository Integration Tests', () => {
|
||||
const inProgressSessions = await repository.findByState('IN_PROGRESS');
|
||||
|
||||
expect(inProgressSessions).toHaveLength(1);
|
||||
expect(inProgressSessions[0].id).toBe(session1.id);
|
||||
expect(inProgressSessions[0]!.id).toBe(session1.id);
|
||||
});
|
||||
|
||||
it('should return empty array when no sessions match state', async () => {
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
import type { Page } from 'playwright'
|
||||
import { PlaywrightAutomationAdapter } from 'packages/automation/infrastructure/adapters/automation'
|
||||
|
||||
describe('CarsFlow integration', () => {
|
||||
test('adapter emits panel-attached then action-started then action-complete for performAddCar', async () => {
|
||||
const adapter = new PlaywrightAutomationAdapter({})
|
||||
const adapter = new PlaywrightAutomationAdapter({}, undefined, undefined)
|
||||
const received: Array<{ type: string }> = []
|
||||
adapter.onLifecycle?.((e) => {
|
||||
received.push({ type: (e as { type: string }).type })
|
||||
adapter.onLifecycle?.((e: { type: string; actionId?: string; timestamp: number; payload?: any }) => {
|
||||
received.push({ type: e.type })
|
||||
})
|
||||
|
||||
|
||||
// Use mock page fixture: minimal object with required methods
|
||||
const mockPage = {
|
||||
waitForSelector: async () => {},
|
||||
@@ -16,7 +17,7 @@ describe('CarsFlow integration', () => {
|
||||
waitForTimeout: async () => {},
|
||||
click: async () => {},
|
||||
setDefaultTimeout: () => {},
|
||||
}
|
||||
} as unknown as Page
|
||||
|
||||
// call attachPanel which emits panel-attached and then action-started
|
||||
await adapter.attachPanel(mockPage, 'add-car')
|
||||
|
||||
@@ -45,6 +45,9 @@ describe('Overlay lifecycle (integration)', () => {
|
||||
info: (...args: unknown[]) => void;
|
||||
warn: (...args: unknown[]) => void;
|
||||
error: (...args: unknown[]) => void;
|
||||
fatal: (...args: unknown[]) => void;
|
||||
child: (...args: unknown[]) => LoggerLike;
|
||||
flush: (...args: unknown[]) => Promise<void>;
|
||||
};
|
||||
const logger = console as unknown as LoggerLike;
|
||||
|
||||
@@ -63,7 +66,7 @@ describe('Overlay lifecycle (integration)', () => {
|
||||
const ackPromise: Promise<ActionAck> = service.startAction(action);
|
||||
|
||||
expect(publisher.events.length).toBe(1);
|
||||
const first = publisher.events[0];
|
||||
const first = publisher.events[0]!;
|
||||
expect(first.type).toBe('modal-opened');
|
||||
expect(first.actionId).toBe('hosted-session');
|
||||
|
||||
@@ -84,8 +87,8 @@ describe('Overlay lifecycle (integration)', () => {
|
||||
expect(ack.id).toBe('hosted-session');
|
||||
expect(ack.status).toBe('confirmed');
|
||||
|
||||
expect(publisher.events[0].type).toBe('modal-opened');
|
||||
expect(publisher.events[0].actionId).toBe('hosted-session');
|
||||
expect(publisher.events[0]!.type).toBe('modal-opened');
|
||||
expect(publisher.events[0]!.actionId).toBe('hosted-session');
|
||||
});
|
||||
|
||||
it('emits panel-missing when cancelAction is called', async () => {
|
||||
@@ -96,6 +99,9 @@ describe('Overlay lifecycle (integration)', () => {
|
||||
info: (...args: unknown[]) => void;
|
||||
warn: (...args: unknown[]) => void;
|
||||
error: (...args: unknown[]) => void;
|
||||
fatal: (...args: unknown[]) => void;
|
||||
child: (...args: unknown[]) => LoggerLike;
|
||||
flush: (...args: unknown[]) => Promise<void>;
|
||||
};
|
||||
const logger = console as unknown as LoggerLike;
|
||||
|
||||
@@ -108,7 +114,7 @@ describe('Overlay lifecycle (integration)', () => {
|
||||
await service.cancelAction('hosted-session-cancel');
|
||||
|
||||
expect(publisher.events.length).toBe(1);
|
||||
const ev = publisher.events[0];
|
||||
const ev = publisher.events[0]!;
|
||||
expect(ev.type).toBe('panel-missing');
|
||||
expect(ev.actionId).toBe('hosted-session-cancel');
|
||||
});
|
||||
|
||||
@@ -74,8 +74,8 @@ describe('companion start automation - browser not connected at step 1', () => {
|
||||
|
||||
const session = await waitForFailedSession(sessionRepository, dto.sessionId);
|
||||
expect(session).toBeDefined();
|
||||
expect(session.state.value).toBe('FAILED');
|
||||
const error = session.errorMessage as string | undefined;
|
||||
expect(session!.state!.value).toBe('FAILED');
|
||||
const error = session!.errorMessage as string | undefined;
|
||||
expect(error).toBeDefined();
|
||||
expect(error).toContain('Step 1 (Navigate to Hosted Racing page)');
|
||||
expect(error).toContain('Browser not connected');
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('companion start automation - browser connection failure before steps',
|
||||
|
||||
const executeStepSpy = vi.spyOn(
|
||||
automationEngine,
|
||||
'executeStep' as keyof typeof automationEngine,
|
||||
'executeStep',
|
||||
);
|
||||
|
||||
const config: HostedSessionConfig = {
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('renderer overlay lifecycle integration', () => {
|
||||
const svc = new OverlaySyncService({
|
||||
lifecycleEmitter: emitter,
|
||||
publisher,
|
||||
logger: console,
|
||||
logger: console as any,
|
||||
defaultTimeoutMs: 2_000,
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ describe('renderer overlay lifecycle integration', () => {
|
||||
const rendererState = reduceEventsToRendererState(publisher.events);
|
||||
|
||||
expect(rendererState.status).toBe('completed');
|
||||
expect(rendererState.actionId).toBe('hosted-session');
|
||||
expect((rendererState as { actionId: string }).actionId).toBe('hosted-session');
|
||||
});
|
||||
|
||||
it('ends in failed state when panel-missing is emitted', async () => {
|
||||
@@ -113,7 +113,7 @@ describe('renderer overlay lifecycle integration', () => {
|
||||
const svc = new OverlaySyncService({
|
||||
lifecycleEmitter: emitter,
|
||||
publisher,
|
||||
logger: console,
|
||||
logger: console as any,
|
||||
defaultTimeoutMs: 200,
|
||||
});
|
||||
|
||||
@@ -141,6 +141,6 @@ describe('renderer overlay lifecycle integration', () => {
|
||||
const rendererState = reduceEventsToRendererState(publisher.events);
|
||||
|
||||
expect(rendererState.status).toBe('failed');
|
||||
expect(rendererState.actionId).toBe('hosted-failure');
|
||||
expect((rendererState as { actionId: string }).actionId).toBe('hosted-failure');
|
||||
});
|
||||
});
|
||||
@@ -9,7 +9,7 @@ describe('renderer overlay integration', () => {
|
||||
const svc = new OverlaySyncService({
|
||||
lifecycleEmitter: emitter,
|
||||
publisher,
|
||||
logger: console,
|
||||
logger: console as any,
|
||||
})
|
||||
|
||||
// simulate renderer request
|
||||
|
||||
@@ -3,7 +3,7 @@ import { DIContainer } from '../../apps/companion/main/di-container';
|
||||
|
||||
test('renderer -> preload -> main: set/get updates BrowserModeConfigLoader (reproduces headless-toggle bug)', () => {
|
||||
// Ensure environment is development so toggle is available
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
// Provide a minimal electron.app mock so DIContainer can resolve paths in node test environment
|
||||
// This avoids calling the real Electron runtime during unit/runner tests.
|
||||
|
||||
@@ -23,7 +23,7 @@ vi.mock('electron', () => ({
|
||||
|
||||
describe('Electron DIContainer Smoke Tests', () => {
|
||||
beforeEach(() => {
|
||||
(DIContainer as typeof DIContainer & { instance?: unknown }).instance = undefined;
|
||||
(DIContainer as unknown as { instance?: unknown }).instance = undefined;
|
||||
});
|
||||
|
||||
it('DIContainer initializes without errors', () => {
|
||||
|
||||
@@ -52,12 +52,15 @@ export class ConsoleMonitor {
|
||||
|
||||
// Monitor uncaught exceptions
|
||||
page.on('pageerror', (error: Error) => {
|
||||
this.errors.push({
|
||||
const errorObj: ConsoleError = {
|
||||
type: 'pageerror',
|
||||
message: error.message,
|
||||
location: error.stack,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
};
|
||||
if (error.stack) {
|
||||
errorObj.location = error.stack;
|
||||
}
|
||||
this.errors.push(errorObj);
|
||||
});
|
||||
|
||||
this.isMonitoring = true;
|
||||
|
||||
@@ -22,19 +22,21 @@ export class ElectronTestHarness {
|
||||
async launch(): Promise<void> {
|
||||
// Path to the built Electron app entry point
|
||||
const electronEntryPath = path.join(__dirname, '../../../apps/companion/dist/main/main.cjs');
|
||||
|
||||
|
||||
// Launch Electron app with the compiled entry file
|
||||
// Note: Playwright may have compatibility issues with certain Electron versions
|
||||
// regarding --remote-debugging-port flag
|
||||
this.app = await electron.launch({
|
||||
const launchOptions: any = {
|
||||
args: [electronEntryPath],
|
||||
env: {
|
||||
...process.env,
|
||||
...Object.fromEntries(Object.entries(process.env).filter(([_, v]) => v !== undefined)),
|
||||
NODE_ENV: 'test',
|
||||
},
|
||||
// Try to disable Chrome DevTools Protocol features that might conflict
|
||||
executablePath: process.env.ELECTRON_EXECUTABLE_PATH,
|
||||
});
|
||||
};
|
||||
if (process.env.ELECTRON_EXECUTABLE_PATH) {
|
||||
launchOptions.executablePath = process.env.ELECTRON_EXECUTABLE_PATH;
|
||||
}
|
||||
this.app = await electron.launch(launchOptions);
|
||||
|
||||
// Wait for first window (renderer process)
|
||||
this.mainWindow = await this.app.firstWindow({
|
||||
|
||||
@@ -61,12 +61,15 @@ export class IPCVerifier {
|
||||
|
||||
const typed: IpcHandlerResult = result as IpcHandlerResult;
|
||||
|
||||
return {
|
||||
const resultObj: IPCTestResult = {
|
||||
channel,
|
||||
success: !typed.error,
|
||||
error: typed.error,
|
||||
duration: Date.now() - start,
|
||||
};
|
||||
if (typed.error) {
|
||||
resultObj.error = typed.error;
|
||||
}
|
||||
return resultObj;
|
||||
} catch (error) {
|
||||
return {
|
||||
channel,
|
||||
@@ -114,12 +117,15 @@ export class IPCVerifier {
|
||||
|
||||
const typed: IpcHandlerResult = result as IpcHandlerResult;
|
||||
|
||||
return {
|
||||
const resultObj: IPCTestResult = {
|
||||
channel,
|
||||
success: !typed.error,
|
||||
error: typed.error,
|
||||
duration: Date.now() - start,
|
||||
};
|
||||
if (typed.error) {
|
||||
resultObj.error = typed.error;
|
||||
}
|
||||
return resultObj;
|
||||
} catch (error) {
|
||||
return {
|
||||
channel,
|
||||
@@ -173,12 +179,15 @@ export class IPCVerifier {
|
||||
|
||||
const typed: IpcHandlerResult = result as IpcHandlerResult;
|
||||
|
||||
return {
|
||||
const resultObj: IPCTestResult = {
|
||||
channel,
|
||||
success: !typed.error,
|
||||
error: typed.error,
|
||||
duration: Date.now() - start,
|
||||
};
|
||||
if (typed.error) {
|
||||
resultObj.error = typed.error;
|
||||
}
|
||||
return resultObj;
|
||||
} catch (error) {
|
||||
return {
|
||||
channel,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { describe, it, expect, afterEach, beforeAll, afterAll } from 'vitest';
|
||||
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/automation/infrastructure/adapters/automation';
|
||||
import { NoOpLogAdapter } from '../../packages/automation/infrastructure/adapters/logging/NoOpLogAdapter';
|
||||
|
||||
describe('Playwright Adapter Smoke Tests', () => {
|
||||
let adapter: PlaywrightAutomationAdapter | undefined;
|
||||
let server: FixtureServer | undefined;
|
||||
let unhandledRejectionHandler: ((reason: unknown) => void) | null = null;
|
||||
const logger = new NoOpLogAdapter();
|
||||
|
||||
beforeAll(() => {
|
||||
unhandledRejectionHandler = (reason: unknown) => {
|
||||
@@ -15,7 +17,7 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
}
|
||||
throw reason;
|
||||
};
|
||||
process.on('unhandledRejection', unhandledRejectionHandler);
|
||||
(process as any).on('unhandledRejection', unhandledRejectionHandler);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -39,7 +41,7 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
|
||||
afterAll(() => {
|
||||
if (unhandledRejectionHandler) {
|
||||
process.removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
(process as any).removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
unhandledRejectionHandler = null;
|
||||
}
|
||||
});
|
||||
@@ -50,7 +52,7 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
headless: true,
|
||||
mode: 'mock',
|
||||
timeout: 5000,
|
||||
});
|
||||
}, logger);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
@@ -59,7 +61,7 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
headless: true,
|
||||
mode: 'mock',
|
||||
timeout: 5000,
|
||||
});
|
||||
}, logger);
|
||||
|
||||
const result = await adapter.connect();
|
||||
expect(result.success).toBe(true);
|
||||
@@ -74,7 +76,7 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
headless: true,
|
||||
mode: 'mock',
|
||||
timeout: 5000,
|
||||
});
|
||||
}, logger);
|
||||
|
||||
await adapter.connect();
|
||||
const navResult = await adapter.navigateToPage(server.getFixtureUrl(2));
|
||||
@@ -87,12 +89,12 @@ describe('Playwright Adapter Smoke Tests', () => {
|
||||
headless: true,
|
||||
mode: 'mock',
|
||||
timeout: 5000,
|
||||
});
|
||||
}, logger);
|
||||
const adapter2 = new PlaywrightAutomationAdapter({
|
||||
headless: true,
|
||||
mode: 'mock',
|
||||
timeout: 5000,
|
||||
});
|
||||
}, logger);
|
||||
expect(adapter1).not.toBe(adapter2);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('OverlaySyncService (unit)', () => {
|
||||
// create service wiring: pass emitter as dependency (constructor shape expected)
|
||||
const svc = new OverlaySyncService({
|
||||
lifecycleEmitter: emitter,
|
||||
logger: console,
|
||||
logger: console as any,
|
||||
publisher: { publish: async () => {} },
|
||||
})
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('OverlaySyncService timeout (unit)', () => {
|
||||
const emitter = new MockLifecycleEmitter()
|
||||
const svc = new OverlaySyncService({
|
||||
lifecycleEmitter: emitter,
|
||||
logger: console,
|
||||
logger: console as any,
|
||||
publisher: { publish: async () => {} },
|
||||
})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { CheckAuthenticationUseCase } from '../../../../packages/automation/appl
|
||||
import { AuthenticationState } from '@gridpilot/automation/domain/value-objects/AuthenticationState';
|
||||
import { BrowserAuthenticationState } from '@gridpilot/automation/domain/value-objects/BrowserAuthenticationState';
|
||||
import { Result } from '../../../../packages/shared/result/Result';
|
||||
import type { IAuthenticationService } from '../../../../packages/automation/application/ports/IAuthenticationService';
|
||||
import type { AuthenticationServicePort } from '../../../../packages/automation/application/ports/AuthenticationServicePort';
|
||||
|
||||
interface ISessionValidator {
|
||||
validateSession(): Promise<Result<boolean>>;
|
||||
@@ -44,7 +44,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
describe('File-based validation only', () => {
|
||||
it('should return AUTHENTICATED when cookies are valid', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -63,7 +63,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should return EXPIRED when cookies are expired', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -81,7 +81,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should return UNKNOWN when no session exists', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -101,7 +101,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
describe('Server-side validation enabled', () => {
|
||||
it('should confirm AUTHENTICATED when file and server both validate', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService,
|
||||
mockAuthService as unknown as AuthenticationServicePort,
|
||||
mockSessionValidator as unknown as ISessionValidator
|
||||
);
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should return EXPIRED when file says valid but server rejects', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService,
|
||||
mockAuthService as unknown as AuthenticationServicePort,
|
||||
mockSessionValidator as unknown as ISessionValidator
|
||||
);
|
||||
|
||||
@@ -146,7 +146,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should work without ISessionValidator injected (optional dependency)', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -166,7 +166,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
describe('Error handling', () => {
|
||||
it('should not block file-based result if server validation fails', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService,
|
||||
mockAuthService as unknown as AuthenticationServicePort,
|
||||
mockSessionValidator as unknown as ISessionValidator
|
||||
);
|
||||
|
||||
@@ -188,7 +188,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should handle authentication service errors gracefully', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -203,7 +203,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should handle session expiry check errors gracefully', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -224,7 +224,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
describe('Page content verification', () => {
|
||||
it('should call verifyPageAuthentication when verifyPageContent is true', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -244,7 +244,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should return EXPIRED when cookies valid but page shows login UI', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -265,7 +265,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should return AUTHENTICATED when both cookies AND page authenticated', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -286,7 +286,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should default verifyPageContent to false (backward compatible)', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -304,7 +304,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('should handle verifyPageAuthentication errors gracefully', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -328,7 +328,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
describe('BDD Scenarios', () => {
|
||||
it('Given valid session cookies, When checking auth, Then return AUTHENTICATED', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -345,7 +345,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('Given expired session cookies, When checking auth, Then return EXPIRED', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -362,7 +362,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('Given no session file, When checking auth, Then return UNKNOWN', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
@@ -379,7 +379,7 @@ describe('CheckAuthenticationUseCase', () => {
|
||||
|
||||
it('Given valid cookies but page shows login, When verifying page content, Then return EXPIRED', async () => {
|
||||
const useCase = new CheckAuthenticationUseCase(
|
||||
mockAuthService as unknown as IAuthenticationService
|
||||
mockAuthService as unknown as AuthenticationServicePort
|
||||
);
|
||||
|
||||
mockAuthService.checkSession.mockResolvedValue(
|
||||
|
||||
@@ -3,11 +3,11 @@ import { CompleteRaceCreationUseCase } from '../../../../packages/automation/app
|
||||
import { Result } from '../../../../packages/shared/result/Result';
|
||||
import { RaceCreationResult } from '@gridpilot/automation/domain/value-objects/RaceCreationResult';
|
||||
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
|
||||
import type { ICheckoutService } from '../../../../packages/automation/application/ports/ICheckoutService';
|
||||
import type { CheckoutServicePort } from '../../../../packages/automation/application/ports/CheckoutServicePort';
|
||||
import { CheckoutState } from '@gridpilot/automation/domain/value-objects/CheckoutState';
|
||||
|
||||
describe('CompleteRaceCreationUseCase', () => {
|
||||
let mockCheckoutService: ICheckoutService;
|
||||
let mockCheckoutService: CheckoutServicePort;
|
||||
let useCase: CompleteRaceCreationUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import { Result } from '../../../../packages/shared/result/Result';
|
||||
import { ConfirmCheckoutUseCase } from '../../../../packages/automation/application/use-cases/ConfirmCheckoutUseCase';
|
||||
import { ICheckoutService, CheckoutInfo } from '../../../../packages/automation/application/ports/ICheckoutService';
|
||||
import { ICheckoutConfirmationPort } from '../../../../packages/automation/application/ports/ICheckoutConfirmationPort';
|
||||
import type { CheckoutServicePort } from '../../../../packages/automation/application/ports/CheckoutServicePort';
|
||||
import type { CheckoutConfirmationPort } from '../../../../packages/automation/application/ports/CheckoutConfirmationPort';
|
||||
import type { CheckoutInfoDTODTO } from '../../../../packages/automation/application/dto/CheckoutInfoDTODTO';
|
||||
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
|
||||
import { CheckoutState, CheckoutStateEnum } from '@gridpilot/automation/domain/value-objects/CheckoutState';
|
||||
import { CheckoutConfirmation } from '@gridpilot/automation/domain/value-objects/CheckoutConfirmation';
|
||||
@@ -44,8 +45,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('Success flow', () => {
|
||||
it('should extract price, get user confirmation, and proceed with checkout', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -73,8 +74,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('should include price in confirmation message', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -100,8 +101,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('User cancellation', () => {
|
||||
it('should abort checkout when user cancels confirmation', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -124,8 +125,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('should not proceed with checkout after cancellation', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -148,8 +149,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('Insufficient funds detection', () => {
|
||||
it('should return error when checkout state is INSUFFICIENT_FUNDS', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -170,8 +171,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('should not ask for confirmation when funds are insufficient', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -191,8 +192,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('Price extraction failure', () => {
|
||||
it('should return error when price cannot be extracted', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -213,8 +214,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('should return error when extraction service fails', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -237,8 +238,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
} as unknown as CheckoutPrice;
|
||||
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -270,8 +271,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
} as unknown as CheckoutPrice;
|
||||
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -295,8 +296,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('Checkout execution failure', () => {
|
||||
it('should return error when proceedWithCheckout fails', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -323,8 +324,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
describe('BDD Scenarios', () => {
|
||||
it('Given checkout price $0.50 and READY state, When user confirms, Then checkout proceeds', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -346,8 +347,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('Given checkout price $0.50, When user cancels, Then checkout is aborted', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -369,8 +370,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('Given INSUFFICIENT_FUNDS state, When executing, Then error is returned', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
@@ -388,8 +389,8 @@ describe('ConfirmCheckoutUseCase', () => {
|
||||
|
||||
it('Given price extraction failure, When executing, Then error is returned', async () => {
|
||||
const useCase = new ConfirmCheckoutUseCase(
|
||||
mockCheckoutService as unknown as ICheckoutService,
|
||||
mockConfirmationPort as unknown as ICheckoutConfirmationPort
|
||||
mockCheckoutService as unknown as CheckoutServicePort,
|
||||
mockConfirmationPort as unknown as CheckoutConfirmationPort
|
||||
);
|
||||
|
||||
mockCheckoutService.extractCheckoutInfo.mockResolvedValue(
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('AutomationConfig', () => {
|
||||
describe('getAutomationMode', () => {
|
||||
describe('NODE_ENV-based mode detection', () => {
|
||||
it('should return production mode when NODE_ENV=production', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const mode = getAutomationMode();
|
||||
@@ -26,7 +26,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should return test mode when NODE_ENV=test', () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
(process.env as any).NODE_ENV = 'test';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const mode = getAutomationMode();
|
||||
@@ -35,7 +35,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should return test mode when NODE_ENV is not set', () => {
|
||||
delete process.env.NODE_ENV;
|
||||
delete (process.env as any).NODE_ENV;
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const mode = getAutomationMode();
|
||||
@@ -44,7 +44,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should return test mode for unknown NODE_ENV values', () => {
|
||||
process.env.NODE_ENV = 'staging';
|
||||
(process.env as any).NODE_ENV = 'staging';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const mode = getAutomationMode();
|
||||
@@ -53,7 +53,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should return development mode when NODE_ENV=development', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const mode = getAutomationMode();
|
||||
@@ -104,7 +104,7 @@ describe('AutomationConfig', () => {
|
||||
|
||||
it('should ignore invalid AUTOMATION_MODE and use NODE_ENV', () => {
|
||||
process.env.AUTOMATION_MODE = 'invalid-mode';
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
|
||||
const mode = getAutomationMode();
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('AutomationConfig', () => {
|
||||
describe('loadAutomationConfig', () => {
|
||||
describe('default configuration', () => {
|
||||
it('should return test mode when NODE_ENV is not set', () => {
|
||||
delete process.env.NODE_ENV;
|
||||
delete (process.env as any).NODE_ENV;
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const config = loadAutomationConfig();
|
||||
@@ -143,7 +143,7 @@ describe('AutomationConfig', () => {
|
||||
|
||||
describe('production mode configuration', () => {
|
||||
it('should return production mode when NODE_ENV=production', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const config = loadAutomationConfig();
|
||||
@@ -228,7 +228,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should fallback to test mode for invalid NODE_ENV', () => {
|
||||
process.env.NODE_ENV = 'invalid-env';
|
||||
(process.env as any).NODE_ENV = 'invalid-env';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const config = loadAutomationConfig();
|
||||
@@ -239,7 +239,7 @@ describe('AutomationConfig', () => {
|
||||
|
||||
describe('full configuration scenario', () => {
|
||||
it('should load complete test environment configuration', () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
(process.env as any).NODE_ENV = 'test';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const config = loadAutomationConfig();
|
||||
@@ -249,7 +249,7 @@ describe('AutomationConfig', () => {
|
||||
});
|
||||
|
||||
it('should load complete production environment configuration', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
delete process.env.AUTOMATION_MODE;
|
||||
|
||||
const config = loadAutomationConfig();
|
||||
|
||||
@@ -2,11 +2,13 @@ import { describe, test, expect, beforeEach } from 'vitest';
|
||||
import { SessionCookieStore } from '@gridpilot/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
|
||||
import type { Cookie } from 'playwright';
|
||||
|
||||
const logger = console as any;
|
||||
|
||||
describe('SessionCookieStore - Cookie Validation', () => {
|
||||
let cookieStore: SessionCookieStore;
|
||||
|
||||
beforeEach(() => {
|
||||
cookieStore = new SessionCookieStore('test-user-data');
|
||||
cookieStore = new SessionCookieStore('test-user-data', logger);
|
||||
});
|
||||
|
||||
describe('validateCookieConfiguration()', () => {
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.NODE_ENV;
|
||||
delete (process.env as any).NODE_ENV;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -21,7 +21,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
describe('Development Mode with Runtime Control', () => {
|
||||
it('should default to headless in development mode', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -31,7 +31,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should allow runtime switch to headless mode in development', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode('headless');
|
||||
@@ -42,7 +42,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should allow runtime switch to headed mode in development', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode('headed');
|
||||
@@ -53,7 +53,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should persist runtime setting across multiple load() calls', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode('headless');
|
||||
@@ -66,7 +66,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should return current development mode via getter', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
expect(loader.getDevelopmentMode()).toBe('headless');
|
||||
@@ -78,7 +78,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
describe('Production Mode', () => {
|
||||
it('should use headless mode when NODE_ENV=production', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -88,7 +88,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should ignore setDevelopmentMode in production', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode('headed');
|
||||
@@ -101,7 +101,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
describe('Test Mode', () => {
|
||||
it('should use headless mode when NODE_ENV=test', () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
(process.env as any).NODE_ENV = 'test';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -111,7 +111,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should ignore setDevelopmentMode in test mode', () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
(process.env as any).NODE_ENV = 'test';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode('headed');
|
||||
@@ -124,7 +124,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
describe('Default Mode', () => {
|
||||
it('should default to headless mode when NODE_ENV is not set', () => {
|
||||
delete process.env.NODE_ENV;
|
||||
delete (process.env as any).NODE_ENV;
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -134,7 +134,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should use headless mode for any non-development NODE_ENV value', () => {
|
||||
process.env.NODE_ENV = 'staging';
|
||||
(process.env as any).NODE_ENV = 'staging';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -146,7 +146,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
|
||||
describe('Source Tracking', () => {
|
||||
it('should report GUI as source in development mode', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -155,7 +155,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should report NODE_ENV as source in production mode', () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -164,7 +164,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should report NODE_ENV as source in test mode', () => {
|
||||
process.env.NODE_ENV = 'test';
|
||||
(process.env as any).NODE_ENV = 'test';
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
@@ -173,7 +173,7 @@ describe('BrowserModeConfig - GREEN Phase', () => {
|
||||
});
|
||||
|
||||
it('should report NODE_ENV as source when NODE_ENV is not set', () => {
|
||||
delete process.env.NODE_ENV;
|
||||
delete (process.env as any).NODE_ENV;
|
||||
|
||||
const loader = new BrowserModeConfigLoader();
|
||||
const config = loader.load();
|
||||
|
||||
@@ -10,6 +10,10 @@ import type {
|
||||
class FakeDashboardOverviewPresenter implements IDashboardOverviewPresenter {
|
||||
viewModel: DashboardOverviewViewModel | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
|
||||
present(viewModel: DashboardOverviewViewModel): void {
|
||||
this.viewModel = viewModel;
|
||||
}
|
||||
@@ -201,11 +205,10 @@ describe('GetDashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
imageService,
|
||||
getDriverStats,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ driverId });
|
||||
await useCase.execute({ driverId }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -389,11 +392,10 @@ describe('GetDashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
imageService,
|
||||
getDriverStats,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ driverId });
|
||||
await useCase.execute({ driverId }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -496,11 +498,10 @@ describe('GetDashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
imageService,
|
||||
getDriverStats,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ driverId });
|
||||
await useCase.execute({ driverId }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
|
||||
@@ -6,7 +6,6 @@ import type { IDriverRepository } from '@gridpilot/racing/domain/repositories/ID
|
||||
import type { IRaceRegistrationRepository } from '@gridpilot/racing/domain/repositories/IRaceRegistrationRepository';
|
||||
import type { IResultRepository } from '@gridpilot/racing/domain/repositories/IResultRepository';
|
||||
import type { ILeagueMembershipRepository } from '@gridpilot/racing/domain/repositories/ILeagueMembershipRepository';
|
||||
import type { LeagueMembership } from '@gridpilot/racing/domain/entities/LeagueMembership';
|
||||
import type { DriverRatingProvider } from '@gridpilot/racing/application/ports/DriverRatingProvider';
|
||||
import type { IImageServicePort } from '@gridpilot/racing/application/ports/IImageServicePort';
|
||||
import type {
|
||||
@@ -17,6 +16,8 @@ import type {
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { League } from '@gridpilot/racing/domain/entities/League';
|
||||
import { Result } from '@gridpilot/racing/domain/entities/Result';
|
||||
import { Driver } from '@gridpilot/racing/domain/entities/Driver';
|
||||
import { LeagueMembership } from '@gridpilot/racing/domain/entities/LeagueMembership';
|
||||
import { GetRaceDetailUseCase } from '@gridpilot/racing/application/use-cases/GetRaceDetailUseCase';
|
||||
import { CancelRaceUseCase } from '@gridpilot/racing/application/use-cases/CancelRaceUseCase';
|
||||
|
||||
@@ -118,31 +119,39 @@ class InMemoryLeagueRepository implements ILeagueRepository {
|
||||
async exists(id: string): Promise<boolean> {
|
||||
return this.leagues.has(id);
|
||||
}
|
||||
|
||||
async searchByName(): Promise<League[]> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class InMemoryDriverRepository implements IDriverRepository {
|
||||
private drivers = new Map<string, { id: string; name: string; country: string }>();
|
||||
|
||||
private drivers = new Map<string, Driver>();
|
||||
|
||||
constructor(drivers: Array<{ id: string; name: string; country: string }>) {
|
||||
for (const driver of drivers) {
|
||||
this.drivers.set(driver.id, {
|
||||
...driver,
|
||||
});
|
||||
this.drivers.set(driver.id, Driver.create({
|
||||
id: driver.id,
|
||||
iracingId: `iracing-${driver.id}`,
|
||||
name: driver.name,
|
||||
country: driver.country,
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<{ id: string; name: string; country: string } | null> {
|
||||
|
||||
async findById(id: string): Promise<Driver | null> {
|
||||
return this.drivers.get(id) ?? null;
|
||||
}
|
||||
|
||||
async findAll(): Promise<Array<{ id: string; name: string; country: string }>> {
|
||||
|
||||
async findAll(): Promise<Driver[]> {
|
||||
return [...this.drivers.values()];
|
||||
}
|
||||
|
||||
async findByIds(ids: string[]): Promise<Array<{ id: string; name: string; country: string }>> {
|
||||
|
||||
async findByIds(ids: string[]): Promise<Driver[]> {
|
||||
return ids
|
||||
.map(id => this.drivers.get(id))
|
||||
.filter((d): d is { id: string; name: string; country: string } => !!d);
|
||||
.filter((d): d is Driver => !!d);
|
||||
}
|
||||
|
||||
async create(): Promise<any> {
|
||||
@@ -160,6 +169,14 @@ class InMemoryDriverRepository implements IDriverRepository {
|
||||
async exists(): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
async findByIRacingId(): Promise<Driver | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
async existsByIRacingId(): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class InMemoryRaceRegistrationRepository implements IRaceRegistrationRepository {
|
||||
@@ -365,6 +382,10 @@ class FakeRaceDetailPresenter implements IRaceDetailPresenter {
|
||||
getViewModel(): RaceDetailViewModel | null {
|
||||
return this.viewModel;
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
describe('GetRaceDetailUseCase', () => {
|
||||
@@ -405,13 +426,13 @@ describe('GetRaceDetailUseCase', () => {
|
||||
const resultRepo = new InMemoryResultRepository([]);
|
||||
|
||||
const membershipRepo = new InMemoryLeagueMembershipRepository();
|
||||
membershipRepo.seedMembership({
|
||||
membershipRepo.seedMembership(LeagueMembership.create({
|
||||
leagueId: league.id,
|
||||
driverId,
|
||||
role: 'member',
|
||||
status: 'active',
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
});
|
||||
}));
|
||||
|
||||
const ratingProvider = new TestDriverRatingProvider();
|
||||
ratingProvider.seed(driverId, 1500);
|
||||
@@ -429,11 +450,10 @@ describe('GetRaceDetailUseCase', () => {
|
||||
membershipRepo,
|
||||
ratingProvider,
|
||||
imageService,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When (execute the query for the current driver)
|
||||
await useCase.execute({ raceId: race.id, driverId });
|
||||
await useCase.execute({ raceId: race.id, driverId }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -502,13 +522,13 @@ describe('GetRaceDetailUseCase', () => {
|
||||
|
||||
const resultRepo = new InMemoryResultRepository([resultEntity]);
|
||||
const membershipRepo = new InMemoryLeagueMembershipRepository();
|
||||
membershipRepo.seedMembership({
|
||||
membershipRepo.seedMembership(LeagueMembership.create({
|
||||
leagueId: league.id,
|
||||
driverId,
|
||||
role: 'member',
|
||||
status: 'active',
|
||||
joinedAt: new Date('2024-01-01'),
|
||||
});
|
||||
}));
|
||||
|
||||
const ratingProvider = new TestDriverRatingProvider();
|
||||
ratingProvider.seed(driverId, 2000);
|
||||
@@ -525,11 +545,10 @@ describe('GetRaceDetailUseCase', () => {
|
||||
membershipRepo,
|
||||
ratingProvider,
|
||||
imageService,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When (executing the query for the completed race)
|
||||
await useCase.execute({ raceId: race.id, driverId });
|
||||
await useCase.execute({ raceId: race.id, driverId }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -566,11 +585,10 @@ describe('GetRaceDetailUseCase', () => {
|
||||
membershipRepo,
|
||||
ratingProvider,
|
||||
imageService,
|
||||
presenter,
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ raceId: 'missing-race', driverId: 'driver-x' });
|
||||
await useCase.execute({ raceId: 'missing-race', driverId: 'driver-x' }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
// Then
|
||||
|
||||
@@ -20,6 +20,10 @@ import type {
|
||||
class FakeRaceResultsDetailPresenter implements IRaceResultsDetailPresenter {
|
||||
viewModel: RaceResultsDetailViewModel | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
|
||||
present(viewModel: RaceResultsDetailViewModel): RaceResultsDetailViewModel {
|
||||
this.viewModel = viewModel;
|
||||
return viewModel;
|
||||
@@ -354,7 +358,7 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
);
|
||||
|
||||
// When executing the query
|
||||
await useCase.execute({ raceId: race.id });
|
||||
await useCase.execute({ raceId: race.id }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -464,7 +468,7 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ raceId: race.id });
|
||||
await useCase.execute({ raceId: race.id }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
@@ -529,7 +533,7 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
);
|
||||
|
||||
// When
|
||||
await useCase.execute({ raceId: 'missing-race' });
|
||||
await useCase.execute({ raceId: 'missing-race' }, presenter);
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
|
||||
@@ -56,6 +56,7 @@ import type {
|
||||
DriverTeamResultDTO,
|
||||
DriverTeamViewModel,
|
||||
} from '@gridpilot/racing/application/presenters/IDriverTeamPresenter';
|
||||
import type { RaceRegistrationsResultDTO } from '@gridpilot/racing/application/presenters/IRaceRegistrationsPresenter';
|
||||
|
||||
/**
|
||||
* Simple in-memory fakes mirroring current alpha behavior.
|
||||
@@ -179,16 +180,14 @@ class TestRaceRegistrationsPresenter implements IRaceRegistrationsPresenter {
|
||||
raceId: string | null = null;
|
||||
driverIds: string[] = [];
|
||||
|
||||
// Accepts either the legacy (raceId, driverIds) shape or the new (driverIds) shape
|
||||
present(raceIdOrDriverIds: string | string[], driverIds?: string[]): void {
|
||||
if (Array.isArray(raceIdOrDriverIds) && driverIds == null) {
|
||||
this.raceId = null;
|
||||
this.driverIds = raceIdOrDriverIds;
|
||||
return;
|
||||
}
|
||||
reset(): void {
|
||||
this.raceId = null;
|
||||
this.driverIds = [];
|
||||
}
|
||||
|
||||
this.raceId = raceIdOrDriverIds as string;
|
||||
this.driverIds = driverIds ?? [];
|
||||
present(input: RaceRegistrationsResultDTO): void {
|
||||
this.driverIds = input.registeredDriverIds;
|
||||
this.raceId = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +317,10 @@ class InMemoryTeamMembershipRepository implements ITeamMembershipRepository {
|
||||
getAllJoinRequests(): TeamJoinRequest[] {
|
||||
return [...this.joinRequests];
|
||||
}
|
||||
|
||||
async countByTeamId(teamId: string): Promise<number> {
|
||||
return this.memberships.filter((m) => m.teamId === teamId).length;
|
||||
}
|
||||
}
|
||||
|
||||
describe('Racing application use-cases - registrations', () => {
|
||||
@@ -342,10 +345,7 @@ describe('Racing application use-cases - registrations', () => {
|
||||
driverRegistrationPresenter,
|
||||
);
|
||||
raceRegistrationsPresenter = new TestRaceRegistrationsPresenter();
|
||||
getRaceRegistrations = new GetRaceRegistrationsUseCase(
|
||||
registrationRepo,
|
||||
raceRegistrationsPresenter,
|
||||
);
|
||||
getRaceRegistrations = new GetRaceRegistrationsUseCase(registrationRepo);
|
||||
});
|
||||
|
||||
it('registers an active league member for a race and tracks registration', async () => {
|
||||
@@ -362,7 +362,7 @@ describe('Racing application use-cases - registrations', () => {
|
||||
expect(driverRegistrationPresenter.raceId).toBe(raceId);
|
||||
expect(driverRegistrationPresenter.driverId).toBe(driverId);
|
||||
|
||||
await getRaceRegistrations.execute({ raceId });
|
||||
await getRaceRegistrations.execute({ raceId }, raceRegistrationsPresenter);
|
||||
expect(raceRegistrationsPresenter.driverIds).toContain(driverId);
|
||||
});
|
||||
|
||||
@@ -389,7 +389,7 @@ describe('Racing application use-cases - registrations', () => {
|
||||
await isDriverRegistered.execute({ raceId, driverId });
|
||||
expect(driverRegistrationPresenter.isRegistered).toBe(false);
|
||||
|
||||
await getRaceRegistrations.execute({ raceId });
|
||||
await getRaceRegistrations.execute({ raceId }, raceRegistrationsPresenter);
|
||||
expect(raceRegistrationsPresenter.driverIds).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -458,8 +458,16 @@ describe('Racing application use-cases - teams', () => {
|
||||
class TestTeamDetailsPresenter implements ITeamDetailsPresenter {
|
||||
viewModel: any = null;
|
||||
|
||||
present(team: any, membership: any, driverId: string): void {
|
||||
this.viewModel = { team, membership, driverId };
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
|
||||
present(input: any): void {
|
||||
this.viewModel = input;
|
||||
}
|
||||
|
||||
getViewModel(): any {
|
||||
return this.viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,7 +752,7 @@ describe('Racing application use-cases - teams', () => {
|
||||
updatedBy: ownerId,
|
||||
});
|
||||
|
||||
await getTeamDetailsUseCase.execute(created.team.id, ownerId);
|
||||
await getTeamDetailsUseCase.execute({ teamId: created.team.id, driverId: ownerId }, teamDetailsPresenter);
|
||||
|
||||
expect(teamDetailsPresenter.viewModel.team.name).toBe('Updated Name');
|
||||
expect(teamDetailsPresenter.viewModel.team.description).toBe('Updated description');
|
||||
|
||||
@@ -9,12 +9,12 @@ describe('getAppMode', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
process.env.NODE_ENV = 'production';
|
||||
(process.env as any).NODE_ENV = 'production';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
process.env.NODE_ENV = ORIGINAL_NODE_ENV;
|
||||
(process.env as any).NODE_ENV = ORIGINAL_NODE_ENV;
|
||||
});
|
||||
|
||||
it('returns "pre-launch" when NEXT_PUBLIC_GRIDPILOT_MODE is undefined', () => {
|
||||
@@ -55,7 +55,7 @@ describe('getAppMode', () => {
|
||||
});
|
||||
|
||||
it('throws in development when NEXT_PUBLIC_GRIDPILOT_MODE is invalid', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
(process.env as any).NODE_ENV = 'development';
|
||||
process.env.NEXT_PUBLIC_GRIDPILOT_MODE = 'invalid-mode';
|
||||
|
||||
expect(() => getAppMode()).toThrowError(/Invalid NEXT_PUBLIC_GRIDPILOT_MODE/);
|
||||
|
||||
@@ -77,7 +77,7 @@ describe('/api/signup POST', () => {
|
||||
|
||||
const data = (await response.json()) as { error: unknown };
|
||||
expect(typeof data.error).toBe('string');
|
||||
expect(data.error.toLowerCase()).toContain('email');
|
||||
expect(typeof data.error === 'string' && data.error.toLowerCase()).toContain('email');
|
||||
});
|
||||
|
||||
it('rejects disposable email domains with 400 and error message', async () => {
|
||||
@@ -110,7 +110,7 @@ describe('/api/signup POST', () => {
|
||||
|
||||
const data = (await second.json()) as { error: unknown };
|
||||
expect(typeof data.error).toBe('string');
|
||||
expect(data.error.toLowerCase()).toContain('already');
|
||||
expect(typeof data.error === 'string' && data.error.toLowerCase()).toContain('already');
|
||||
});
|
||||
|
||||
it('returns 429 with retryAfter when rate limit is exceeded', async () => {
|
||||
|
||||
Reference in New Issue
Block a user