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

Feat(SPV-1425): add validation for paymail #933

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

dzolt-4chain
Copy link
Contributor

Pull Request Checklist

  • πŸ“– I created my PR using provided : CODE_STANDARDS
  • πŸ“– I have read the short Code of Conduct: CODE_OF_CONDUCT
  • 🏠 I tested my changes locally.
  • βœ… I have provided tests for my changes.
  • πŸ“ I have used conventional commits.
  • πŸ“— I have updated any related documentation.
  • πŸ’Ύ PR was issued based on the Github or Jira issue.

@dzolt-4chain dzolt-4chain requested a review from a team as a code owner February 26, 2025 16:31
Copy link

Manual Tests

ℹ️ Remember to ask team members to perform manual tests and to assign tested label after testing.

@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 4.04040% with 95 lines in your changes missing coverage. Please review.

Project coverage is 35.18%. Comparing base (047b196) to head (1831486).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
actions/v2/admin/internal/mapping/paymail.go 0.00% 48 Missing ⚠️
actions/v2/admin/internal/mapping/user.go 0.00% 13 Missing ⚠️
engine/v2/paymails/paymailsmodels/paymail.go 0.00% 12 Missing ⚠️
engine/v2/paymails/paymails_service.go 0.00% 6 Missing ⚠️
engine/v2/users/users_service.go 0.00% 6 Missing ⚠️
actions/v2/admin/users/create.go 33.33% 2 Missing and 2 partials ⚠️
lox/conditionals.go 0.00% 4 Missing ⚠️
engine/v2/database/repository/users.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #933      +/-   ##
==========================================
- Coverage   35.69%   35.18%   -0.52%     
==========================================
  Files         419      427       +8     
  Lines       19853    20095     +242     
==========================================
- Hits         7087     7070      -17     
- Misses      12175    12434     +259     
  Partials      591      591              
Flag Coverage Ξ”
unittests 35.18% <4.04%> (-0.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
actions/v2/admin/users/paymail_add.go 80.00% <100.00%> (-6.00%) ⬇️
api/gen.models.go 0.00% <ΓΈ> (ΓΈ)
engine/v2/users/usersmodels/user.go 0.00% <ΓΈ> (ΓΈ)
engine/v2/database/repository/users.go 0.00% <0.00%> (ΓΈ)
actions/v2/admin/users/create.go 50.00% <33.33%> (-17.40%) ⬇️
lox/conditionals.go 0.00% <0.00%> (ΓΈ)
engine/v2/paymails/paymails_service.go 0.00% <0.00%> (ΓΈ)
engine/v2/users/users_service.go 0.00% <0.00%> (ΓΈ)
engine/v2/paymails/paymailsmodels/paymail.go 0.00% <0.00%> (ΓΈ)
actions/v2/admin/internal/mapping/user.go 0.00% <0.00%> (ΓΈ)
... and 1 more

... and 31 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 047b196...1831486. Read the comment docs.

@@ -32,8 +33,8 @@ func (s *APIAdminUsers) AddPaymailToUser(c *gin.Context, id string) {
newPaymail := &paymailsmodels.NewPaymail{
Alias: alias,
Domain: domain,
PublicName: requestBody.PublicName,
Avatar: requestBody.AvatarURL,
PublicName: lo.IfF(requestBody.PublicName != nil, func() string { return *requestBody.PublicName }).Else(""),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Proposition for simplifying this is to have function like below:

package lox

import "github.com/samber/lo"

type IfElse[T any] interface {
	Else(result T) T
}

func Elvis[T any](value *T) IfElse[T] {
	return lo.IfF[T](value != nil, func() T {
		return *value
	})
}

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've applied it to this part, but it doesn't help with other IfF where the logic is more complicated as it requires mapping.

We could do an additional function that also accepts a function but the only benefit of that is to skip the != nil check.

so right now we have

return &transaction.OutputAnnotation{
		Bucket: bucket.Name(from.Bucket),
		Paymail: lo.IfF(
			from.Paymail != nil,
			func() *transaction.PaymailAnnotation {
				return &transaction.PaymailAnnotation{
					Sender:    from.Paymail.Sender,
					Receiver:  from.Paymail.Receiver,
					Reference: from.Paymail.Reference,
				}
			},
		).Else(nil),
	}

We could have

return &transaction.OutputAnnotation{
		Bucket: bucket.Name(from.Bucket),
		Paymail: lox.UnwrapAndMap(
			from.Paymail,
			func() *transaction.PaymailAnnotation {
				return &transaction.PaymailAnnotation{
					Sender:    from.Paymail.Sender,
					Receiver:  from.Paymail.Receiver,
					Reference: from.Paymail.Reference,
				}
			},
		).Else(nil),
	}

LMKWYT

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.

5 participants