aboutsummaryrefslogblamecommitdiffstats
path: root/entities/bug/op_create_test.go
blob: e534162b0f70164b7eae77dc8832063c6d38f614 (plain) (tree)
1
2
3
4
5
6
7
8
9
           

        
                 
              
 

                                             
                                                        
                                                          
                                               
                                                   
                                                   


                               
                                        



                                                                                       

                                                                                   
 














                                                                                           
 

                                        





                                                                                                             
 
package bug

import (
	"testing"
	"time"

	"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"
)

func TestCreate(t *testing.T) {
	repo := repository.NewMockRepo()

	rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
	require.NoError(t, err)

	b, op, err := Create(rene, time.Now().Unix(), "title", "message", nil, nil)
	require.NoError(t, err)

	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) {
	dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
		return NewCreateOp(author, unixTime, "title", "message", nil)
	})
	dag.SerializeRoundTripTest(t, func(author identity.Interface, unixTime int64) *CreateOperation {
		return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"})
	})
}