prisma-client-extensions icon indicating copy to clipboard operation
prisma-client-extensions copied to clipboard

callback-free-itx: Fixed $rollback and added $transaction

Open vaharoni opened this issue 1 year ago • 2 comments

This PR contains the following improvements:

  1. Fixes the $rollback behavior Currently, the promise being rejected when calling $rollback is caught and ignored. This means the original target txClient is unaware that an exception was raised during the execution of its $transaction, and therefore performs a commit rather than a rollback.

  2. Adds a $transaction method One of the goals of this extension is to allow integration tests per issue 12458. The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a global beforeEach block, and rolling back that transaction in afterEach. This allows full test independence, as rolling back the transaction means the database remains unchanged between tests. The code being tested should be unaware the prisma client is being mocked. It should be able to invoke prisma.$transaction if it needs to. However, in the current extension implementation this does not work. This PR enables this behavior by proxying the $transaction method, sending txClient to the callback.

vaharoni avatar May 23 '24 15:05 vaharoni

Would be nice to see this

acron0 avatar Jun 05 '24 11:06 acron0

@vaharoni

The idea is that we can mock the prisma client by sending this imperative-styled transaction wrapper instead, starting a transaction in a global beforeEach block, and rolling back that transaction in afterEach

How can I specifically achieve the above content with code?

gyunseo avatar Jul 11 '24 09:07 gyunseo