-
Notifications
You must be signed in to change notification settings - Fork 10
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
Debugging usercredit, userprofile, balance display issues, Kenyon #346
base: main
Are you sure you want to change the base?
Conversation
pwdel
commented
Sep 27, 2024
- Attempting to debug usercredit problem seen on Kenyon instance
Tested on local after modifications, it's displaying credits as expected in the case of no wins, only investment so far, from one user, as previous. This is after having converted the integertype to int64.
|
Setup we're working with for test case: https://github.com/ajlacey/socialpredict/blob/main/backend/setup/setup.yaml
|
… in publicuser package.
// user portfolio, (which is public) | ||
router.HandleFunc("/v0/portfolio/{username}", usershandlers.GetPublicUserPortfolio).Methods("GET") | ||
router.HandleFunc("/v0/portfolio/{username}", publicuser.GetPublicUserPortfolio).Methods("GET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we use the package name before calling the handler, this call looks redundant (it stutters). Consider renaming the function to Portfolio
or GetPortfolio
so that the call would look like publicuser.Portfolio
or publicuser.GetPortfolio
.
This can be applied to the other handlers that are being updated in the server as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider renaming this file to portfolio.go
since it is a member of the publicuser
package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add an empty test file. If you're planning to add tests, I would add this file as part of the PR that adds the tests.
// Migrate the User model | ||
if err := db.AutoMigrate(&models.User{}); err != nil { | ||
t.Fatalf("Failed to migrate user model: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewFakeDB(t)
migrates the models on creation, so this is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as publicuser_test- this isn't necessary unless you're adding tests. Since there is no new privateuser code here, I think it makes sense to add this when we create tests for the privateuser package.
@@ -0,0 +1,68 @@ | |||
package usercredit_test |
There was a problem hiding this comment.
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 should be a separate package. We're not exporting test functionality here.
@@ -53,12 +55,11 @@ func GetUserCreditHandler(w http.ResponseWriter, r *http.Request) { | |||
|
|||
} | |||
|
|||
func calculateUserCredit(db *gorm.DB, username string) int { | |||
func CalculateUserCredit(db *gorm.DB, username string, maximumdebt int64) int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can remain private when the testing is done in the same package.
db := modelstesting.NewFakeDB(t) | ||
if err := db.AutoMigrate(&models.User{}); err != nil { | ||
t.Fatalf("Failed to migrate models: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db migration happens when creating the fake.
Username: test.username, | ||
Email: test.email, | ||
AccountBalance: test.accountBalance, | ||
ApiKey: test.apiKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this field necessary to create a user? It doesn't look like it, but I may misunderstand the gorm struct tagging. If it's not necessary, I don't think we're using this field in the tests at all and can safely remove it.