Skip to content

Commit

Permalink
chore: add missing methods in twilio usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellgithinji committed Sep 17, 2021
1 parent 8d9fefb commit 9e32ecc
Show file tree
Hide file tree
Showing 11 changed files with 941 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ jobs:

- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 72.1
TESTCOVERAGE_THRESHOLD: 72.8
run: |
bash scripts/coverage.sh
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,82 @@ func TestServiceOTPImpl_SaveOTPToFirestore(t *testing.T) {
}
}

func TestImplOTP_VerifyOtp(t *testing.T) {
ctx := firebasetools.GetAuthenticatedContext(t)

s, err := newTestOtpSService(t)
if err != nil {
t.Errorf("unable to initialize test service with error %v", err)
return
}

msisdn := interserviceclient.TestUserPhoneNumber
appID := ksuid.New().String()
retryStep := 1

verificationCode, err := s.GenerateRetryOTP(ctx, &msisdn, retryStep, &appID)
if err != nil {
t.Errorf("failed to generate retry OTP to phone: %v", err)
}

type args struct {
ctx context.Context
msisdn *string
verificationCode *string
}
tests := []struct {
name string
args args
want bool
wantErr bool
panics bool
}{
{
name: "valid: correct params passed",
args: args{
ctx: ctx,
msisdn: &msisdn,
verificationCode: &verificationCode,
},
want: true,
wantErr: false,
},
{
name: "invalid: missing phone number",
args: args{
ctx: ctx,
verificationCode: &verificationCode,
},
panics: true,
},
{
name: "invalid: missing verification code",
args: args{
ctx: ctx,
msisdn: &msisdn,
},
panics: true,
},
}
for _, tt := range tests {
if !tt.panics {
t.Run(tt.name, func(t *testing.T) {
got, err := s.VerifyOtp(tt.args.ctx, tt.args.msisdn, tt.args.verificationCode)
if (err != nil) != tt.wantErr {
t.Errorf("ImplOTP.VerifyOtp() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ImplOTP.VerifyOtp() = %v, want %v", got, tt.want)
}
})
}
if tt.panics {
fcVerifyOtp := func() { _, _ = s.VerifyOtp(tt.args.ctx, tt.args.msisdn, tt.args.verificationCode) }
assert.Panics(t, fcVerifyOtp)
}
}
}
func TestServiceOTPImpl_VerifyEmailOtp(t *testing.T) {
s, err := newTestOtpSService(t)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions pkg/engagement/infrastructure/services/twilio/mock/twilio_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ type FakeServiceTwilio struct {
to string,
message string,
) (bool, error)
MakeWhatsappTwilioRequestFn func(
ctx context.Context,
method string,
urlPath string,
content url.Values,
target interface{},
) error
}

// Room is a mock of the Room method
Expand Down Expand Up @@ -105,3 +112,20 @@ func (f *FakeServiceTwilio) TemporaryPIN(
) (bool, error) {
return f.TemporaryPINFn(ctx, to, message)
}

// MakeWhatsappTwilioRequest is a mock of the MakeWhatsappTwilioRequest method
func (f *FakeServiceTwilio) MakeWhatsappTwilioRequest(
ctx context.Context,
method string,
urlPath string,
content url.Values,
target interface{},
) error {
return f.MakeWhatsappTwilioRequestFn(
ctx,
method,
urlPath,
content,
target,
)
}
15 changes: 15 additions & 0 deletions pkg/engagement/infrastructure/services/twilio/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ type ServiceTwilio interface {
to string,
message string,
) (bool, error)

MakeTwilioRequest(
method string,
urlPath string,
content url.Values,
target interface{},
) error

MakeWhatsappTwilioRequest(
ctx context.Context,
method string,
urlPath string,
content url.Values,
target interface{},
) error
}

// NewService initializes a service to interact with Twilio
Expand Down
Loading

0 comments on commit 9e32ecc

Please sign in to comment.