feat: authsession service
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package userresolution
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
|
||||
"galaxy/authsession/internal/domain/common"
|
||||
)
|
||||
|
||||
func TestKindIsKnown(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value Kind
|
||||
want bool
|
||||
}{
|
||||
{name: "existing", value: KindExisting, want: true},
|
||||
{name: "creatable", value: KindCreatable, want: true},
|
||||
{name: "blocked", value: KindBlocked, want: true},
|
||||
{name: "unknown", value: Kind("unknown"), want: false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := tt.value.IsKnown(); got != tt.want {
|
||||
require.Failf(t, "test failed", "IsKnown() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResultValidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value Result
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "existing valid",
|
||||
value: Result{
|
||||
Kind: KindExisting,
|
||||
UserID: common.UserID("user-123"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "creatable valid",
|
||||
value: Result{
|
||||
Kind: KindCreatable,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "blocked valid",
|
||||
value: Result{
|
||||
Kind: KindBlocked,
|
||||
BlockReasonCode: BlockReasonCode("policy_blocked"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "existing requires user id",
|
||||
value: Result{
|
||||
Kind: KindExisting,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "creatable rejects user id",
|
||||
value: Result{
|
||||
Kind: KindCreatable,
|
||||
UserID: common.UserID("user-123"),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "blocked requires reason",
|
||||
value: Result{
|
||||
Kind: KindBlocked,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "blocked rejects user id",
|
||||
value: Result{
|
||||
Kind: KindBlocked,
|
||||
UserID: common.UserID("user-123"),
|
||||
BlockReasonCode: BlockReasonCode("policy_blocked"),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := tt.value.Validate()
|
||||
if tt.wantErr && err == nil {
|
||||
require.FailNow(t, "Validate() returned nil error")
|
||||
}
|
||||
if !tt.wantErr && err != nil {
|
||||
require.Failf(t, "test failed", "Validate() returned error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user