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

[SDP-961] Change POST /disbursements to accept Verification Type #103

Merged
merged 14 commits into from
Nov 28, 2023

Conversation

ziyliu
Copy link
Contributor

@ziyliu ziyliu commented Nov 21, 2023

What

Add verification types to /disbursement endpoint

Why

Finally leverage validation of verification type for the above endpoint

Known limitations

[TODO or N/A]

Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR does not mix refactoring changes with feature changes (split into two PRs otherwise).
  • This PR's title starts with the name of the package, area, or subject affected by the change.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • This PR contains the link to the Jira ticket it addresses.

Configs and Secrets

  • No new CONFIG variables are required -OR- the new required ones were added to the helmchart's values.yaml file.
  • No new CONFIG variables are required -OR- the new required ones were added to the deployments (pr-preview, dev, demo, prd).
  • No new SECRETS variables are required -OR- the new required ones were mentioned in the helmchart's values.yaml file.
  • No new SECRETS variables are required -OR- the new required ones were added to the deployments (pr-preview secrets, dev secrets, demo secrets, prd secrets).

Release

  • This is not a breaking change.
  • This is ready for production.. If your PR is not ready for production, please consider opening additional complementary PRs using this one as the base. Only merge this into develop or main after it's ready for production!

Deployment

  • Does the deployment work after merging?

@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 21, 2023 18:59 — with GitHub Actions Inactive
@ziyliu ziyliu had a problem deploying to Receiver Registration - E2E Integration Tests November 21, 2023 18:59 — with GitHub Actions Failure
@ziyliu ziyliu marked this pull request as draft November 21, 2023 18:59
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 21, 2023 23:06 — with GitHub Actions Inactive
@ziyliu ziyliu had a problem deploying to Receiver Registration - E2E Integration Tests November 21, 2023 23:06 — with GitHub Actions Failure
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 21, 2023 23:27 — with GitHub Actions Inactive
@ziyliu ziyliu had a problem deploying to Receiver Registration - E2E Integration Tests November 21, 2023 23:27 — with GitHub Actions Failure
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 21, 2023 23:36 — with GitHub Actions Inactive
@ziyliu ziyliu had a problem deploying to Receiver Registration - E2E Integration Tests November 21, 2023 23:36 — with GitHub Actions Failure
Comment on lines 12 to 15
VERIFICATION_FIELD_PIN_MIN_LENGTH = 4
VERIFICATION_FIELD_PIN_MAX_LENGTH = 8

VERIFICATION_FIELD_MAX_ID_LENGTH = 50
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with @torisamples on these values

@ziyliu ziyliu marked this pull request as ready for review November 21, 2023 23:37
@ziyliu ziyliu self-assigned this Nov 21, 2023
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 22, 2023 18:12 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 22, 2023 18:12 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 22, 2023 18:14 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 22, 2023 18:14 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 22, 2023 18:48 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 22, 2023 18:48 — with GitHub Actions Inactive
internal/data/disbursements.go Outdated Show resolved Hide resolved
internal/data/disbursements.go Outdated Show resolved Hide resolved
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 19:00 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 19:00 — with GitHub Actions Inactive
@@ -52,16 +54,21 @@ func (d DisbursementHandler) PostDisbursement(w http.ResponseWriter, r *http.Req
return
}

// validate request
v := validators.NewValidator()
iv := validators.NewDisbursementInstructionsValidator(disbursementRequest.VerificationField)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the NewDisbursementInstructionsValidator as we're not validating instructions at this stage. We're just validating the 5 fields posted when creating a new disbursement.

We should revert this back to v := validators.NewValidator() and just make sure that VerificationField is not empty.

v := validators.NewValidator()
v.Check(disbursementRequest.Name != "", "name", "name is required")
v.Check(disbursementRequest.CountryCode != "", "country_code", "country_code is required")
v.Check(disbursementRequest.WalletID != "", "wallet_id", "wallet_id is required")
v.Check(disbursementRequest.AssetID != "", "asset_id", "asset_id is required")
v.Check(disbursementRequest.VerificationField != "", "verification_field", "verification_field is required")

if v.HasErrors() {
      httperror.BadRequest("Request invalid", err, v.Errors).Render(w)
      return
}

Copy link
Contributor Author

@ziyliu ziyliu Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marwen-abid my thinking is that wouldn't we want to make sure that VerificationField is one of the three existing types? i.e. we decide to add a new verification type but not use it for this endpoint. I know we're technically not validating instructions in this handler but the additional ValidateAndGetVerificationType call on the NewDisbursementInstructionsValidator instance provides an additional error messaging for when the type is invalid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this shortcut is worth it.

the new method you created ValidateAndGetVerificationType is only used here, so I think it makes more sense to create a new validator called DisbursementRequestValidator that takes the whole disbursementRequest and validates it. You can move ValidateAndGetVerificationType to that new validator.

internal/serve/httphandler/disbursement_handler_test.go Outdated Show resolved Hide resolved
internal/serve/httphandler/disbursement_handler_test.go Outdated Show resolved Hide resolved
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 19:24 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 19:24 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 19:42 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 19:42 — with GitHub Actions Inactive
@ziyliu ziyliu requested a review from marwen-abid November 28, 2023 19:43
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 21:55 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 21:55 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 22:05 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 22:05 — with GitHub Actions Inactive
Copy link
Collaborator

@marwen-abid marwen-abid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks great 🚀

more feedback

rename

lint
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 22:14 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 22:14 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Receiver Registration - E2E Integration Tests November 28, 2023 22:16 — with GitHub Actions Inactive
@ziyliu ziyliu temporarily deployed to Anchor Integration Tests November 28, 2023 22:16 — with GitHub Actions Inactive
@ziyliu ziyliu merged commit a665505 into develop Nov 28, 2023
6 checks passed
@ziyliu ziyliu deleted the erica/sdp-961 branch November 28, 2023 22:25
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

Successfully merging this pull request may close these issues.

3 participants