Skip to content

Commit

Permalink
Merge pull request #11 from passageidentity/users/db/ch1156-create-up…
Browse files Browse the repository at this point in the history
…date-user-metadata

[MAIN] Create and update user via metadata now supported
  • Loading branch information
dylanbrookes authored Apr 29, 2022
2 parents 12c79a4 + 24adf16 commit e7ccdad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
25 changes: 14 additions & 11 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ const (
)

type User struct {
ID string `json:"id"`
Status UserStatus `json:"status"`
Email string `json:"email"`
Phone string `json:"phone"`
EmailVerified bool `json:"email_verified"`
CreatedAt time.Time `json:"created_at"`
LastLogin time.Time `json:"last_login_at"`
ID string `json:"id"`
Status UserStatus `json:"status"`
Email string `json:"email"`
Phone string `json:"phone"`
EmailVerified bool `json:"email_verified"`
CreatedAt time.Time `json:"created_at"`
LastLogin time.Time `json:"last_login_at"`
UserMetadata map[string]interface{} `json:"user_metadata"`
}

type Device struct {
Expand Down Expand Up @@ -115,8 +116,9 @@ func (a *App) DeactivateUser(userID string) (*User, error) {
}

type UpdateBody struct {
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
UserMetadata map[string]interface{} `json:"user_metadata,omitempty"`
}

// UpdateUser receives an UpdateBody struct, updating the corresponding user's attribute(s)
Expand Down Expand Up @@ -167,8 +169,9 @@ func (a *App) DeleteUser(userID string) (bool, error) {
}

type CreateUserBody struct {
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
UserMetadata map[string]interface{} `json:"user_metadata,omitempty"`
}

// CreateUser receives a CreateUserBody struct, creating a user with provided values
Expand Down
18 changes: 17 additions & 1 deletion user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,28 @@ func TestUpdateUser(t *testing.T) {
updateBody := passage.UpdateBody{
Email: "[email protected]",
Phone: "+15005550006",
UserMetadata: map[string]interface{}{
"example1": "123",
},
}

user, err := psg.UpdateUser(PassageUserID, updateBody)
require.Nil(t, err)
assert.Equal(t, "[email protected]", user.Email)
assert.Equal(t, "+15005550006", user.Phone)
assert.Equal(t, "123", user.UserMetadata["example1"])

secondUpdateBody := passage.UpdateBody{
Email: "[email protected]",
Phone: "+15005550006",
UserMetadata: map[string]interface{}{
"example1": "456",
},
}
user, err = psg.UpdateUser(PassageUserID, secondUpdateBody)
require.Nil(t, err)
assert.Equal(t, "[email protected]", user.Email)
assert.Equal(t, "+15005550006", user.Phone)
assert.Equal(t, "456", user.UserMetadata["example1"])
}

func TestCreateUser(t *testing.T) {
Expand Down

0 comments on commit e7ccdad

Please sign in to comment.