Skip to content

Commit

Permalink
test(errors): add spec for IsOTPRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
curzolapierre committed Feb 12, 2024
1 parent 48f9057 commit 94a6965
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions http/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package http

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
)

func Test_IsOTPRequired(t *testing.T) {
cases := map[string]struct {
expectedValue bool
givenError error
}{
"returns OTP required when the ErrOTPRequired variable is passed": {
givenError: ErrOTPRequired,
expectedValue: true,
},
"returns OTP required when a message 'OTP Required' is returned by API": {
givenError: requestFailedError("OTP Required"),
expectedValue: true,
},
"returns false when API does not returns 'OPT Required'": {
givenError: requestFailedError("bad request"),
expectedValue: false,
},
"returns false when an normal error is given": {
givenError: errors.New("bad request"),
expectedValue: false,
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
// When
optRequired := IsOTPRequired(c.givenError)

// Then
require.Equal(t, c.expectedValue, optRequired)
})
}
}

func requestFailedError(message string) error {
return &RequestFailedError{Message: message}
}

0 comments on commit 94a6965

Please sign in to comment.