Quramy / jest-prisma

Jest environment for integrated testing with Prisma client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does middleware not support?

seol-gang opened this issue · comments

I wrote code to test the middleware of Prisma.

according to the guide, I mocked the test code with the code below.

jest.mock("@/server/db/client", () => {
  return {
    prisma: jestPrisma.client,
  };
});

and the client file is written like this.

import { PrismaClient } from "@prisma/client";

import { env } from "../../env/server.mjs";
import softDeleteMiddleware from "./middleware/softDelete";

declare global {
  // eslint-disable-next-line no-var
  var prisma: PrismaClient | undefined;
}

const prisma =
  global.prisma ||
  new PrismaClient({
    log:
      env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
  });

if (env.NODE_ENV !== "production") {
  global.prisma = prisma;
}

prisma.$use(softDeleteMiddleware);

export { prisma };

the middleware is the same as the code from here.

the setup was also done according to the guide, and the test codes without middleware applied worked well.

Test Code

test("exists row when delete", async () => {
    const user = await userRepo.createUser("test", "test@test.com");
    await userRepo.deleteUser(user.id);

    const result = await userRepo.findUserById(user.id);

    expect(result).not.toBeNull();
    expect(result?.deletedAt).not.toBeNull();
  });

does middleware not support? Or I wonder if it doesn't work because I set it up wrong.

does middleware not support?

jest-prisma does not support middleware for now.

Or I wonder if it doesn't work because I set it up wrong.

Because jest-prisma does create prisma client instance. But I want to provide feature to configure "how to instantiate prisma client" for advanced users (e.g. client extension or middleware, ...)

does middleware not support?

jest-prisma does not support middleware for now.

Or I wonder if it doesn't work because I set it up wrong.

Because jest-prisma does create prisma client instance. But I want to provide feature to configure "how to instantiate prisma client" for advanced users (e.g. client extension or middleware, ...)

Okay, so it's working pretty well for the rest of the non-middleware stuff, so I think that's great, and I think it's going to be a really cool library if we can add some middleware functionality in the future.