Skip to content

Commit ed823c9

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/224-caching' into 224-caching
2 parents 79040af + cdf121b commit ed823c9

1 file changed

Lines changed: 0 additions & 195 deletions

File tree

cache/__tests__/cache.test.js

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

0 commit comments

Comments
 (0)