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

use helper function for UserSignup creation in signup unit tests #494

Merged

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Jan 16, 2025

a follow-up of #492

KUBESAW-254

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.38%. Comparing base (1629d19) to head (10cf119).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #494   +/-   ##
=======================================
  Coverage   85.38%   85.38%           
=======================================
  Files          32       32           
  Lines        3174     3174           
=======================================
  Hits         2710     2710           
  Misses        376      376           
  Partials       88       88           
Flag Coverage Δ
unittests 85.38% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Nice 👍

Thanks for cleaning it up.

},
Status: crtapi.UserSignupStatus{},
}
otherUserSignup := testusersignup.NewUserSignup(
Copy link
Contributor

Choose a reason for hiding this comment

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

minor and not strictly related to your changes - it looks like now there is not much difference in how the "usersignup it's stored" compared to the other tests. I mean I'm not sure what the test case description refers to. I thought it was about how the otherUserSignup is configured ( with the PropagatedClaims filed being populated ) .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are completely right. It's a leftover that wasn't properly cleaned up after migration of UserSignups from using userIds to using usernames as the name of the resource. The end-goal is to clean this up, but this will require a lot of changes, so I'm doing it in small batches (for now some changes in unit tests that will help me to minimize the size of the changes of the final PRs).
As for this test. It's not about how it's stored, but how it is retrieved - this test doesn't use the userID. Anyway, this sub-test will go away in the upcoming PR.

Copy link

openshift-ci bot commented Jan 16, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MatousJobanek, mfrancisc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,mfrancisc]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Conditions: []crtapi.Condition{
signup := testusersignup.NewUserSignup(
testusersignup.WithName("bill"),
func(userSignup *crtapi.UserSignup) {
Copy link
Contributor

Choose a reason for hiding this comment

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

testusersignup.WithIncompleteSignup("test_reason", "test_message") would make the test more readable IMHO, even if it this would be the single use of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in a103f78

},
}
}
})

svc.MockSignup = func(ctx *gin.Context) (*crtapi.UserSignup, error) {
assert.Equal(s.T(), expectedUserID, ctx.GetString(context.SubKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just testing gin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's testing the rest of the signupCtrl.PostHandler - what happens after the Signup function returns the UserSignup resource.
Let's improve the tests later as soon as we get rid of the unnecessary mocks.

@@ -300,11 +275,11 @@ func (s *TestSignupSuite) TestInitVerificationHandler() {
BodyString("")

data := []byte(fmt.Sprintf(`{"phone_number": "%s", "country_code": "1"}`, phoneNumber))
rr := initPhoneVerification(s.T(), handler, gin.Param{}, data, userID, "", http.MethodPut, "/api/v1/signup/verification")
rr := initPhoneVerification(s.T(), handler, gin.Param{}, data, userID, "johny", http.MethodPut, "/api/v1/signup/verification")
Copy link
Contributor

Choose a reason for hiding this comment

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

grammar nazi nitpick: "johnny"

Copy link
Contributor Author

@MatousJobanek MatousJobanek Jan 21, 2025

Choose a reason for hiding this comment

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

🤦‍♂️ 638f7ab

@MatousJobanek MatousJobanek merged commit adb9357 into codeready-toolchain:master Jan 22, 2025
11 of 13 checks passed
MatousJobanek added a commit to MatousJobanek/registration-service that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants