refactor(api): allow router handler injection in tests

This commit is contained in:
2026-04-21 13:10:00 +00:00
parent 0921dfbe5e
commit c95961d596
2 changed files with 48 additions and 5 deletions
+33
View File
@@ -1,5 +1,6 @@
import { assertEquals } from 'jsr:@std/assert@^1.0.0';
import { EventEmitter } from 'node:events';
import { AuthMiddleware } from '../ts/api/middleware/auth.ts';
import { ApiRouter } from '../ts/api/router.ts';
class TestResponse {
@@ -49,6 +50,38 @@ function createRouter(): ApiRouter {
{} as never,
{} as never,
['valid-key'],
{
authMiddleware: new AuthMiddleware(['valid-key']),
sanityMiddleware: {
validateChatRequest() {
return { valid: true };
},
sanitizeChatRequest(body: Record<string, unknown>) {
return body;
},
validateEmbeddingsRequest() {
return { valid: true };
},
sanitizeEmbeddingsRequest(body: Record<string, unknown>) {
return body;
},
} as never,
chatHandler: {
async handleChatCompletion() {
throw new Error('chat handler should not run in this test');
},
} as never,
modelsHandler: {
async handleListModels() {
throw new Error('models handler should not run in this test');
},
} as never,
embeddingsHandler: {
async handleEmbeddings() {
throw new Error('embeddings handler should not run in this test');
},
} as never,
},
);
}