stock-bot/libs/core/handlers/test/auto-register-simple.test.ts
2025-06-26 16:12:27 -04:00

75 lines
2.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
import type { IServiceContainer } from '@stock-bot/types';
import { BaseHandler } from '../src/base/BaseHandler';
import { autoRegisterHandlers, createAutoHandlerRegistry } from '../src/registry/auto-register';
describe('Auto Registration - Simple Tests', () => {
describe('autoRegisterHandlers', () => {
it('should return empty results for non-existent directory', async () => {
const mockServices = {} as IServiceContainer;
const result = await autoRegisterHandlers('./non-existent-directory', mockServices);
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
it('should handle directory with no handler files', async () => {
const mockServices = {} as IServiceContainer;
// Use the test directory itself which has no handler files
const result = await autoRegisterHandlers('./test', mockServices);
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
it('should support dry run mode', async () => {
const mockServices = {} as IServiceContainer;
const result = await autoRegisterHandlers('./non-existent', mockServices, { dryRun: true });
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
it('should handle excluded patterns', async () => {
const mockServices = {} as IServiceContainer;
const result = await autoRegisterHandlers('./test', mockServices, {
exclude: ['test'],
});
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
it('should accept custom pattern', async () => {
const mockServices = {} as IServiceContainer;
const result = await autoRegisterHandlers('./test', mockServices, {
pattern: '.custom.',
});
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
});
describe('createAutoHandlerRegistry', () => {
it('should create registry with registerDirectory method', () => {
const mockServices = {} as IServiceContainer;
const registry = createAutoHandlerRegistry(mockServices);
expect(registry).toHaveProperty('registerDirectory');
expect(registry).toHaveProperty('registerDirectories');
expect(typeof registry.registerDirectory).toBe('function');
expect(typeof registry.registerDirectories).toBe('function');
});
it('should register from multiple directories', async () => {
const mockServices = {} as IServiceContainer;
const registry = createAutoHandlerRegistry(mockServices);
const result = await registry.registerDirectories(['./non-existent-1', './non-existent-2']);
expect(result.registered).toEqual([]);
expect(result.failed).toEqual([]);
});
});
});