diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-24 15:55:09 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-24 15:55:09 -0600 |
| commit | f6ad289b8d27219c47aefec24113ccb02a62dd99 (patch) | |
| tree | 8febaf35f6686c3f46ed4b8a1990138b6f622300 /app/domain/entity_test.go | |
| parent | 7fb5255aafc435f5b47725716963f3aebfb9feb2 (diff) | |
refactor: extract defaultEntity type
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()) + }) + }) +} |
