2022-12-26 14:09:34 +00:00
|
|
|
//nolint:dupl
|
2022-01-30 17:49:25 +00:00
|
|
|
package domain_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2022-01-30 17:49:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResponseTypeType(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
in string
|
|
|
|
out domain.ResponseType
|
2022-02-01 17:27:48 +00:00
|
|
|
}{
|
|
|
|
{in: "id", out: domain.ResponseTypeID},
|
|
|
|
{in: "code", out: domain.ResponseTypeCode},
|
|
|
|
} {
|
2022-01-30 17:49:25 +00:00
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(tc.in, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
result, err := domain.ParseResponseType(tc.in)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result != tc.out {
|
|
|
|
t.Errorf("ParseResponseType(%s) = %v, want %v", tc.in, result, tc.out)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResponseType_UnmarshalForm(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
input := []byte("code")
|
2022-07-28 18:07:37 +00:00
|
|
|
result := domain.ResponseTypeUnd
|
2022-01-30 17:49:25 +00:00
|
|
|
|
|
|
|
if err := result.UnmarshalForm(input); err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result != domain.ResponseTypeCode {
|
|
|
|
t.Errorf("UnmarshalForm(%s) = %v, want %v", input, result, domain.ResponseTypeCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResponseType_UnmarshalJSON(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
input := []byte(`"code"`)
|
2022-07-28 18:07:37 +00:00
|
|
|
result := domain.ResponseTypeUnd
|
2022-01-30 17:49:25 +00:00
|
|
|
|
|
|
|
if err := result.UnmarshalJSON(input); err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result != domain.ResponseTypeCode {
|
|
|
|
t.Errorf("UnmarshalJSON(%s) = %v, want %v", input, result, domain.ResponseTypeCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResponseType_String(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
in domain.ResponseType
|
|
|
|
out string
|
2022-02-01 17:27:48 +00:00
|
|
|
}{
|
|
|
|
{name: "id", in: domain.ResponseTypeID, out: "id"},
|
|
|
|
{name: "code", in: domain.ResponseTypeCode, out: "code"},
|
|
|
|
} {
|
2022-01-30 17:49:25 +00:00
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
result := tc.in.String()
|
|
|
|
if result != tc.out {
|
|
|
|
t.Errorf("String() = %v, want %v", result, tc.out)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|