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
|
package domain
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xlgmokha/x/pkg/x"
)
func TestDefaultEntity(t *testing.T) {
type example struct {
defaultEntity
}
t.Run("GetID", func(t *testing.T) {
t.Run("returns the assigned ID", func(t *testing.T) {
example := x.New[*example](WithULID[*example]())
assert.Equal(t, example.ID, example.GetID())
})
})
t.Run("SetID", func(t *testing.T) {
t.Run("assigns a new ID", func(t *testing.T) {
id := ID("1")
example := x.New[*example]()
example.SetID(id)
assert.Equal(t, id, example.GetID())
})
})
t.Run("ToGID", func(t *testing.T) {
example := x.New[*example](WithULID[*example]())
gid := example.ToGID()
assert.Equal(t, fmt.Sprintf("gid://sparkle/Entity/%s", example.ID), gid)
})
t.Run("ToObjectReference", func(t *testing.T) {
t.Run("returns a valid object reference", func(t *testing.T) {
example := x.New[*example](WithULID[*example]())
reference := example.ToObjectReference()
require.NotNil(t, reference)
require.NoError(t, reference.Validate())
require.NoError(t, reference.ValidateAll())
assert.Equal(t, fmt.Sprintf("object_type:\"entity\" object_id:\"%s\"", example.ID), reference.String())
})
})
}
|