Files
dbis_core-lite/tests/compliance/screening.test.ts
2026-02-09 21:51:45 -08:00

166 lines
5.4 KiB
TypeScript

import { ScreeningService } from '@/compliance/screening-engine/screening-service';
import { ScreeningRequest, ScreeningStatus } from '@/compliance/screening-engine/types';
import { PaymentRepository } from '@/repositories/payment-repository';
import { TestHelpers } from '../utils/test-helpers';
import { v4 as uuidv4 } from 'uuid';
describe('Compliance Screening Service', () => {
let screeningService: ScreeningService;
let paymentRepository: PaymentRepository;
let testPaymentId: string;
beforeAll(async () => {
paymentRepository = new PaymentRepository();
screeningService = new ScreeningService(paymentRepository);
});
beforeEach(async () => {
await TestHelpers.cleanDatabase();
// Create a test payment for screening
const paymentRequest = TestHelpers.createTestPaymentRequest();
const operator = await TestHelpers.createTestOperator('TEST_MAKER', 'MAKER' as any);
testPaymentId = await paymentRepository.create(
paymentRequest,
operator.id,
`TEST-${uuidv4()}`
);
});
afterAll(async () => {
await TestHelpers.cleanDatabase();
});
afterAll(async () => {
await TestHelpers.cleanDatabase();
});
describe('screen', () => {
it('should PASS screening for clean beneficiary', async () => {
const request: ScreeningRequest = {
paymentId: testPaymentId,
beneficiaryName: 'John Doe',
beneficiaryCountry: 'US',
receiverBIC: 'CLEANBIC1',
amount: 1000,
currency: 'USD',
};
const result = await screeningService.screen(request);
expect(result.status).toBe(ScreeningStatus.PASS);
expect(result.reasons).toBeUndefined();
expect(result.screeningId).toBeDefined();
expect(result.screenedAt).toBeInstanceOf(Date);
});
it('should FAIL screening if beneficiary name matches sanctions', async () => {
// Note: This test assumes SanctionsChecker will fail for specific names
// In real implementation, you'd mock or configure test sanctions data
const request: ScreeningRequest = {
paymentId: testPaymentId,
beneficiaryName: 'SANCTIONED PERSON', // Should trigger sanctions check
beneficiaryCountry: 'US',
receiverBIC: 'CLEANBIC2',
amount: 1000,
currency: 'USD',
};
const result = await screeningService.screen(request);
// Result depends on actual sanctions checker implementation
expect(result.status).toBeDefined();
expect(['PASS', 'FAIL']).toContain(result.status);
expect(result.screeningId).toBeDefined();
});
it('should check BIC sanctions', async () => {
const request: ScreeningRequest = {
paymentId: testPaymentId,
beneficiaryName: 'Clean Beneficiary',
beneficiaryCountry: 'US',
receiverBIC: 'SANCTIONED_BIC', // Should trigger BIC check
amount: 1000,
currency: 'USD',
};
const result = await screeningService.screen(request);
expect(result.status).toBeDefined();
expect(result.screeningId).toBeDefined();
});
it('should update payment with compliance status', async () => {
const request: ScreeningRequest = {
paymentId: testPaymentId,
beneficiaryName: 'Clean Beneficiary',
beneficiaryCountry: 'US',
receiverBIC: 'CLEANBIC3',
amount: 1000,
currency: 'USD',
};
await screeningService.screen(request);
const payment = await paymentRepository.findById(testPaymentId);
expect(payment?.complianceStatus).toBeDefined();
expect(['PASS', 'FAIL', 'PENDING']).toContain(payment?.complianceStatus);
expect(payment?.complianceScreeningId).toBeDefined();
});
it('should handle screening errors gracefully', async () => {
const invalidRequest: ScreeningRequest = {
paymentId: 'non-existent-payment-id',
beneficiaryName: 'Test',
receiverBIC: 'TESTBIC',
amount: 1000,
currency: 'USD',
};
// Should handle error and return FAIL status
const result = await screeningService.screen(invalidRequest);
expect(result.status).toBe(ScreeningStatus.FAIL);
expect(result.reasons).toBeDefined();
expect(result.reasons?.length).toBeGreaterThan(0);
});
});
describe('isScreeningPassed', () => {
it('should return true if screening passed', async () => {
const request: ScreeningRequest = {
paymentId: testPaymentId,
beneficiaryName: 'Clean Beneficiary',
beneficiaryCountry: 'US',
receiverBIC: 'CLEANBIC4',
amount: 1000,
currency: 'USD',
};
await screeningService.screen(request);
// Update payment status to PASS manually for this test
await paymentRepository.update(testPaymentId, {
complianceStatus: 'PASS' as any,
});
const passed = await screeningService.isScreeningPassed(testPaymentId);
expect(passed).toBe(true);
});
it('should return false if screening failed', async () => {
await paymentRepository.update(testPaymentId, {
complianceStatus: 'FAIL' as any,
});
const passed = await screeningService.isScreeningPassed(testPaymentId);
expect(passed).toBe(false);
});
it('should return false for non-existent payment', async () => {
const passed = await screeningService.isScreeningPassed('uuidv4()');
expect(passed).toBe(false);
});
});
});