Backend Complete: Interface Refactoring & Service Container Enhancements
Repository Interface Optimization: - Created IBaseRepository.ts and IPaginatedRepository.ts - Refactored all 7 repository interfaces to extend base interfaces - Eliminated ~200 lines of redundant code (70% reduction) - Improved type safety and maintainability Dependency Injection Improvements: - Added EmailService and GameTokenService to DIContainer - Updated CreateUserCommandHandler constructor for DI - Updated RequestPasswordResetCommandHandler constructor for DI - Enhanced testability and service consistency Environment Configuration: - Created comprehensive .env.example with 40+ variables - Organized into 12 logical sections (Database, Security, Email, etc.) - Added security guidelines and best practices - Documented all backend environment requirements Documentation: - Added comprehensive codebase review - Created refactoring summary report - Added frontend implementation guide Impact: Improved code quality, reduced maintenance overhead, enhanced developer experience
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
import { ContactMapper } from '../../../../src/Application/DTOs/Mappers/ContactMapper';
|
||||
import { ContactType, ContactState } from '../../../../src/Domain/Contact/ContactAggregate';
|
||||
|
||||
describe('ContactMapper', () => {
|
||||
const createMockContact = (overrides: any = {}) => ({
|
||||
id: 'contact-123',
|
||||
name: 'John Doe',
|
||||
email: 'john.doe@example.com',
|
||||
userid: 'user-456',
|
||||
type: ContactType.QUESTION,
|
||||
txt: 'This is a test contact message.',
|
||||
state: ContactState.ACTIVE,
|
||||
createDate: new Date('2024-01-01'),
|
||||
updateDate: new Date('2024-01-02'),
|
||||
adminResponse: null,
|
||||
responseDate: null,
|
||||
respondedBy: null,
|
||||
...overrides
|
||||
});
|
||||
|
||||
describe('toShortDto', () => {
|
||||
it('should map ContactAggregate to ShortContactDto correctly', () => {
|
||||
// Arrange
|
||||
const contact = createMockContact();
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toShortDto(contact);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual({
|
||||
id: 'contact-123',
|
||||
name: 'John Doe',
|
||||
email: 'john.doe@example.com',
|
||||
type: ContactType.QUESTION,
|
||||
createDate: new Date('2024-01-01'),
|
||||
state: ContactState.ACTIVE,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle different contact types', () => {
|
||||
// Arrange
|
||||
const bugContact = createMockContact({
|
||||
id: 'bug-contact',
|
||||
type: ContactType.BUG,
|
||||
name: 'Bug Reporter'
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toShortDto(bugContact);
|
||||
|
||||
// Assert
|
||||
expect(result.type).toBe(ContactType.BUG);
|
||||
expect(result.name).toBe('Bug Reporter');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toDetailDto', () => {
|
||||
it('should map ContactAggregate to DetailContactDto correctly', () => {
|
||||
// Arrange
|
||||
const contact = createMockContact();
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toDetailDto(contact);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual({
|
||||
id: 'contact-123',
|
||||
name: 'John Doe',
|
||||
email: 'john.doe@example.com',
|
||||
userid: 'user-456',
|
||||
type: ContactType.QUESTION,
|
||||
txt: 'This is a test contact message.',
|
||||
state: ContactState.ACTIVE,
|
||||
createDate: new Date('2024-01-01'),
|
||||
updateDate: new Date('2024-01-02'),
|
||||
adminResponse: null,
|
||||
responseDate: null,
|
||||
respondedBy: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle contact with admin response', () => {
|
||||
// Arrange
|
||||
const respondedContact = createMockContact({
|
||||
adminResponse: 'Thank you for your question. Here is the answer...',
|
||||
responseDate: new Date('2024-01-03'),
|
||||
respondedBy: 'admin-789'
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toDetailDto(respondedContact);
|
||||
|
||||
// Assert
|
||||
expect(result.adminResponse).toBe('Thank you for your question. Here is the answer...');
|
||||
expect(result.responseDate).toEqual(new Date('2024-01-03'));
|
||||
expect(result.respondedBy).toBe('admin-789');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toShortDtoList', () => {
|
||||
it('should map array of ContactAggregate to array of ShortContactDto', () => {
|
||||
// Arrange
|
||||
const contacts = [
|
||||
createMockContact({ id: 'contact-1', name: 'First Contact' }),
|
||||
createMockContact({ id: 'contact-2', name: 'Second Contact', type: ContactType.BUG }),
|
||||
createMockContact({ id: 'contact-3', name: 'Third Contact', type: ContactType.SALES })
|
||||
];
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toShortDtoList(contacts);
|
||||
|
||||
// Assert
|
||||
expect(result).toHaveLength(3);
|
||||
expect(result[0]).toEqual({
|
||||
id: 'contact-1',
|
||||
name: 'First Contact',
|
||||
email: 'john.doe@example.com',
|
||||
type: ContactType.QUESTION,
|
||||
createDate: new Date('2024-01-01'),
|
||||
state: ContactState.ACTIVE,
|
||||
});
|
||||
expect(result[1].type).toBe(ContactType.BUG);
|
||||
expect(result[2].type).toBe(ContactType.SALES);
|
||||
});
|
||||
|
||||
it('should handle empty array', () => {
|
||||
// Arrange
|
||||
const contacts: any[] = [];
|
||||
|
||||
// Act
|
||||
const result = ContactMapper.toShortDtoList(contacts);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user