1package bug
2
3import (
4 "encoding/json"
5 "testing"
6 "time"
7
8 "github.com/MichaelMure/git-bug/identity"
9 "github.com/stretchr/testify/assert"
10)
11
12func TestCreate(t *testing.T) {
13 snapshot := Snapshot{}
14
15 rene := identity.NewBare("René Descartes", "rene@descartes.fr")
16 unix := time.Now().Unix()
17
18 create := NewCreateOp(rene, unix, "title", "message", nil)
19
20 create.Apply(&snapshot)
21
22 hash, err := create.Hash()
23 assert.NoError(t, err)
24
25 comment := Comment{Author: rene, Message: "message", UnixTime: Timestamp(create.UnixTime)}
26
27 expected := Snapshot{
28 Title: "title",
29 Comments: []Comment{
30 comment,
31 },
32 Author: rene,
33 CreatedAt: create.Time(),
34 Timeline: []TimelineItem{
35 &CreateTimelineItem{
36 CommentTimelineItem: NewCommentTimelineItem(hash, comment),
37 },
38 },
39 }
40
41 assert.Equal(t, expected, snapshot)
42}
43
44func TestCreateSerialize(t *testing.T) {
45 var rene = identity.NewBare("René Descartes", "rene@descartes.fr")
46 unix := time.Now().Unix()
47 before := NewCreateOp(rene, unix, "title", "message", nil)
48
49 data, err := json.Marshal(before)
50 assert.NoError(t, err)
51
52 var after CreateOperation
53 err = json.Unmarshal(data, &after)
54 assert.NoError(t, err)
55
56 assert.Equal(t, before, &after)
57}