@bsv/overlay-express 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,11 @@ function createMockDbValue (): Record<string, any> {
22
22
  deleteOne: jest.fn<any>().mockResolvedValue({}),
23
23
  countDocuments: jest.fn<any>().mockResolvedValue(0)
24
24
  }
25
- return { collection: jest.fn<any>().mockReturnValue(mockCollection) }
25
+ return {
26
+ collection: jest.fn<any>().mockReturnValue(mockCollection),
27
+ command: jest.fn<any>().mockResolvedValue({ ok: 1 }),
28
+ databaseName: 'TestService_lookup_services'
29
+ }
26
30
  }
27
31
 
28
32
  describe('OverlayExpress', () => {
@@ -753,7 +757,21 @@ describe('OverlayExpress', () => {
753
757
  expect(corsMiddleware).toBeDefined()
754
758
  })
755
759
 
756
- it('should register health check route', async () => {
760
+ it('should register health check routes', async () => {
761
+ const getSpy = jest.spyOn(instance.app, 'get')
762
+ jest.spyOn(instance.app, 'listen').mockImplementation((port: any, callback: any) => {
763
+ callback()
764
+ return {} as any
765
+ })
766
+
767
+ await instance.start()
768
+
769
+ expect(getSpy.mock.calls.find(call => call[0] === '/health')).toBeDefined()
770
+ expect(getSpy.mock.calls.find(call => call[0] === '/health/live')).toBeDefined()
771
+ expect(getSpy.mock.calls.find(call => call[0] === '/health/ready')).toBeDefined()
772
+ })
773
+
774
+ it('should return detailed readiness health', async () => {
757
775
  const getSpy = jest.spyOn(instance.app, 'get')
758
776
  jest.spyOn(instance.app, 'listen').mockImplementation((port: any, callback: any) => {
759
777
  callback()
@@ -762,8 +780,28 @@ describe('OverlayExpress', () => {
762
780
 
763
781
  await instance.start()
764
782
 
765
- const healthRoute = getSpy.mock.calls.find(call => call[0] === '/health')
766
- expect(healthRoute).toBeDefined()
783
+ const readyRoute = getSpy.mock.calls.find(call => call[0] === '/health/ready')
784
+ const res = {
785
+ status: jest.fn().mockReturnThis(),
786
+ json: jest.fn()
787
+ }
788
+
789
+ readyRoute?.[1]({} as any, res as any)
790
+ await new Promise(resolve => setImmediate(resolve))
791
+
792
+ expect(res.status).toHaveBeenCalledWith(200)
793
+ expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
794
+ status: 'ok',
795
+ ready: true,
796
+ service: expect.objectContaining({
797
+ name: 'TestServer'
798
+ }),
799
+ checks: expect.arrayContaining([
800
+ expect.objectContaining({ name: 'engine', status: 'ok' }),
801
+ expect.objectContaining({ name: 'knex', status: 'ok' }),
802
+ expect.objectContaining({ name: 'mongo', status: 'ok' })
803
+ ])
804
+ }))
767
805
  })
768
806
 
769
807
  it('should register admin routes', async () => {
@@ -0,0 +1,16 @@
1
+ declare module '@bsv/auth-express-middleware' {
2
+ import type { RequestHandler } from 'express'
3
+
4
+ export interface AuthRequest {
5
+ auth?: {
6
+ identityKey?: string
7
+ certificates?: Array<{
8
+ certifier?: string
9
+ type?: string
10
+ decryptedFields?: Record<string, any>
11
+ }>
12
+ }
13
+ }
14
+
15
+ export function createAuthMiddleware (config: Record<string, any>): RequestHandler
16
+ }