@prisma-extensions/factory
@prisma-extensions/factory
- Create factories@prisma-extensions/msoft-delete
- Enable a deletedAt
field.@prisma-extensions/truncate
- Truncate
Challenges
- When using
model.$allModels
you can't get the model the method is being acted on. - When using
model.$allModels
you can't get the types of the model the method is being acted on.
Blockers
Proposed API
- Utilizes
@prisma-extensions/truncate
const xprisma = new PrismaClient()
.$extends(factoryExtension)
.$extends(truncateExtension)
const UserFactory = xprisma.user.createFactory({
firstName: "Jane",
lastName: "Doe",
})
describe("Post", () => {
describe("Standard" () => {
afterEach(async () => {
await xprisma.$truncate()
})
test("example", async () => {
const user = UserFactory.build()
const post = await PostFactory.create({
title: "Foo",
content: "Bar",
author: {
create: user,
},
})
})
})
describe("Persistent Record", () => {
const user = UserFactory.create()
afterAll(async () => {
await xprisma.$truncate({ only: ["User"] })
})
afterEach(async () => {
await xprisma.$truncate({ exclude: ["User"] })
})
test("example", async () => {
const post = await PostFactory.create({
title: "Foo",
content: "Bar",
author: {
connect: { id: user.id },
},
})
})
})
})
Useful Links
Learn more about the power of Turborepo: