Skip to content

Commit

Permalink
chore: update test user details when creating one
Browse files Browse the repository at this point in the history
  • Loading branch information
allansifuna committed Dec 11, 2023
1 parent 2382ddd commit 10a84da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
const (
anonymousUserUID = "AgkGYKUsRifO2O9fTLDuVCMr2hb2" // This is an anonymous user
verifyPhone = "testing/verify_phone"
updateUserDetails = "testing/update_user_profile"
createUserByPhone = "testing/create_user_by_phone"
loginByPhone = "testing/login_by_phone"
removeUserByPhone = "testing/remove_user"
Expand Down Expand Up @@ -299,6 +300,9 @@ func CreateTestPhoneNumberUser(t *testing.T, onboardingClient *InterServiceClien
ctx := context.Background()

phone := TestUserPhoneNumber
firstName := "Test"
lastName := "User"
gender := "Male"
PIN := TestUserPin
flavour := feedlib.FlavourConsumer

Expand Down Expand Up @@ -336,6 +340,31 @@ func CreateTestPhoneNumberUser(t *testing.T, onboardingClient *InterServiceClien
if err != nil {
return nil, fmt.Errorf("failed to unmarshal OTP: %v", err)
}
updateUserProfilePayload := map[string]interface{}{
"uid": response.Auth.UID,
"firstName": firstName,
"lastName": lastName,
"gender": gender,
}
resp, err = onboardingClient.MakeRequest(
ctx,
http.MethodPost,
updateUserDetails,
updateUserProfilePayload,
)
if err != nil {
return nil, fmt.Errorf("unable to update user details: %w", err)
}
updateDetailsResp, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to convert response to string: %v", err)
}

var userProfile *profileutils.UserProfile
err = json.Unmarshal(updateDetailsResp, &userProfile)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal OTP: %v", err)
}

return response, nil
}
Expand Down
6 changes: 6 additions & 0 deletions test_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func TestCreateOrLoginTestPhoneNumberUser(t *testing.T) {
type args struct {
onboardingClient *interserviceclient.InterServiceClient
}
// clean of any pre-existing test users
err = interserviceclient.RemoveTestPhoneNumberUser(t, onboardingClient)
if err != nil {
t.Errorf("failed to remove test user: %v", err)
return
}
tests := []struct {
name string
args args
Expand Down

0 comments on commit 10a84da

Please sign in to comment.