diff --git a/http/errors_test.go b/http/errors_test.go new file mode 100644 index 0000000..ab31d52 --- /dev/null +++ b/http/errors_test.go @@ -0,0 +1,55 @@ +package http + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_IsOTPRequired(t *testing.T) { + t.Run("returns OTP required when the ErrOTPRequired variable is passed", func(t *testing.T) { + // Given + err := ErrOTPRequired + + // When + optRequired := IsOTPRequired(err) + + // Then + require.True(t, optRequired) + }) + t.Run("returns OTP required when a message 'OTP Required' is returned by API", func(t *testing.T) { + // Given + err := requestFailedError("OTP Required") + + // When + optRequired := IsOTPRequired(err) + + // Then + require.True(t, optRequired) + }) + t.Run("returns false when API does not returns 'OPT Required'", func(t *testing.T) { + // Given + err := requestFailedError("bad request") + + // When + optRequired := IsOTPRequired(err) + + // Then + require.False(t, optRequired) + }) + t.Run("returns false when an normal error is given", func(t *testing.T) { + // Given + err := errors.New("bad request") + + // When + optRequired := IsOTPRequired(err) + + // Then + require.False(t, optRequired) + }) +} + +func requestFailedError(message string) error { + return &RequestFailedError{Message: message} +}