72 lines
3.2 KiB
TypeScript
72 lines
3.2 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { DIContainer } from '@apps/companion/main/di-container';
|
|
import { StartAutomationSessionUseCase } from 'apps/companion/main/automation/application/use-cases/StartAutomationSessionUseCase';
|
|
import { CheckAuthenticationUseCase } from 'apps/companion/main/automation/application/use-cases/CheckAuthenticationUseCase';
|
|
import { InitiateLoginUseCase } from 'apps/companion/main/automation/application/use-cases/InitiateLoginUseCase';
|
|
import { ClearSessionUseCase } from 'apps/companion/main/automation/application/use-cases/ClearSessionUseCase';
|
|
import { ConfirmCheckoutUseCase } from 'apps/companion/main/automation/application/use-cases/ConfirmCheckoutUseCase';
|
|
import { PlaywrightAutomationAdapter } from 'core/automation/infrastructure//automation';
|
|
import { InMemorySessionRepository } from 'apps/companion/main/automation/infrastructure/repositories/InMemorySessionRepository';
|
|
import { NoOpLogAdapter } from '@core/automation/infrastructure//logging/NoOpLogAdapter';
|
|
|
|
// Mock Electron's app module
|
|
vi.mock('electron', () => ({
|
|
app: {
|
|
getPath: vi.fn((name: string) => {
|
|
if (name === 'userData') return '/tmp/test-user-data';
|
|
return '/tmp/test';
|
|
}),
|
|
getAppPath: vi.fn(() => '/tmp/test-app'),
|
|
isPackaged: false,
|
|
},
|
|
}));
|
|
|
|
describe('Electron DIContainer Smoke Tests', () => {
|
|
beforeEach(() => {
|
|
(DIContainer as unknown as { instance?: unknown }).instance = undefined;
|
|
});
|
|
|
|
it('DIContainer initializes without errors', () => {
|
|
expect(() => DIContainer.getInstance()).not.toThrow();
|
|
});
|
|
|
|
it('All use cases are accessible', () => {
|
|
const container = DIContainer.getInstance();
|
|
|
|
expect(() => container.getStartAutomationUseCase()).not.toThrow();
|
|
expect(() => container.getCheckAuthenticationUseCase()).not.toThrow();
|
|
expect(() => container.getInitiateLoginUseCase()).not.toThrow();
|
|
expect(() => container.getClearSessionUseCase()).not.toThrow();
|
|
expect(() => container.getConfirmCheckoutUseCase()).not.toThrow();
|
|
});
|
|
|
|
it('Use case instances are available after initialization', () => {
|
|
const container = DIContainer.getInstance();
|
|
|
|
// Verify all core use cases are available
|
|
expect(container.getStartAutomationUseCase()).not.toBeNull();
|
|
expect(container.getStartAutomationUseCase()).toBeDefined();
|
|
|
|
// These may be null in test mode, but should not throw
|
|
expect(() => container.getCheckAuthenticationUseCase()).not.toThrow();
|
|
expect(() => container.getInitiateLoginUseCase()).not.toThrow();
|
|
expect(() => container.getClearSessionUseCase()).not.toThrow();
|
|
});
|
|
|
|
it('Container provides access to dependencies', () => {
|
|
const container = DIContainer.getInstance();
|
|
|
|
// Verify core dependencies are accessible
|
|
expect(container.getSessionRepository()).toBeDefined();
|
|
expect(container.getAutomationEngine()).toBeDefined();
|
|
expect(container.getBrowserAutomation()).toBeDefined();
|
|
expect(container.getLogger()).toBeDefined();
|
|
});
|
|
|
|
it('ConfirmCheckoutUseCase can be verified without errors', () => {
|
|
const container = DIContainer.getInstance();
|
|
|
|
// This getter should not throw even if null (verifies the import)
|
|
expect(() => container.getConfirmCheckoutUseCase()).not.toThrow();
|
|
});
|
|
}); |