wip
This commit is contained in:
@@ -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