morintd / prismock

A mock for PrismaClient, dedicated to unit testing.
https://www.npmjs.com/package/prismock
MIT License
203 stars 23 forks source link

Queries with nested wheres don't work #1098

Open NatalieFrecka opened 2 months ago

NatalieFrecka commented 2 months ago

First of all, this library is great so far. It's saved me a ton of work. Prisma is really lacking when it comes to unit testing, so I really appreciate the dedication.

This might be an expected issue since most nesting doesn't seem to be covered, but I don't see any mention of nested where clauses in the README, so I figured I'd bring it up.

prisma.caseStudy.findFirst({
    orderBy: { lastUpdated: "desc" },
    where: {
      location: {
        companyId: { id: companyId },
      },
    },
});
prisma.user.findMany({
    where: {
        companyId: { id: companyId }, 
    },
});

The above examples do not work when unit testing. I always get back the most recently updated CaseStudy not matter what Company Id is provided.

if it helps: A Company can have many Locations A Location can only have one Company A CaseStudy can only have one Location A Location can have many CaseStudies

I'm on prismock version 1.33.1.

morintd commented 1 month ago

Hello @NatalieFrecka , thanks a lot for bringing this up! Unfortunately I haven't been able to reproduce it on my side, is there any chance you can provide a minimal reproduction repo? Would love to have a look at this.