Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is jest-prisma work with transaction? #87

Closed
YutaUra opened this issue May 24, 2023 · 2 comments
Closed

Is jest-prisma work with transaction? #87

YutaUra opened this issue May 24, 2023 · 2 comments

Comments

@YutaUra
Copy link
Contributor

YutaUra commented May 24, 2023

Expected

The following tests succeed

const transaction = async (prisma) => {
  await prisma.$transaction(async (p) => {
    await p.user.create({ data: { /* */ } })

    throw new Error("Something failed. Affected changes will be rollback.")
  }).catch(console.error)
}

// test code
it("test", async () => {
  const prisma = jestPrisma.client
  
  const before = await prisma.user.aggregate({ _count: true })
  expect(before._count).toBe(0)

  await transaction(prisma)

  const after = await prisma.user.aggregate({ _count: true })
  expect(after._count).toBe(0) // Prisma is expected to rollback, so there should be no increase in users
})

Actual

expect(received).toBe(expected)

Expected: 0
Received: 1

Reproduction

Please check the code I forked.

https://github.com/YutaUra/jest-prisma/blob/reproducing_transaction_bug/examples/example-prj/src/service/Transaction.ts
https://github.com/YutaUra/jest-prisma/blob/reproducing_transaction_bug/examples/example-prj/src/service/Transaction.test.ts

Others

Is the unavailability of Transaction a bug or a specification?

If it is a specification at this time, I think documentation needs to be added. If so, I would be happy to help.

@Quramy
Copy link
Owner

Quramy commented May 24, 2023

jest-prisma work with transaction?

Partially yes. But jest-prisma can't throw rolledback exception in application $transaction

@YutaUra
Copy link
Contributor Author

YutaUra commented May 24, 2023

I have worked on adding the document for now. #89
I hope you will check it out when you have time!

If I come up with any ideas on how to implement transaction rollback, I will share them with you!

@YutaUra YutaUra closed this as completed May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants