module cleanup
This commit is contained in:
194
apps/api/src/domain/payments/PaymentsController.test.ts
Normal file
194
apps/api/src/domain/payments/PaymentsController.test.ts
Normal file
@@ -0,0 +1,194 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { PaymentsController } from './PaymentsController';
|
||||
import { PaymentsService } from './PaymentsService';
|
||||
import { GetPaymentsQuery, CreatePaymentInput, UpdatePaymentStatusInput, GetMembershipFeesQuery, UpsertMembershipFeeInput, UpdateMemberPaymentInput, GetPrizesQuery, CreatePrizeInput, AwardPrizeInput, DeletePrizeInput, GetWalletQuery, ProcessWalletTransactionInput } from './dtos/PaymentsDto';
|
||||
|
||||
describe('PaymentsController', () => {
|
||||
let controller: PaymentsController;
|
||||
let service: ReturnType<typeof vi.mocked<PaymentsService>>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PaymentsController],
|
||||
providers: [
|
||||
{
|
||||
provide: PaymentsService,
|
||||
useValue: {
|
||||
getPayments: vi.fn(),
|
||||
createPayment: vi.fn(),
|
||||
updatePaymentStatus: vi.fn(),
|
||||
getMembershipFees: vi.fn(),
|
||||
upsertMembershipFee: vi.fn(),
|
||||
updateMemberPayment: vi.fn(),
|
||||
getPrizes: vi.fn(),
|
||||
createPrize: vi.fn(),
|
||||
awardPrize: vi.fn(),
|
||||
deletePrize: vi.fn(),
|
||||
getWallet: vi.fn(),
|
||||
processWalletTransaction: vi.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PaymentsController>(PaymentsController);
|
||||
service = vi.mocked(module.get(PaymentsService));
|
||||
});
|
||||
|
||||
describe('getPayments', () => {
|
||||
it('should return payments', async () => {
|
||||
const query: GetPaymentsQuery = { status: 'pending' };
|
||||
const result = { payments: [] };
|
||||
service.getPayments.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.getPayments(query);
|
||||
|
||||
expect(service.getPayments).toHaveBeenCalledWith(query);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPayment', () => {
|
||||
it('should create payment', async () => {
|
||||
const input: CreatePaymentInput = { amount: 100, type: 'membership_fee', payerId: 'payer-123', payerType: 'driver', leagueId: 'league-123' };
|
||||
const result = { payment: { id: 'pay-123' } };
|
||||
service.createPayment.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.createPayment(input);
|
||||
|
||||
expect(service.createPayment).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updatePaymentStatus', () => {
|
||||
it('should update payment status', async () => {
|
||||
const input: UpdatePaymentStatusInput = { paymentId: 'pay-123', status: 'completed' };
|
||||
const result = { payment: { id: 'pay-123', status: 'completed' } };
|
||||
service.updatePaymentStatus.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.updatePaymentStatus(input);
|
||||
|
||||
expect(service.updatePaymentStatus).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMembershipFees', () => {
|
||||
it('should return membership fees', async () => {
|
||||
const query: GetMembershipFeesQuery = { leagueId: 'league-123' };
|
||||
const result = { fees: [] };
|
||||
service.getMembershipFees.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.getMembershipFees(query);
|
||||
|
||||
expect(service.getMembershipFees).toHaveBeenCalledWith(query);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('upsertMembershipFee', () => {
|
||||
it('should upsert membership fee', async () => {
|
||||
const input: UpsertMembershipFeeInput = { leagueId: 'league-123', amount: 50 };
|
||||
const result = { feeId: 'fee-123' };
|
||||
service.upsertMembershipFee.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.upsertMembershipFee(input);
|
||||
|
||||
expect(service.upsertMembershipFee).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateMemberPayment', () => {
|
||||
it('should update member payment', async () => {
|
||||
const input: UpdateMemberPaymentInput = { memberId: 'member-123', paymentId: 'pay-123' };
|
||||
const result = { success: true };
|
||||
service.updateMemberPayment.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.updateMemberPayment(input);
|
||||
|
||||
expect(service.updateMemberPayment).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPrizes', () => {
|
||||
it('should return prizes', async () => {
|
||||
const query: GetPrizesQuery = { leagueId: 'league-123' };
|
||||
const result = { prizes: [] };
|
||||
service.getPrizes.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.getPrizes(query);
|
||||
|
||||
expect(service.getPrizes).toHaveBeenCalledWith(query);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPrize', () => {
|
||||
it('should create prize', async () => {
|
||||
const input: CreatePrizeInput = { name: 'Prize', amount: 100 };
|
||||
const result = { prizeId: 'prize-123' };
|
||||
service.createPrize.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.createPrize(input);
|
||||
|
||||
expect(service.createPrize).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('awardPrize', () => {
|
||||
it('should award prize', async () => {
|
||||
const input: AwardPrizeInput = { prizeId: 'prize-123', driverId: 'driver-123' };
|
||||
const result = { success: true };
|
||||
service.awardPrize.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.awardPrize(input);
|
||||
|
||||
expect(service.awardPrize).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deletePrize', () => {
|
||||
it('should delete prize', async () => {
|
||||
const query: DeletePrizeInput = { prizeId: 'prize-123' };
|
||||
const result = { success: true };
|
||||
service.deletePrize.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.deletePrize(query);
|
||||
|
||||
expect(service.deletePrize).toHaveBeenCalledWith(query);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getWallet', () => {
|
||||
it('should return wallet', async () => {
|
||||
const query: GetWalletQuery = { userId: 'user-123' };
|
||||
const result = { balance: 100 };
|
||||
service.getWallet.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.getWallet(query);
|
||||
|
||||
expect(service.getWallet).toHaveBeenCalledWith(query);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('processWalletTransaction', () => {
|
||||
it('should process wallet transaction', async () => {
|
||||
const input: ProcessWalletTransactionInput = { userId: 'user-123', amount: 50, type: 'deposit' };
|
||||
const result = { transactionId: 'tx-123' };
|
||||
service.processWalletTransaction.mockResolvedValue(result);
|
||||
|
||||
const response = await controller.processWalletTransaction(input);
|
||||
|
||||
expect(service.processWalletTransaction).toHaveBeenCalledWith(input);
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
30
apps/api/src/domain/payments/PaymentsModule.test.ts
Normal file
30
apps/api/src/domain/payments/PaymentsModule.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PaymentsModule } from './PaymentsModule';
|
||||
import { PaymentsController } from './PaymentsController';
|
||||
import { PaymentsService } from './PaymentsService';
|
||||
|
||||
describe('PaymentsModule', () => {
|
||||
let module: TestingModule;
|
||||
|
||||
beforeEach(async () => {
|
||||
module = await Test.createTestingModule({
|
||||
imports: [PaymentsModule],
|
||||
}).compile();
|
||||
});
|
||||
|
||||
it('should compile the module', () => {
|
||||
expect(module).toBeDefined();
|
||||
});
|
||||
|
||||
it('should provide PaymentsController', () => {
|
||||
const controller = module.get<PaymentsController>(PaymentsController);
|
||||
expect(controller).toBeDefined();
|
||||
expect(controller).toBeInstanceOf(PaymentsController);
|
||||
});
|
||||
|
||||
it('should provide PaymentsService', () => {
|
||||
const service = module.get<PaymentsService>(PaymentsService);
|
||||
expect(service).toBeDefined();
|
||||
expect(service).toBeInstanceOf(PaymentsService);
|
||||
});
|
||||
});
|
||||
@@ -23,10 +23,10 @@ import { GetWalletUseCase } from '@core/payments/application/use-cases/GetWallet
|
||||
import { ProcessWalletTransactionUseCase } from '@core/payments/application/use-cases/ProcessWalletTransactionUseCase';
|
||||
|
||||
// Import concrete in-memory implementations
|
||||
import { InMemoryPaymentRepository } from '/payments/persistence/inmemory/InMemoryPaymentRepository';
|
||||
import { InMemoryMembershipFeeRepository, InMemoryMemberPaymentRepository } from '/payments/persistence/inmemory/InMemoryMembershipFeeRepository';
|
||||
import { InMemoryPrizeRepository } from '/payments/persistence/inmemory/InMemoryPrizeRepository';
|
||||
import { InMemoryWalletRepository, InMemoryTransactionRepository } from '/payments/persistence/inmemory/InMemoryWalletRepository';
|
||||
import { InMemoryPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryPaymentRepository';
|
||||
import { InMemoryMembershipFeeRepository, InMemoryMemberPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryMembershipFeeRepository';
|
||||
import { InMemoryPrizeRepository } from '@adapters/payments/persistence/inmemory/InMemoryPrizeRepository';
|
||||
import { InMemoryWalletRepository, InMemoryTransactionRepository } from '@adapters/payments/persistence/inmemory/InMemoryWalletRepository';
|
||||
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';
|
||||
|
||||
// Repository injection tokens
|
||||
|
||||
Reference in New Issue
Block a user