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 var rene = identity.NewIdentity("René Descartes", "rene@descartes.fr")
16
17 unix := time.Now().Unix()
18
19 create := NewCreateOp(rene, unix, "title", "message", nil)
20
21 create.Apply(&snapshot)
22
23 hash, err := create.Hash()
24 assert.NoError(t, err)
25
26 comment := Comment{Author: rene, Message: "message", UnixTime: Timestamp(create.UnixTime)}
27
28 expected := Snapshot{
29 Title: "title",
30 Comments: []Comment{
31 comment,
32 },
33 Author: rene,
34 CreatedAt: create.Time(),
35 Timeline: []TimelineItem{
36 &CreateTimelineItem{
37 CommentTimelineItem: NewCommentTimelineItem(hash, comment),
38 },
39 },
40 }
41
42 assert.Equal(t, expected, snapshot)
43}
44
45func TestCreateSerialize(t *testing.T) {
46 var rene = identity.NewBare("René Descartes", "rene@descartes.fr")
47 unix := time.Now().Unix()
48 before := NewCreateOp(rene, unix, "title", "message", nil)
49
50 data, err := json.Marshal(before)
51 assert.NoError(t, err)
52
53 var after CreateOperation
54 err = json.Unmarshal(data, &after)
55 assert.NoError(t, err)
56
57 assert.Equal(t, before, &after)
58}