78 lines
No EOL
3 KiB
TypeScript
78 lines
No EOL
3 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach, mock } from 'bun:test';
|
|
import { autoRegisterHandlers, createAutoHandlerRegistry } from '../src/registry/auto-register';
|
|
import { BaseHandler } from '../src/base/BaseHandler';
|
|
import type { IServiceContainer } from '@stock-bot/types';
|
|
|
|
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([]);
|
|
});
|
|
});
|
|
}); |