110 lines
4.6 KiB
TypeScript
110 lines
4.6 KiB
TypeScript
import { container } from '../../../src/Application/Services/DIContainer';
|
|
import { IUserRepository } from '../../../src/Domain/IRepository/IUserRepository';
|
|
import { IChatRepository } from '../../../src/Domain/IRepository/IChatRepository';
|
|
import { LoggingService } from '../../../src/Application/Services/LoggingService';
|
|
|
|
describe('DIContainer', () => {
|
|
// Cleanup after all tests to prevent Jest hanging
|
|
afterAll(async () => {
|
|
await LoggingService.getInstance().shutdown();
|
|
});
|
|
|
|
describe('Repositories', () => {
|
|
it('should return singleton IUserRepository instance', () => {
|
|
const repo1 = container.userRepository;
|
|
const repo2 = container.userRepository;
|
|
|
|
expect(repo1).toBeTruthy();
|
|
expect(repo1).toBe(repo2); // Same instance (singleton)
|
|
expect(typeof repo1.findById).toBe('function'); // Has interface methods
|
|
});
|
|
|
|
it('should return singleton IChatRepository instance', () => {
|
|
const repo1 = container.chatRepository;
|
|
const repo2 = container.chatRepository;
|
|
|
|
expect(repo1).toBeTruthy();
|
|
expect(repo1).toBe(repo2); // Same instance (singleton)
|
|
expect(typeof repo1.findById).toBe('function'); // Has interface methods
|
|
});
|
|
});
|
|
|
|
describe('Command Handlers', () => {
|
|
it('should return singleton CreateUserCommandHandler instance', () => {
|
|
const handler1 = container.createUserCommandHandler;
|
|
const handler2 = container.createUserCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton LoginCommandHandler instance', () => {
|
|
const handler1 = container.loginCommandHandler;
|
|
const handler2 = container.loginCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton DeactivateUserCommandHandler instance', () => {
|
|
const handler1 = container.deactivateUserCommandHandler;
|
|
const handler2 = container.deactivateUserCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton DeleteUserCommandHandler instance', () => {
|
|
const handler1 = container.deleteUserCommandHandler;
|
|
const handler2 = container.deleteUserCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton DeleteDeckCommandHandler instance', () => {
|
|
const handler1 = container.deleteDeckCommandHandler;
|
|
const handler2 = container.deleteDeckCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton DeleteOrganizationCommandHandler instance', () => {
|
|
const handler1 = container.deleteOrganizationCommandHandler;
|
|
const handler2 = container.deleteOrganizationCommandHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
});
|
|
|
|
describe('Query Handlers', () => {
|
|
it('should return singleton GetUserByIdQueryHandler instance', () => {
|
|
const handler1 = container.getUserByIdQueryHandler;
|
|
const handler2 = container.getUserByIdQueryHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
|
|
it('should return singleton GetUsersByPageQueryHandler instance', () => {
|
|
const handler1 = container.getUsersByPageQueryHandler;
|
|
const handler2 = container.getUsersByPageQueryHandler;
|
|
|
|
expect(handler1).toBeTruthy();
|
|
expect(handler1).toBe(handler2); // Same instance (singleton)
|
|
});
|
|
});
|
|
|
|
describe('Services', () => {
|
|
it('should return singleton JWTService instance', () => {
|
|
const service1 = container.jwtService;
|
|
const service2 = container.jwtService;
|
|
|
|
expect(service1).toBeTruthy();
|
|
expect(service1).toBe(service2); // Same instance (singleton)
|
|
});
|
|
});
|
|
});
|