diff options
Diffstat (limited to 'app/domain/entity_test.go')
| -rw-r--r-- | app/domain/entity_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/app/domain/entity_test.go b/app/domain/entity_test.go new file mode 100644 index 0000000..ee3fbae --- /dev/null +++ b/app/domain/entity_test.go @@ -0,0 +1,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()) + }) + }) +} |
