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 7aed3b3 commit 7da6b16
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions http/errors_test.go
Original file line number Diff line number Diff line change
@@ -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}
}

0 comments on commit 7da6b16

Please sign in to comment.