@@ -127,4 +127,49 @@ describe('SNP integration tests', () => {
127127 hash : sampleEventsLastBlockHash ,
128128 } ) ;
129129 } ) ;
130+
131+ test ( 'handleMsg throws error when inject() fails' , async ( ) => {
132+ const snpClient = new SnpEventStreamHandler ( {
133+ db,
134+ eventServer,
135+ lastMessageId : '0' ,
136+ } ) ;
137+
138+ const originalInject = eventServer . fastifyInstance . inject . bind ( eventServer . fastifyInstance ) ;
139+ eventServer . fastifyInstance . inject = ( ) => {
140+ throw new Error ( 'Simulated inject failure' ) ;
141+ } ;
142+
143+ await expect (
144+ snpClient . handleMsg ( 'test-msg-id' , '2024-01-01T00:00:00Z' , '/test/path' , { } )
145+ ) . rejects . toThrow (
146+ 'Failed to process SNP message test-msg-id at path /test/path: Simulated inject failure'
147+ ) ;
148+
149+ eventServer . fastifyInstance . inject = originalInject ;
150+ } ) ;
151+
152+ test ( 'handleMsg throws error when response status is not 200' , async ( ) => {
153+ const snpClient = new SnpEventStreamHandler ( {
154+ db,
155+ eventServer,
156+ lastMessageId : '0' ,
157+ } ) ;
158+
159+ const originalInject = eventServer . fastifyInstance . inject . bind ( eventServer . fastifyInstance ) ;
160+ eventServer . fastifyInstance . inject = ( ( ) => {
161+ return Promise . resolve ( {
162+ statusCode : 500 ,
163+ body : 'Internal Server Error' ,
164+ } ) ;
165+ } ) as typeof eventServer . fastifyInstance . inject ;
166+
167+ await expect (
168+ snpClient . handleMsg ( 'test-msg-id' , '2024-01-01T00:00:00Z' , '/test/path' , { } )
169+ ) . rejects . toThrow (
170+ 'Failed to process SNP message test-msg-id at path /test/path, status: 500, body: Internal Server Error'
171+ ) ;
172+
173+ eventServer . fastifyInstance . inject = originalInject ;
174+ } ) ;
130175} ) ;
0 commit comments