Fix: Added invalid JSON check on payment triggers#1028
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds JSON validation to payment triggers to prevent network requests when the trigger's JSON data is invalid. The change addresses issue #765 by implementing early JSON validation that logs errors without attempting external HTTP calls.
- Added try-catch wrapper around JSON parsing in
postDataForTriggerfunction - Implemented early return with error logging when JSON validation fails
- Added comprehensive test coverage for the new validation behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| services/triggerService.ts | Added JSON validation with early return and error logging before network requests |
| tests/unittests/triggerService.test.ts | Added unit tests demonstrating JSON validation functionality |
| tests/integration-tests/triggerJsonValidation.test.ts | Added integration tests covering various JSON validation scenarios |
chedieck
left a comment
There was a problem hiding this comment.
I added a console error, since this situation should never happen unless we manual edit the db, and fixed linting issues (check if you have ./git/hooks/pre-commit in place, if not copy it there from .githooks/).
chedieck
left a comment
There was a problem hiding this comment.
I fixed some linting issues and some stuff that was erroring due to changes in master.
In any case, I looked further and didn't undestand the reason for the tests included in the tests/integration-tests/triggerJsonValidation.test.ts to be in a separate file from the other trigger tests — I don't understand why they are included in integration-tests/ since, AFAIK, they are not testing any integration.
Klakurka
left a comment
There was a problem hiding this comment.
Right, thanks.
I consolidated those tests, cleaned it up a bit.
Have a look at the lint-staged changes I had to make to be able to build - this is an issue for me that I had to fix in another WIP branch.
This reverts commit 342f5c5.
Related to #765
Description
Added check to make sure we aren't firing off payment triggers with invalid JSON.
Test plan