Pull the Fastify instance off the running server for hermetic REST injects.
(r: RunningServer)
| 71 | |
| 72 | /** Pull the Fastify instance off the running server for hermetic REST injects. */ |
| 73 | function appOf(r: RunningServer): { |
| 74 | inject: (req: unknown) => Promise<{ statusCode: number; json: () => unknown }>; |
| 75 | } { |
| 76 | const app = r.services.invokeFunction((a) => { |
| 77 | const gw = a.get(IRestGateway); |
| 78 | return gw.app as unknown as { |
| 79 | inject: (req: unknown) => Promise<{ statusCode: number; json: () => unknown }>; |
| 80 | }; |
| 81 | }); |
| 82 | // Auto-attach the fixed bearer token so the M5.1 auth hook passes. A |
| 83 | // caller-supplied `authorization` header wins, so explicit token tests keep |
| 84 | // working; every other header (Range, content-type, …) is preserved. |
| 85 | return { |
| 86 | inject(req: unknown) { |
| 87 | const q = req as { headers?: Record<string, string | string[] | undefined> }; |
| 88 | return app.inject({ |
| 89 | ...q, |
| 90 | headers: { authorization: 'Bearer test-token', ...q.headers }, |
| 91 | }); |
| 92 | }, |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | function wsUrl(http: string): string { |
| 97 | return http.replace(/^http:\/\//, 'ws://') + '/api/v1/ws'; |
no test coverage detected