aboutsummaryrefslogtreecommitdiffstats
path: root/entities/bug/op_create_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-23 15:01:36 +0200
committerGitHub <noreply@github.com>2022-08-23 15:01:36 +0200
commit5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f (patch)
treee5382a09a45098672b6d60397eac201617fdd6ec /entities/bug/op_create_test.go
parent81fd7a5d8b6443e65c861f00a7387c0a3c926c66 (diff)
parent6ed4b8b7a1185ad278eb2e40b32e859f828233d9 (diff)
downloadgit-bug-5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f.tar.gz
Merge pull request #664 from MichaelMure/combined-id-rework
bug: have a type for combined ids, fix #653
Diffstat (limited to 'entities/bug/op_create_test.go')
-rw-r--r--entities/bug/op_create_test.go56
1 files changed, 19 insertions, 37 deletions
diff --git a/entities/bug/op_create_test.go b/entities/bug/op_create_test.go
index f2c9e675..e534162b 100644
--- a/entities/bug/op_create_test.go
+++ b/entities/bug/op_create_test.go
@@ -6,55 +6,37 @@ import (
"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"
- "github.com/MichaelMure/git-bug/util/timestamp"
)
func TestCreate(t *testing.T) {
- snapshot := Snapshot{}
-
- repo := repository.NewMockRepoClock()
+ repo := repository.NewMockRepo()
rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
require.NoError(t, err)
- unix := time.Now().Unix()
-
- create := NewCreateOp(rene, unix, "title", "message", nil)
-
- create.Apply(&snapshot)
-
- id := create.Id()
- require.NoError(t, id.Validate())
-
- comment := Comment{
- id: entity.CombineIds(create.Id(), create.Id()),
- Author: rene,
- Message: "message",
- UnixTime: timestamp.Timestamp(create.UnixTime),
- }
-
- expected := Snapshot{
- id: create.Id(),
- Title: "title",
- Comments: []Comment{
- comment,
- },
- Author: rene,
- Participants: []identity.Interface{rene},
- Actors: []identity.Interface{rene},
- CreateTime: create.Time(),
- Timeline: []TimelineItem{
- &CreateTimelineItem{
- CommentTimelineItem: NewCommentTimelineItem(comment),
- },
- },
- }
+ b, op, err := Create(rene, time.Now().Unix(), "title", "message", nil, nil)
+ require.NoError(t, err)
- require.Equal(t, expected, snapshot)
+ 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) {