Initial commit: add .gitignore and README

This commit is contained in:
defiQUG
2026-02-09 21:51:45 -08:00
commit 929fe6f6b6
240 changed files with 40977 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
/**
* Unit tests for Export Validator
*/
import { ExportValidator } from '@/exports/utils/export-validator';
import { ExportQuery, ExportFormat, ExportScope } from '@/exports/types';
describe('ExportValidator', () => {
describe('validateQuery', () => {
it('should validate correct query parameters', () => {
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
startDate: new Date('2024-01-01'),
endDate: new Date('2024-01-31'),
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(true);
expect(result.errors.length).toBe(0);
});
it('should detect invalid date range', () => {
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
startDate: new Date('2024-01-31'),
endDate: new Date('2024-01-01'), // End before start
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(false);
expect(result.errors).toContain('Start date must be before end date');
});
it('should detect date range exceeding 365 days', () => {
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
startDate: new Date('2024-01-01'),
endDate: new Date('2025-01-10'), // More than 365 days
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(false);
expect(result.errors).toContain('Date range cannot exceed 365 days');
});
it('should validate UETR format', () => {
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
uetr: 'invalid-uetr-format',
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(false);
expect(result.errors).toContain('Invalid UETR format. Must be a valid UUID.');
});
it('should accept valid UETR format', () => {
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
uetr: '123e4567-e89b-12d3-a456-426614174000',
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(true);
});
it('should validate account number length', () => {
const longAccountNumber = 'A'.repeat(101); // Exceeds 100 characters
const query: ExportQuery = {
format: ExportFormat.RAW_ISO,
scope: ExportScope.MESSAGES,
accountNumber: longAccountNumber,
};
const result = ExportValidator.validateQuery(query);
expect(result.valid).toBe(false);
expect(result.errors).toContain('Account number cannot exceed 100 characters');
});
});
describe('validateFileSize', () => {
it('should validate file size within limit', () => {
const result = ExportValidator.validateFileSize(1024 * 1024); // 1 MB
expect(result.valid).toBe(true);
});
it('should detect file size exceeding limit', () => {
const result = ExportValidator.validateFileSize(200 * 1024 * 1024); // 200 MB
expect(result.valid).toBe(false);
expect(result.error).toContain('exceeds maximum allowed size');
});
it('should detect empty file', () => {
const result = ExportValidator.validateFileSize(0);
expect(result.valid).toBe(false);
expect(result.error).toContain('Export file is empty');
});
});
describe('validateRecordCount', () => {
it('should validate record count within limit', () => {
const result = ExportValidator.validateRecordCount(100);
expect(result.valid).toBe(true);
});
it('should detect record count exceeding limit', () => {
const result = ExportValidator.validateRecordCount(20000);
expect(result.valid).toBe(false);
expect(result.error).toContain('exceeds maximum batch size');
});
it('should detect zero record count', () => {
const result = ExportValidator.validateRecordCount(0);
expect(result.valid).toBe(false);
expect(result.error).toContain('No records found for export');
});
});
});