@@ -481,198 +481,3 @@ describe('Cache Statistics', () => {
481481 expect ( cache . cache . size ) . toBe ( 1 )
482482 } )
483483} )
484-
485- describe ( 'GOG Endpoint Cache Middleware' , ( ) => {
486- let mockReq
487- let mockRes
488- let mockNext
489-
490- beforeEach ( ( ) => {
491- // Clear cache before each test
492- cache . clear ( )
493-
494- // Reset mock request
495- mockReq = {
496- method : 'POST' ,
497- body : { } ,
498- query : { } ,
499- params : { }
500- }
501-
502- // Reset mock response
503- mockRes = {
504- statusCode : 200 ,
505- headers : { } ,
506- set : jest . fn ( function ( key , value ) {
507- if ( typeof key === 'object' ) {
508- Object . assign ( this . headers , key )
509- } else {
510- this . headers [ key ] = value
511- }
512- return this
513- } ) ,
514- status : jest . fn ( function ( code ) {
515- this . statusCode = code
516- return this
517- } ) ,
518- json : jest . fn ( function ( data ) {
519- this . jsonData = data
520- return this
521- } )
522- }
523-
524- // Reset mock next
525- mockNext = jest . fn ( )
526- } )
527-
528- afterEach ( ( ) => {
529- cache . clear ( )
530- } )
531-
532- describe ( 'cacheGogFragments middleware' , ( ) => {
533- it ( 'should pass through when ManuscriptWitness is missing' , ( ) => {
534- mockReq . body = { }
535-
536- cacheGogFragments ( mockReq , mockRes , mockNext )
537-
538- expect ( mockNext ) . toHaveBeenCalled ( )
539- expect ( mockRes . json ) . not . toHaveBeenCalled ( )
540- } )
541-
542- it ( 'should pass through when ManuscriptWitness is invalid' , ( ) => {
543- mockReq . body = { ManuscriptWitness : 'not-a-url' }
544-
545- cacheGogFragments ( mockReq , mockRes , mockNext )
546-
547- expect ( mockNext ) . toHaveBeenCalled ( )
548- expect ( mockRes . json ) . not . toHaveBeenCalled ( )
549- } )
550-
551- it ( 'should return cache MISS on first request' , ( ) => {
552- mockReq . body = { ManuscriptWitness : 'https://example.org/manuscript/1' }
553- mockReq . query = { limit : '50' , skip : '0' }
554-
555- cacheGogFragments ( mockReq , mockRes , mockNext )
556-
557- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
558- expect ( mockNext ) . toHaveBeenCalled ( )
559- } )
560-
561- it ( 'should return cache HIT on second identical request' , ( ) => {
562- mockReq . body = { ManuscriptWitness : 'https://example.org/manuscript/1' }
563- mockReq . query = { limit : '50' , skip : '0' }
564-
565- // First request - populate cache
566- cacheGogFragments ( mockReq , mockRes , mockNext )
567- mockRes . json ( [ { '@id' : 'fragment1' , '@type' : 'WitnessFragment' } ] )
568-
569- // Reset mocks for second request
570- mockRes . headers = { }
571- mockRes . json = jest . fn ( )
572- mockNext = jest . fn ( )
573-
574- // Second request - should hit cache
575- cacheGogFragments ( mockReq , mockRes , mockNext )
576-
577- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'HIT' )
578- expect ( mockRes . json ) . toHaveBeenCalledWith ( [ { '@id' : 'fragment1' , '@type' : 'WitnessFragment' } ] )
579- expect ( mockNext ) . not . toHaveBeenCalled ( )
580- } )
581-
582- it ( 'should cache based on pagination parameters' , ( ) => {
583- const manuscriptURI = 'https://example.org/manuscript/1'
584-
585- // Request with limit=50, skip=0
586- mockReq . body = { ManuscriptWitness : manuscriptURI }
587- mockReq . query = { limit : '50' , skip : '0' }
588-
589- cacheGogFragments ( mockReq , mockRes , mockNext )
590- mockRes . json ( [ { '@id' : 'fragment1' } ] )
591-
592- // Request with different pagination - should be MISS
593- mockRes . headers = { }
594- mockRes . json = jest . fn ( )
595- mockNext = jest . fn ( )
596- mockReq . query = { limit : '100' , skip : '0' }
597-
598- cacheGogFragments ( mockReq , mockRes , mockNext )
599-
600- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
601- expect ( mockNext ) . toHaveBeenCalled ( )
602- } )
603- } )
604-
605- describe ( 'cacheGogGlosses middleware' , ( ) => {
606- it ( 'should pass through when ManuscriptWitness is missing' , ( ) => {
607- mockReq . body = { }
608-
609- cacheGogGlosses ( mockReq , mockRes , mockNext )
610-
611- expect ( mockNext ) . toHaveBeenCalled ( )
612- expect ( mockRes . json ) . not . toHaveBeenCalled ( )
613- } )
614-
615- it ( 'should pass through when ManuscriptWitness is invalid' , ( ) => {
616- mockReq . body = { ManuscriptWitness : 'not-a-url' }
617-
618- cacheGogGlosses ( mockReq , mockRes , mockNext )
619-
620- expect ( mockNext ) . toHaveBeenCalled ( )
621- expect ( mockRes . json ) . not . toHaveBeenCalled ( )
622- } )
623-
624- it ( 'should return cache MISS on first request' , ( ) => {
625- mockReq . body = { ManuscriptWitness : 'https://example.org/manuscript/1' }
626- mockReq . query = { limit : '50' , skip : '0' }
627-
628- cacheGogGlosses ( mockReq , mockRes , mockNext )
629-
630- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
631- expect ( mockNext ) . toHaveBeenCalled ( )
632- } )
633-
634- it ( 'should return cache HIT on second identical request' , ( ) => {
635- mockReq . body = { ManuscriptWitness : 'https://example.org/manuscript/1' }
636- mockReq . query = { limit : '50' , skip : '0' }
637-
638- // First request - populate cache
639- cacheGogGlosses ( mockReq , mockRes , mockNext )
640- mockRes . json ( [ { '@id' : 'gloss1' , '@type' : 'Gloss' } ] )
641-
642- // Reset mocks for second request
643- mockRes . headers = { }
644- mockRes . json = jest . fn ( )
645- mockNext = jest . fn ( )
646-
647- // Second request - should hit cache
648- cacheGogGlosses ( mockReq , mockRes , mockNext )
649-
650- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'HIT' )
651- expect ( mockRes . json ) . toHaveBeenCalledWith ( [ { '@id' : 'gloss1' , '@type' : 'Gloss' } ] )
652- expect ( mockNext ) . not . toHaveBeenCalled ( )
653- } )
654-
655- it ( 'should cache based on pagination parameters' , ( ) => {
656- const manuscriptURI = 'https://example.org/manuscript/1'
657-
658- // Request with limit=50, skip=0
659- mockReq . body = { ManuscriptWitness : manuscriptURI }
660- mockReq . query = { limit : '50' , skip : '0' }
661-
662- cacheGogGlosses ( mockReq , mockRes , mockNext )
663- mockRes . json ( [ { '@id' : 'gloss1' } ] )
664-
665- // Request with different pagination - should be MISS
666- mockRes . headers = { }
667- mockRes . json = jest . fn ( )
668- mockNext = jest . fn ( )
669- mockReq . query = { limit : '100' , skip : '0' }
670-
671- cacheGogGlosses ( mockReq , mockRes , mockNext )
672-
673- expect ( mockRes . headers [ 'X-Cache' ] ) . toBe ( 'MISS' )
674- expect ( mockNext ) . toHaveBeenCalled ( )
675- } )
676- } )
677- } )
678-
0 commit comments