callback-free-itx: Fixed $rollback and added $transaction #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following improvements:
Fixes the
$rollback
behaviorCurrently, the promise being rejected when calling
$rollback
is caught and ignored. This means the original targettxClient
is unaware that an exception was raised during the execution of its$transaction
, and therefore performs a commit rather than a rollback.Adds a
$transaction
methodOne 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 inafterEach
. 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 invokeprisma.$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, sendingtxClient
to the callback.