2023-08-05 23:58:57 +00:00
|
|
|
package domain_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2024-05-06 16:23:11 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain/scope"
|
2023-08-05 23:58:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestScopes_UnmarshalForm(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
input := []byte("profile email")
|
2024-05-06 16:23:11 +00:00
|
|
|
actual := make(domain.Scopes, 0)
|
2023-08-05 23:58:57 +00:00
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
if err := actual.UnmarshalForm(input); err != nil {
|
|
|
|
t.Fatal(err)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
expect := domain.Scopes{scope.Profile, scope.Email}
|
|
|
|
if !reflect.DeepEqual(actual, expect) {
|
|
|
|
t.Errorf("UnmarshalForm(%s) = %s, want %s", input, actual, expect)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScopes_UnmarshalJSON(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
input := []byte(`"profile email"`)
|
2024-05-06 16:23:11 +00:00
|
|
|
actual := make(domain.Scopes, 0)
|
2023-08-05 23:58:57 +00:00
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
if err := actual.UnmarshalJSON(input); err != nil {
|
|
|
|
t.Fatal(err)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
expect := domain.Scopes{scope.Profile, scope.Email}
|
|
|
|
if !reflect.DeepEqual(actual, expect) {
|
|
|
|
t.Errorf("UnmarshalJSON(%s) = %s, want %s", input, actual, expect)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScopes_MarshalJSON(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
scopes := domain.Scopes{scope.Email, scope.Profile}
|
2023-08-05 23:58:57 +00:00
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
actual, err := scopes.MarshalJSON()
|
2023-08-05 23:58:57 +00:00
|
|
|
if err != nil {
|
2024-05-06 16:23:11 +00:00
|
|
|
t.Fatal(err)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
if string(actual) != fmt.Sprintf(`"%s"`, scopes) {
|
|
|
|
t.Errorf("MarshalJSON() = %s, want %s", actual, fmt.Sprintf(`"%s"`, scopes))
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScopes_String(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
scopes := domain.Scopes{scope.Profile, scope.Email}
|
|
|
|
if actual := scopes.String(); actual != fmt.Sprint(scopes) {
|
|
|
|
t.Errorf("String() = %s, want %s", actual, scopes)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScopes_IsEmpty(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
scopes := domain.Scopes{scope.Und}
|
|
|
|
if actual := scopes.IsEmpty(); !actual {
|
|
|
|
t.Errorf("IsEmpty() = %t, want %t", actual, true)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScopes_Has(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-05-06 16:23:11 +00:00
|
|
|
scopes := domain.Scopes{scope.Profile, scope.Email}
|
|
|
|
if actual := scopes.Has(scope.Email); !actual {
|
|
|
|
t.Errorf("Has(%s) = %t, want %t", scope.Email, actual, true)
|
2023-08-05 23:58:57 +00:00
|
|
|
}
|
|
|
|
}
|