1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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())
})
})
}
|