Hi! :wave: I’m quite new to Prisma and I’ve recen...
# orm-help
c
Hi! 👋 I’m quite new to Prisma and I’ve recently using it in a project and it has worked quite well for me. I now have to implement some logic that involves writing to the database and making POST/PUT/DELETE calls to an external API. I want to implement the Unit of Work pattern to execute all these “data writing” operations in a way that, if the external API call fails then the transaction should be rolled back. To that end, I decided to use the preview feature “interactive transactions”. The problem I face now, is that it’s quite challenging writing unit tests for that because the logic to be unit tested is within the body of an
async
function passed to the
prisma.$transaction()
function. I’m using Jest to mock the Prisma client, but in this case I would have to provide a mock for the
prisma.$transaction()
function and in doing so, I would be replacing the very logic I’m trying to unit test. I hope I explained the case well enough. I’d really appreciate some guidance from any that has run into this scenario. Thanks in advance! P/S: Is the Prisma Team planning to implement manual transaction control (start, commit, rollback)?
o
Hi @Carlos Weckesser! If it’s really hard to test the logic related with database operations it’s worth to test it in integration tests which will have connection to DB, because now as you said you’ll mock most of your logic. Take a look at the example how to configure integration tests with Postgres -> https://dev.to/devsilk/nest-js-integration-tests-o8n
c
Thanks for the answer @Olgierd Liberski!