1
/** @jest-environment node */
3
import { createMocks } from "node-mocks-http";
4
import handler from "@/src/pages/api/public/ingestion";
5
import { type NextApiResponse, type NextApiRequest } from "next";
6
import { Prisma } from "@prisma/client";
10
ERROR Error verifying auth header: PrismaClientKnownRequestError:
11
Invalid `prisma.apiKey.findUnique()` invocation:
12
Server has closed the connection.
13
at ai.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:126:6775)
14
at ai.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:126:6109)
15
at ai.request (/var/task/node_modules/@prisma/client/runtime/library.js:126:5817)
16
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:131:9709)
17
at async d (/var/task/.next/server/chunks/5811.js:1:9768)
18
at async f (/var/task/.next/server/pages/api/public/generations.js:1:1026)
19
at async /var/task/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:136:41
20
at async K (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16545)
21
at async U.render (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16981)
22
at async r3.runApi (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:41752) {
24
clientVersion: '5.9.1',
25
meta: { modelName: 'ApiKey' }
28
ERROR Error verifying auth header: PrismaClientKnownRequestError:
29
Invalid `prisma.apiKey.findUnique()` invocation:
30
Timed out fetching a new connection from the connection pool. More info: (Current connection pool timeout: 10, connection limit: 1)
31
at ai.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:126:6775)
32
at ai.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:126:6109)
33
at ai.request (/var/task/node_modules/@prisma/client/runtime/library.js:126:5817)
34
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:131:9709)
35
at async l (/var/task/.next/server/chunks/5811.js:1:9768)
36
at async y (/var/task/.next/server/pages/api/public/spans.js:1:1018)
37
at async /var/task/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:136:41
38
at async K (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16545)
39
at async U.render (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16981)
40
at async r3.runApi (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:41752) {
42
clientVersion: '5.9.1',
43
meta: { modelName: 'ApiKey', connection_limit: 1, timeout: 10 }
46
jest.mock("../server/db.ts", () => {
47
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
48
const originalModule = jest.requireActual("../server/db.ts");
50
// Create a mock for PrismaClient
51
const mockPrismaClient = {
55
findUnique: jest.fn(() => {
56
throw new Prisma.PrismaClientKnownRequestError(
57
"Timed out fetching a new connection from the connection pool. More info: (Current connection pool timeout: 10, connection limit: 1)",
60
clientVersion: "5.9.1",
61
meta: { modelName: "ApiKey", connection_limit: 1, timeout: 10 },
65
findUniqueOrThrow: jest.fn(),
66
findFirstOrThrow: jest.fn(),
68
createMany: jest.fn(),
71
updateMany: jest.fn(),
73
deleteMany: jest.fn(),
80
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
84
prisma: mockPrismaClient,
88
describe("/api/public/ingestion API Endpoint", () => {
89
it(`should return 500 for prisma exception`, async () => {
90
const { req, res } = createMocks({
93
authorization: "Bearer mock-token",
98
// Extend the req object to include the missing env property
99
const extendedReq = req as unknown as NextApiRequest;
100
// Cast the res object to NextApiResponse to satisfy the type requirement
101
const extendedRes = res as unknown as NextApiResponse;
103
await handler(extendedReq, extendedRes);
104
expect(res._getStatusCode()).toBe(500);