aboutsummaryrefslogtreecommitdiffstats
path: root/entities/bug/op_create_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'entities/bug/op_create_test.go')
-rw-r--r--entities/bug/op_create_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/entities/bug/op_create_test.go b/entities/bug/op_create_test.go
new file mode 100644
index 00000000..e534162b
--- /dev/null
+++ b/entities/bug/op_create_test.go
@@ -0,0 +1,49 @@
+package bug
+
+import (
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/MichaelMure/git-bug/entities/common"
+ "github.com/MichaelMure/git-bug/entities/identity"
+ "github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/entity/dag"
+ "github.com/MichaelMure/git-bug/repository"
+)
+
+func TestCreate(t *testing.T) {
+ repo := repository.NewMockRepo()
+
+ rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
+ require.NoError(t, err)
+
+ b, op, err := Create(rene, time.Now().Unix(), "title", "message", nil, nil)
+ require.NoError(t, err)
+
+ require.Equal(t, "title", op.Title)
+ require.Equal(t, "message", op.Message)
+
+ // Create generate the initial operation and create a new timeline item
+ snap := b.Compile()
+ require.Equal(t, common.OpenStatus, snap.Status)
+ require.Equal(t, rene, snap.Author)
+ require.Equal(t, "title", snap.Title)
+ require.Len(t, snap.Operations, 1)
+ require.Equal(t, op, snap.Operations[0])
+
+ require.Len(t, snap.Timeline, 1)
+ require.Equal(t, entity.CombineIds(b.Id(), op.Id()), snap.Timeline[0].CombinedId())
+ require.Equal(t, rene, snap.Timeline[0].(*CreateTimelineItem).Author)
+ require.Equal(t, "message", snap.Timeline[0].(*CreateTimelineItem).Message)
+}
+
+func TestCreateSerialize(t *testing.T) {
+ dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
+ return NewCreateOp(author, unixTime, "title", "message", nil)
+ })
+ dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
+ return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"})
+ })
+}