Socket
Socket
Sign inDemoInstall

@prisma-extensions/factory

Package Overview
Dependencies
9
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @prisma-extensions/factory

Factory enables you to easily create and build database records for testing or seeding purposes.


Version published
Weekly downloads
14
decreased by-17.65%
Maintainers
1
Install size
704 kB
Created
Weekly downloads
 

Readme

Source

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

      // ...
    })
  })
})

Learn more about the power of Turborepo:

  • Pipelines
  • Caching
  • Remote Caching
  • Filtering
  • Configuration Options
  • CLI Usage

Keywords

FAQs

Last updated on 04 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc