From 8d839200c3ba7fee149e6b6b59ba222e17ba10c1 Mon Sep 17 00:00:00 2001 From: Dylan Brookes Date: Thu, 28 Apr 2022 14:54:19 -0500 Subject: [PATCH 1/2] Create and update user via metadata now supported --- user.go | 25 ++++++++++++++----------- user_test.go | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/user.go b/user.go index 7e5cc7b..3d0ede4 100644 --- a/user.go +++ b/user.go @@ -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 { @@ -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"` } // UpdateUser receives an UpdateBody struct, updating the corresponding user's attribute(s) @@ -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"` } // CreateUser receives a CreateUserBody struct, creating a user with provided values diff --git a/user_test.go b/user_test.go index fc0b42b..0ee7542 100644 --- a/user_test.go +++ b/user_test.go @@ -77,12 +77,28 @@ func TestUpdateUser(t *testing.T) { updateBody := passage.UpdateBody{ Email: "updatedEmail@123.com", Phone: "+15005550006", + UserMetadata: map[string]interface{}{ + "example1": "123", + }, } - user, err := psg.UpdateUser(PassageUserID, updateBody) require.Nil(t, err) assert.Equal(t, "updatedEmail@123.com", user.Email) assert.Equal(t, "+15005550006", user.Phone) + assert.Equal(t, "123", user.UserMetadata["example1"]) + + secondUpdateBody := passage.UpdateBody{ + Email: "updatedEmail@123.com", + Phone: "+15005550006", + UserMetadata: map[string]interface{}{ + "example1": "456", + }, + } + user, err = psg.UpdateUser(PassageUserID, secondUpdateBody) + require.Nil(t, err) + assert.Equal(t, "updatedEmail@123.com", user.Email) + assert.Equal(t, "+15005550006", user.Phone) + assert.Equal(t, "456", user.UserMetadata["example1"]) } func TestCreateUser(t *testing.T) { From 24adf1688f87c2e5755c8172698cf0e2977fad03 Mon Sep 17 00:00:00 2001 From: Dylan Brookes Date: Thu, 28 Apr 2022 14:58:04 -0500 Subject: [PATCH 2/2] motempty added @calhorn95 --- user.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user.go b/user.go index 3d0ede4..93a0458 100644 --- a/user.go +++ b/user.go @@ -118,7 +118,7 @@ func (a *App) DeactivateUser(userID string) (*User, error) { type UpdateBody struct { Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` - UserMetadata map[string]interface{} `json:"user_metadata"` + UserMetadata map[string]interface{} `json:"user_metadata,omitempty"` } // UpdateUser receives an UpdateBody struct, updating the corresponding user's attribute(s) @@ -171,7 +171,7 @@ func (a *App) DeleteUser(userID string) (bool, error) { type CreateUserBody struct { Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` - UserMetadata map[string]interface{} `json:"user_metadata"` + UserMetadata map[string]interface{} `json:"user_metadata,omitempty"` } // CreateUser receives a CreateUserBody struct, creating a user with provided values