2018-10-18 18:21:07 +03:00
|
|
|
package errs
|
|
|
|
|
|
|
|
import (
|
2019-02-21 11:51:50 +03:00
|
|
|
"reflect"
|
2018-10-18 18:21:07 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFailure_ApiErrorsSlice(t *testing.T) {
|
|
|
|
var err = Failure{}
|
|
|
|
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": ["Your account has insufficient funds to activate integration module"]}`)
|
2019-02-21 11:51:50 +03:00
|
|
|
expected := map[string]string{
|
|
|
|
"0": "Your account has insufficient funds to activate integration module",
|
|
|
|
}
|
2018-10-18 18:21:07 +03:00
|
|
|
|
|
|
|
resp, e := ErrorResponse(b)
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetRuntimeError(e)
|
|
|
|
err.SetApiError(resp.ErrorMsg)
|
2018-10-18 18:21:07 +03:00
|
|
|
|
|
|
|
if resp.Errors != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetApiErrors(ErrorsHandler(resp.Errors))
|
2018-10-18 18:21:07 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
eq := reflect.DeepEqual(expected, err.ApiErrors())
|
2018-10-18 18:21:07 +03:00
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if eq != true {
|
|
|
|
t.Errorf("%+v", eq)
|
2018-10-18 18:21:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFailure_ApiErrorsMap(t *testing.T) {
|
|
|
|
var err = Failure{}
|
|
|
|
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": {"id": "ID must be an integer"}}`)
|
2019-02-21 11:51:50 +03:00
|
|
|
expected := map[string]string{
|
|
|
|
"id": "ID must be an integer",
|
|
|
|
}
|
2018-10-18 18:21:07 +03:00
|
|
|
|
|
|
|
resp, e := ErrorResponse(b)
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetRuntimeError(e)
|
|
|
|
err.SetApiError(resp.ErrorMsg)
|
2018-10-18 18:21:07 +03:00
|
|
|
|
|
|
|
if resp.Errors != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetApiErrors(ErrorsHandler(resp.Errors))
|
2018-10-18 18:21:07 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
eq := reflect.DeepEqual(expected, err.ApiErrors())
|
2018-10-18 18:21:07 +03:00
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if eq != true {
|
|
|
|
t.Errorf("%+v", eq)
|
2018-10-18 18:21:07 +03:00
|
|
|
}
|
|
|
|
}
|