@@ -12,12 +12,17 @@ import { ObjectKernel } from '@objectstack/runtime';
1212describe ( 'ValidatorPlugin' , ( ) => {
1313 let plugin : ValidatorPlugin ;
1414 let mockKernel : any ;
15+ let mockCtx : any ;
1516
1617 beforeEach ( ( ) => {
1718 // Create a mock kernel with middleware support
1819 mockKernel = {
1920 use : jest . fn ( ) ,
2021 } ;
22+ mockCtx = {
23+ app : mockKernel ,
24+ hook : jest . fn ( ) ,
25+ } ;
2126 plugin = new ValidatorPlugin ( ) ;
2227 } ) ;
2328
@@ -54,62 +59,57 @@ describe('ValidatorPlugin', () => {
5459
5560 describe ( 'Installation' , ( ) => {
5661 it ( 'should install successfully with mock kernel' , async ( ) => {
57- const ctx = { app : mockKernel } ;
58- await plugin . init ( ctx ) ;
62+ await plugin . init ( mockCtx ) ;
5963
6064 // Verify that middleware hooks were registered
61- expect ( mockKernel . use ) . toHaveBeenCalled ( ) ;
65+ expect ( mockCtx . hook ) . toHaveBeenCalled ( ) ;
6266 } ) ;
6367
6468 it ( 'should register query validation when enabled' , async ( ) => {
6569 const pluginWithQuery = new ValidatorPlugin ( { enableQueryValidation : true } ) ;
66- const ctx = { app : mockKernel } ;
6770
68- await pluginWithQuery . init ( ctx ) ;
71+ await pluginWithQuery . init ( mockCtx ) ;
6972
7073 // Check that use was called (for query validation)
71- expect ( mockKernel . use ) . toHaveBeenCalledWith ( 'beforeQuery' , expect . any ( Function ) ) ;
74+ expect ( mockCtx . hook ) . toHaveBeenCalledWith ( 'beforeQuery' , expect . any ( Function ) ) ;
7275 } ) ;
7376
7477 it ( 'should register mutation validation when enabled' , async ( ) => {
7578 const pluginWithMutation = new ValidatorPlugin ( { enableMutationValidation : true } ) ;
76- const ctx = { app : mockKernel } ;
7779
78- await pluginWithMutation . init ( ctx ) ;
80+ await pluginWithMutation . init ( mockCtx ) ;
7981
8082 // Check that use was called (for mutation validation)
81- expect ( mockKernel . use ) . toHaveBeenCalledWith ( 'beforeMutation' , expect . any ( Function ) ) ;
83+ expect ( mockCtx . hook ) . toHaveBeenCalledWith ( 'beforeMutation' , expect . any ( Function ) ) ;
8284 } ) ;
8385
8486 it ( 'should not register query validation when disabled' , async ( ) => {
8587 const pluginNoQuery = new ValidatorPlugin ( { enableQueryValidation : false } ) ;
86- const ctx = { app : mockKernel } ;
8788
88- await pluginNoQuery . init ( ctx ) ;
89+ await pluginNoQuery . init ( mockCtx ) ;
8990
9091 // Should not have registered beforeQuery hook
91- const beforeQueryCalls = mockKernel . use . mock . calls . filter (
92+ const beforeQueryCalls = mockCtx . hook . mock . calls . filter (
9293 ( call : any [ ] ) => call [ 0 ] === 'beforeQuery'
9394 ) ;
9495 expect ( beforeQueryCalls . length ) . toBe ( 0 ) ;
9596 } ) ;
9697
9798 it ( 'should not register mutation validation when disabled' , async ( ) => {
9899 const pluginNoMutation = new ValidatorPlugin ( { enableMutationValidation : false } ) ;
99- const ctx = { app : mockKernel } ;
100100
101- await pluginNoMutation . init ( ctx ) ;
101+ await pluginNoMutation . init ( mockCtx ) ;
102102
103103 // Should not have registered beforeMutation hook
104- const beforeMutationCalls = mockKernel . use . mock . calls . filter (
104+ const beforeMutationCalls = mockCtx . hook . mock . calls . filter (
105105 ( call : any [ ] ) => call [ 0 ] === 'beforeMutation'
106106 ) ;
107107 expect ( beforeMutationCalls . length ) . toBe ( 0 ) ;
108108 } ) ;
109109
110110 it ( 'should handle kernel without middleware support' , async ( ) => {
111111 const kernelNoMiddleware = { } ;
112- const ctx = { app : kernelNoMiddleware } ;
112+ const ctx = { app : kernelNoMiddleware , hook : undefined } ; // Simulate no hook support
113113
114114 // Should not throw error
115115 await expect ( plugin . init ( ctx ) ) . resolves . not . toThrow ( ) ;
0 commit comments