package domain import ( "fmt" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/xlgmokha/x/pkg/x" ) func TestSparkle(t *testing.T) { t.Run("New", func(t *testing.T) { t.Run("with a valid body", func(t *testing.T) { sparkle := x.New[*Sparkle](WithText("@tanuki for helping me with my homework!")) require.NoError(t, sparkle.Validate()) assert.Equal(t, "@tanuki", sparkle.Sparklee) assert.Equal(t, "for helping me with my homework!", sparkle.Reason) }) t.Run("with an empty body", func(t *testing.T) { sparkle := x.New[*Sparkle](WithText("")) require.Error(t, sparkle.Validate()) }) t.Run("without a reason", func(t *testing.T) { sparkle := x.New[*Sparkle](WithText("@tanuki")) require.Error(t, sparkle.Validate()) }) t.Run("without a username", func(t *testing.T) { sparkle := x.New[*Sparkle](WithText("for helping me with my homework")) require.Error(t, sparkle.Validate()) }) }) t.Run("ToGID", func(t *testing.T) { t.Run("returns a valid global id", func(t *testing.T) { sparkle := x.New[*Sparkle](WithULID[*Sparkle]()) gid := sparkle.ToGID() assert.Equal(t, fmt.Sprintf("gid://sparkle/Sparkle/%s", sparkle.ID), gid.String()) }) }) t.Run("ToObjectReference", func(t *testing.T) { t.Run("returns a valid object reference", func(t *testing.T) { sparkle := x.New[*Sparkle](WithULID[*Sparkle]()) reference := sparkle.ToGID().ToObjectReference() require.NotNil(t, reference) require.NoError(t, reference.ValidateAll()) assert.Equal(t, sparkle.ID.String(), reference.GetObjectId()) assert.Equal(t, "sparkle", reference.GetObjectType()) }) }) }