-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(errors): add spec for IsOTPRequired
- Loading branch information
1 parent
48f9057
commit 94a6965
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |