@@ -122,6 +122,31 @@ describe('Cache Middleware Tests', () => {
122122 cacheQuery ( mockReq , mockRes , mockNext )
123123 expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
124124 } )
125+
126+ it ( 'should create different cache keys for different query bodies' , ( ) => {
127+ mockReq . method = 'POST'
128+ mockReq . query = { limit : '100' , skip : '0' }
129+
130+ // First request for Annotations
131+ mockReq . body = { type : 'Annotation' }
132+ cacheQuery ( mockReq , mockRes , mockNext )
133+ mockRes . json ( [ { id : '1' , type : 'Annotation' } ] )
134+
135+ // Reset mocks for second request
136+ mockRes . headers = { }
137+ const jsonSpy = jest . fn ( )
138+ mockRes . json = jsonSpy
139+ mockNext = jest . fn ( )
140+
141+ // Second request for Person (different body, should be MISS)
142+ mockReq . body = { type : 'Person' }
143+ cacheQuery ( mockReq , mockRes , mockNext )
144+
145+ expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
146+ expect ( mockNext ) . toHaveBeenCalled ( )
147+ // json was replaced by middleware, so check it wasn't called before next()
148+ expect ( jsonSpy ) . not . toHaveBeenCalled ( )
149+ } )
125150 } )
126151
127152 describe ( 'cacheSearch middleware' , ( ) => {
0 commit comments