1package bug
2
3import (
4 "encoding/json"
5 "testing"
6 "time"
7
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10
11 "github.com/MichaelMure/git-bug/identity"
12 "github.com/MichaelMure/git-bug/repository"
13)
14
15func TestAddCommentSerialize(t *testing.T) {
16 repo := repository.NewMockRepo()
17
18 rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
19 require.NoError(t, err)
20
21 unix := time.Now().Unix()
22 before := NewAddCommentOp(rene, unix, "message", nil)
23
24 data, err := json.Marshal(before)
25 assert.NoError(t, err)
26
27 var after AddCommentOperation
28 err = json.Unmarshal(data, &after)
29 assert.NoError(t, err)
30
31 // enforce creating the ID
32 before.Id()
33
34 // Replace the identity stub with the real thing
35 assert.Equal(t, rene.Id(), after.Author().Id())
36 after.Author_ = rene
37
38 assert.Equal(t, before, &after)
39}