mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(core): Validate shutdown handlers on startup (#8260)
This commit is contained in:
@@ -124,4 +124,36 @@ describe('ShutdownService', () => {
|
||||
expect(shutdownService.isShuttingDown()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validate', () => {
|
||||
it('should throw error if component is not registered with the DI container', () => {
|
||||
class UnregisteredComponent {
|
||||
onShutdown() {}
|
||||
}
|
||||
|
||||
shutdownService.register(10, {
|
||||
serviceClass: UnregisteredComponent as unknown as ServiceClass,
|
||||
methodName: 'onShutdown',
|
||||
});
|
||||
|
||||
expect(() => shutdownService.validate()).toThrow(
|
||||
'Component "UnregisteredComponent" is not registered with the DI container. Any component using @OnShutdown() must be decorated with @Service()',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error if component is missing the shutdown method', () => {
|
||||
class TestComponent {}
|
||||
|
||||
shutdownService.register(10, {
|
||||
serviceClass: TestComponent as unknown as ServiceClass,
|
||||
methodName: 'onShutdown',
|
||||
});
|
||||
|
||||
Container.set(TestComponent, new TestComponent());
|
||||
|
||||
expect(() => shutdownService.validate()).toThrow(
|
||||
'Component "TestComponent" does not have a "onShutdown" method',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user