Despite encountering an environment variable not found error, I have a similar code example where the database connection works fine. Here is the function and model:
model sdk_error {
view_id String @id
message String
timestamp DateTime
}
const errorIngestionHandler = async (req: Request, res: Response) => {
const time = new Date('November 8, 2022, 12:00:00');
const errorModel = await prisma.sdk_error.create({
data: {
view_id: '1234',
message: 'this is a test',
timestamp: time,
},
});
const ret = await prisma.sdk_error.findUnique({
where: {
view_id: errorModel.view_id,
},
});
res.send(ret);
};
I am attempting to test my request handler by creating a test input for comparison. The issue arises with the create function resulting in the following error:
Invalid prisma.sdk_error.create()
invocation in C:\Users\cmb\vlly\vlly-api\src\v1\ingestion\error.ts:6:45
3 //Errors
4 const errorIngestionHandler = async (req: Request, res: Response) => {
5 const time = new Date('November 8, 2022, 12:00:00');
→ 6 const errorModel = await prisma.sdk_error.create(
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:12
|
11 | provider = "mysql"
12 | url = env("DATABASE_URL")
Validation Error Count: 1
4 | const errorIngestionHandler = async (req: Request, res: Response) => {
5 | const time = new Date('November 8, 2022, 12:00:00');
> 6 | const errorModel = await prisma.sdk_error.create({
| ^
7 | data: {
8 | view_id: '1234',
9 | message: 'this is a test',
at RequestHandler.handleRequestError (node_modules/@prisma/client/runtime/index.js:34316:13)
at node_modules/@prisma/client/runtime/index.js:34737:25
at PrismaClient._executeRequest (node_modules/@prisma/client/runtime/index.js:35301:22)
at PrismaClient._request (node_modules/@prisma/client/runtime/index.js:35273:16)
at errorIngestionHandler (src/v1/ingestion/error.ts:6:22)
● API Endpoint test › creates new row in error table
Invalid `prisma.sdk_error.create()` invocation in C:\Users\cmb\vlly\vlly-api\src\v1\ingestion\error.ts:6:45
3 //Errors
4 const errorIngestionHandler = async (req: Request, res: Response) => {
5 const time = new Date('November 8, 2022, 12:00:00');
→ 6 const errorModel = await prisma.sdk_error.create(
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:12
|
11 | provider = "mysql"
12 | url = env("DATABASE_URL")
|
Validation Error Count: 1
4 | const errorIngestionHandler = async (req: Request, res: Response) => {
5 | const time = new Date('November 8, 2022, 12:00:00');
> 6 | const errorModel = await prisma.sdk_error.create({
| ^
7 | data: {
8 | view_id: '1234',
9 | message: 'this is a test',
at RequestHandler.handleRequestError (node_modules/@prisma/client/runtime/index.js:34316:13)
at node_modules/@prisma/client/runtime/index.js:34737:25
at PrismaClient._executeRequest (node_modules/@prisma/client/runtime/index.js:35301:22)
at PrismaClient._request (node_modules/@prisma/client/runtime/index.js:35273:16)
at errorIngestionHandler (src/v1/ingestion/error.ts:6:22)
● API Endpoint test › creates new row in error table
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
20 | .expect('Not implemented');
21 | });
> 22 | it('creates new row in error table', async () => {
| ^
23 | const time = new Date('November 8, 2022, 12:00:00');
24 | const expected = {
25 | view_id: '1234',
at src/v1/ingestion/error.test.ts:22:3
at Object.<anonymous> (src/v1/ingestion/error.test.ts:8:1)
Edit: added entire error stack trace for more context