wip
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user