(options: MockRequestOptions)
| 24 | * - req.files |
| 25 | */ |
| 26 | export function createMockRequest(options: MockRequestOptions): Request { |
| 27 | const { chatflowId, body = {}, sourceRequest, files = [] } = options |
| 28 | |
| 29 | const headers: Record<string, string | string[] | undefined> = sourceRequest ? { ...sourceRequest.headers } : { host: 'localhost:3000' } |
| 30 | |
| 31 | return { |
| 32 | params: { id: chatflowId }, |
| 33 | body: { |
| 34 | streaming: true, |
| 35 | question: '', |
| 36 | ...body |
| 37 | }, |
| 38 | get: (header: string) => { |
| 39 | if (sourceRequest) return sourceRequest.get(header) |
| 40 | const lower = header.toLowerCase() |
| 41 | const val = headers[lower] |
| 42 | return typeof val === 'string' ? val : undefined |
| 43 | }, |
| 44 | protocol: sourceRequest?.protocol ?? 'http', |
| 45 | headers, |
| 46 | files |
| 47 | } as unknown as Request |
| 48 | } |
no test coverage detected