2018-09-28 21:39:39 +03:00
|
|
|
package bug
|
2018-07-12 22:31:41 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-09-25 18:56:58 +03:00
|
|
|
"time"
|
2018-09-29 21:41:19 +03:00
|
|
|
|
2020-11-08 21:15:06 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-05-03 12:45:15 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entities/common"
|
2022-08-19 00:34:05 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entities/identity"
|
2020-11-30 03:55:30 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2022-07-25 14:16:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity/dag"
|
2020-07-01 21:00:53 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-07-12 22:31:41 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
2021-05-03 12:45:15 +03:00
|
|
|
repo := repository.NewMockRepo()
|
2020-11-08 21:15:06 +03:00
|
|
|
|
|
|
|
rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-03 12:45:15 +03:00
|
|
|
b, op, err := Create(rene, time.Now().Unix(), "title", "message", nil, nil)
|
|
|
|
require.NoError(t, err)
|
2018-07-12 22:31:41 +03:00
|
|
|
|
2021-05-03 12:45:15 +03:00
|
|
|
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)
|
2018-07-12 22:31:41 +03:00
|
|
|
}
|
2019-01-19 21:23:31 +03:00
|
|
|
|
|
|
|
func TestCreateSerialize(t *testing.T) {
|
2022-08-24 22:29:17 +03:00
|
|
|
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) {
|
|
|
|
return NewCreateOp(author, unixTime, "title", "message", nil), nil
|
2022-07-25 14:16:16 +03:00
|
|
|
})
|
2022-08-24 22:29:17 +03:00
|
|
|
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) {
|
|
|
|
return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"}), nil
|
2022-07-25 14:16:16 +03:00
|
|
|
})
|
2019-01-19 21:23:31 +03:00
|
|
|
}
|