Skip to content

Commit

Permalink
chore: fix test and misc clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Dumbledore <mathenge362@gmail.com>
  • Loading branch information
ageeknamedslickback committed Nov 11, 2021
1 parent eea76f3 commit 3c0ae05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
7 changes: 4 additions & 3 deletions pkg/engagement/infrastructure/services/library/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ func (s ServiceLibraryImpl) GetFaqsContent(ctx context.Context, flavour feedlib.
return s.getCMSPosts(ctx, faqsRequestConsumer)
}

// get profile from onboarding service
user, err := profileutils.GetLoggedInUser(ctx)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("unable to get user: %w", err)
}

profile, err := s.onboarding.GetUserProfile(ctx, user.UID)
log.Printf("The logged in user: %v\n\n\n\n", user.UID)

profile, err := s.onboarding.GetUserProfile(ctx, user.UID)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("unable to get user profile: %w", err)
Expand All @@ -237,11 +237,12 @@ func (s ServiceLibraryImpl) GetFaqsContent(ctx context.Context, flavour feedlib.
switch profile.Role {
case profileutils.RoleTypeEmployee:
return s.getCMSPosts(ctx, employeeHelpRequest)

case profileutils.RoleTypeAgent:
return s.getCMSPosts(ctx, agentHelpRequest)

default:
return s.getCMSPosts(ctx, faqsRequestPro)

}
}

Expand Down
31 changes: 21 additions & 10 deletions pkg/engagement/infrastructure/services/onboarding/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ type ProfileService interface {
ctx context.Context,
uid UserUIDs,
) (map[string][]string, error)
GetUserProfile(ctx context.Context, uid string) (*profileutils.UserProfile, error)
GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error)
GetUserProfile(
ctx context.Context,
uid string,
) (*profileutils.UserProfile, error)
GetUserProfileByPhoneOrEmail(
ctx context.Context,
payload *dto.RetrieveUserProfileInput,
) (*profileutils.UserProfile, error)
}

// NewRemoteProfileService initializes a connection to a remote profile service
Expand Down Expand Up @@ -167,18 +173,20 @@ func (rps RemoteProfileService) GetUserProfile(
return nil, fmt.Errorf("error calling profile service: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(
"user profile not found. Error code: %v",
resp.StatusCode,
)
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("error reading profile response body: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(
"failed to get user profile with status %v and data: %s",
resp.Status,
string(data),
)
}

user := profileutils.UserProfile{}
err = json.Unmarshal(data, &user)
if err != nil {
Expand All @@ -189,7 +197,10 @@ func (rps RemoteProfileService) GetUserProfile(
}

// GetUserProfileByPhoneOrEmail gets the specified users' profile from the onboarding service
func (rps RemoteProfileService) GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error) {
func (rps RemoteProfileService) GetUserProfileByPhoneOrEmail(
ctx context.Context,
payload *dto.RetrieveUserProfileInput,
) (*profileutils.UserProfile, error) {
ctx, span := tracer.Start(ctx, "GetUserProfileByPhoneOrEmail")
defer span.End()
payload = &dto.RetrieveUserProfileInput{
Expand Down

0 comments on commit 3c0ae05

Please sign in to comment.