Skip to content

Commit

Permalink
chore: fix test and misc clean up (#65)
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 fcb1501
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -378,9 +376,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/savannahghi/converterandformatter v0.0.3/go.mod h1:0o7yieYU10WabPqKuqj+5QL52eTL1eGElxjb+A68bbA=
Expand Down Expand Up @@ -422,7 +418,6 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
Expand Down Expand Up @@ -456,7 +451,6 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
7 changes: 3 additions & 4 deletions pkg/engagement/infrastructure/services/library/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,20 @@ func (s ServiceLibraryImpl) GetFeedContent(ctx context.Context, flavour feedlib.
func (s ServiceLibraryImpl) GetFaqsContent(ctx context.Context, flavour feedlib.Flavour) ([]*domain.GhostCMSPost, error) {
ctx, span := tracer.Start(ctx, "GetFaqsContent")
defer span.End()
if !feedlib.FlavourConsumer.IsValid() {
if !flavour.IsValid() {
return nil, fmt.Errorf("flavour `%s` is invalid", flavour)
}
if flavour == feedlib.FlavourConsumer {
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)

if err != nil {
helpers.RecordSpanError(span, err)
return nil, fmt.Errorf("unable to get user profile: %w", err)
Expand All @@ -237,11 +235,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 fcb1501

Please sign in to comment.