summaryrefslogtreecommitdiff
path: root/app/domain/entity_test.go
blob: 1ac1d2610f70a9a89cf0360338fc52087a22633b (plain)
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
package domain

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/xlgmokha/x/pkg/x"
)

func TestEntity(t *testing.T) {
	type example struct {
		entity
	}

	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.String())
	})
}