@prisma-extensions/factory
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-canary.20230204011658 • Public • Published

@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,
        },
      })

      // ...
    })
  })

  // Tests should be isolated (use sparingly)
  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:

Package Sidebar

Install

npm i @prisma-extensions/factory

Weekly Downloads

16

Version

0.1.0-canary.20230204011658

License

MIT

Unpacked Size

29.3 kB

Total Files

25

Last publish

Collaborators

  • tmilewski