mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 17:12:10 +01:00
feat: complete tRPC integration and fix platform UI issues
- Implement comprehensive tRPC setup with type-safe API - Create tRPC routers for dashboard, admin, and auth endpoints - Migrate frontend components to use tRPC client - Fix platform dashboard Settings button functionality - Add platform settings page with profile and security management - Create OpenAI API mocking infrastructure for cost-safe testing - Update tests to work with new tRPC architecture - Sync database schema to fix AIBatchRequest table errors
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { processUnprocessedSessions, getAIProcessingCosts } from "../../lib/processingScheduler";
|
||||
import {
|
||||
processUnprocessedSessions,
|
||||
getAIProcessingCosts,
|
||||
} from "../../lib/processingScheduler";
|
||||
|
||||
vi.mock("../../lib/prisma", () => ({
|
||||
prisma: {
|
||||
@ -85,7 +88,9 @@ describe("Processing Scheduler", () => {
|
||||
|
||||
it("should handle errors gracefully", async () => {
|
||||
const { prisma } = await import("../../lib/prisma");
|
||||
vi.mocked(prisma.session.findMany).mockRejectedValue(new Error("Database error"));
|
||||
vi.mocked(prisma.session.findMany).mockRejectedValue(
|
||||
new Error("Database error")
|
||||
);
|
||||
|
||||
await expect(processUnprocessedSessions(1)).resolves.not.toThrow();
|
||||
});
|
||||
@ -95,7 +100,7 @@ describe("Processing Scheduler", () => {
|
||||
it("should calculate processing costs correctly", async () => {
|
||||
const mockAggregation = {
|
||||
_sum: {
|
||||
totalCostEur: 10.50,
|
||||
totalCostEur: 10.5,
|
||||
promptTokens: 1000,
|
||||
completionTokens: 500,
|
||||
totalTokens: 1500,
|
||||
@ -106,12 +111,14 @@ describe("Processing Scheduler", () => {
|
||||
};
|
||||
|
||||
const { prisma } = await import("../../lib/prisma");
|
||||
vi.mocked(prisma.aIProcessingRequest.aggregate).mockResolvedValue(mockAggregation);
|
||||
vi.mocked(prisma.aIProcessingRequest.aggregate).mockResolvedValue(
|
||||
mockAggregation
|
||||
);
|
||||
|
||||
const result = await getAIProcessingCosts();
|
||||
|
||||
expect(result).toEqual({
|
||||
totalCostEur: 10.50,
|
||||
totalCostEur: 10.5,
|
||||
totalRequests: 25,
|
||||
totalPromptTokens: 1000,
|
||||
totalCompletionTokens: 500,
|
||||
@ -133,7 +140,9 @@ describe("Processing Scheduler", () => {
|
||||
};
|
||||
|
||||
const { prisma } = await import("../../lib/prisma");
|
||||
vi.mocked(prisma.aIProcessingRequest.aggregate).mockResolvedValue(mockAggregation);
|
||||
vi.mocked(prisma.aIProcessingRequest.aggregate).mockResolvedValue(
|
||||
mockAggregation
|
||||
);
|
||||
|
||||
const result = await getAIProcessingCosts();
|
||||
|
||||
@ -146,4 +155,4 @@ describe("Processing Scheduler", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,8 +2,8 @@ import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { parseTranscriptToMessages } from "../../lib/transcriptParser";
|
||||
|
||||
describe("Transcript Parser", () => {
|
||||
const startTime = new Date('2024-01-01T10:00:00Z');
|
||||
const endTime = new Date('2024-01-01T10:30:00Z');
|
||||
const startTime = new Date("2024-01-01T10:00:00Z");
|
||||
const endTime = new Date("2024-01-01T10:30:00Z");
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@ -22,7 +22,9 @@ describe("Transcript Parser", () => {
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.messages).toHaveLength(3);
|
||||
expect(result.messages![0].role).toBe("User");
|
||||
expect(result.messages![0].content).toBe("Hello, I need help with my account");
|
||||
expect(result.messages![0].content).toBe(
|
||||
"Hello, I need help with my account"
|
||||
);
|
||||
expect(result.messages![1].role).toBe("Assistant");
|
||||
expect(result.messages![2].role).toBe("User");
|
||||
expect(result.messages![2].content).toBe("I can't log in to my account");
|
||||
@ -42,7 +44,9 @@ User: I need support with my order
|
||||
expect(result.messages![0].role).toBe("User");
|
||||
expect(result.messages![0].content).toBe("Hello there");
|
||||
expect(result.messages![1].role).toBe("Assistant");
|
||||
expect(result.messages![1].content).toBe("Hello! How can I help you today?");
|
||||
expect(result.messages![1].content).toBe(
|
||||
"Hello! How can I help you today?"
|
||||
);
|
||||
expect(result.messages![2].role).toBe("User");
|
||||
expect(result.messages![2].content).toBe("I need support with my order");
|
||||
});
|
||||
@ -124,15 +128,17 @@ User: Third
|
||||
it("should handle empty content", () => {
|
||||
expect(parseTranscriptToMessages("", startTime, endTime)).toEqual({
|
||||
success: false,
|
||||
error: "Empty transcript content"
|
||||
error: "Empty transcript content",
|
||||
});
|
||||
expect(parseTranscriptToMessages(" \n\n ", startTime, endTime)).toEqual({
|
||||
expect(
|
||||
parseTranscriptToMessages(" \n\n ", startTime, endTime)
|
||||
).toEqual({
|
||||
success: false,
|
||||
error: "Empty transcript content"
|
||||
error: "Empty transcript content",
|
||||
});
|
||||
expect(parseTranscriptToMessages("\t\r\n", startTime, endTime)).toEqual({
|
||||
success: false,
|
||||
error: "Empty transcript content"
|
||||
error: "Empty transcript content",
|
||||
});
|
||||
});
|
||||
|
||||
@ -185,4 +191,4 @@ System: Mixed case system
|
||||
expect(firstTimestamp.getSeconds()).toBe(45);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user