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

make UserIdentifierInput fields pointers #301

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Bugfix-20231110-135823.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Bugfix
body: make UserIdentifierInput fields pointers, fixing the omitempty struct tag behavior
time: 2023-11-10T13:58:23.41047-06:00
4 changes: 2 additions & 2 deletions team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ func TestTeamAddMemberhip(t *testing.T) {
team, _ := clientWithAlias.GetTeamWithAlias("example")
newMembership := ol.TeamMembershipUserInput{
Role: "user",
User: ol.UserIdentifierInput{Id: id1, Email: "[email protected]"},
User: ol.UserIdentifierInput{Id: &id1, Email: ol.NewString("[email protected]")},
Copy link
Collaborator

@rocktavious rocktavious Nov 10, 2023

Choose a reason for hiding this comment

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

I "think" this should probably actually be using NewUserIdentifier("[email protected]") - One thing i've been reading up about with idomatic go is that we should really push to use "constructors" for all our types so we can present better interfaces to "setup" objects and then also have a handle to do things like what we do in NewUserIdentifier where we convert the "string" of e-mail into a *string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introducing NewUserIdentifier() here would make the line read as:
User: NewUserIdentifier("[email protected]"),
but then we are getting a UserIdentifier without an Id

}
result, err := clientWithTeamId.AddMemberships(&team.TeamId, newMembership)
// Assert
Expand Down Expand Up @@ -829,7 +829,7 @@ func TestTeamRemoveMemberhip(t *testing.T) {
team, _ := client1.GetTeamWithAlias("example")
membershipToDelete := ol.TeamMembershipUserInput{
Role: "user",
User: ol.UserIdentifierInput{Id: id1, Email: "[email protected]"},
User: ol.UserIdentifierInput{Id: &id1, Email: ol.NewString("[email protected]")},
}

result, err := client2.RemoveMemberships(&team.TeamId, membershipToDelete)
Expand Down
8 changes: 4 additions & 4 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
}

type UserIdentifierInput struct {
Id ID `graphql:"id" json:"id,omitempty"`
Email string `graphql:"email" json:"email,omitempty"`
Id *ID `graphql:"id" json:"id,omitempty"`
Email *string `graphql:"email" json:"email,omitempty"`
}

type UserInput struct {
Expand All @@ -53,11 +53,11 @@
func NewUserIdentifier(value string) UserIdentifierInput {
if IsID(value) {
return UserIdentifierInput{
Id: ID(value),
Id: NewID(value),

Check warning on line 56 in user.go

View check run for this annotation

Codecov / codecov/patch

user.go#L56

Added line #L56 was not covered by tests
}
}
return UserIdentifierInput{
Email: value,
Email: NewString(value),
}
}

Expand Down
Loading