1package bug
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/require"
8
9 "github.com/MichaelMure/git-bug/entities/identity"
10 "github.com/MichaelMure/git-bug/entity"
11 "github.com/MichaelMure/git-bug/entity/dag"
12 "github.com/MichaelMure/git-bug/repository"
13 "github.com/MichaelMure/git-bug/util/timestamp"
14)
15
16func TestCreate(t *testing.T) {
17 snapshot := Snapshot{}
18
19 repo := repository.NewMockRepoClock()
20
21 rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
22 require.NoError(t, err)
23
24 unix := time.Now().Unix()
25
26 create := NewCreateOp(rene, unix, "title", "message", nil)
27
28 create.Apply(&snapshot)
29
30 id := create.Id()
31 require.NoError(t, id.Validate())
32
33 comment := Comment{
34 id: entity.CombineIds(create.Id(), create.Id()),
35 Author: rene,
36 Message: "message",
37 UnixTime: timestamp.Timestamp(create.UnixTime),
38 }
39
40 expected := Snapshot{
41 id: create.Id(),
42 Title: "title",
43 Comments: []Comment{
44 comment,
45 },
46 Author: rene,
47 Participants: []identity.Interface{rene},
48 Actors: []identity.Interface{rene},
49 CreateTime: create.Time(),
50 Timeline: []TimelineItem{
51 &CreateTimelineItem{
52 CommentTimelineItem: NewCommentTimelineItem(comment),
53 },
54 },
55 }
56
57 require.Equal(t, expected, snapshot)
58}
59
60func TestCreateSerialize(t *testing.T) {
61 dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
62 return NewCreateOp(author, unixTime, "title", "message", nil)
63 })
64 dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
65 return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"})
66 })
67}