aboutsummaryrefslogblamecommitdiffstats
path: root/commands/bug/testenv/testenv.go
blob: 10f20950ddf817049f1af62f6ec5c35718d62368 (plain) (tree)






























































                                                                                             
package testenv

import (
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/MichaelMure/git-bug/commands/execenv"
	"github.com/MichaelMure/git-bug/entity"
)

const (
	testUserName  = "John Doe"
	testUserEmail = "jdoe@example.com"
)

func NewTestEnvAndUser(t *testing.T) (*execenv.Env, entity.Id) {
	t.Helper()

	testEnv := execenv.NewTestEnv(t)

	i, err := testEnv.Backend.NewIdentity(testUserName, testUserEmail)
	require.NoError(t, err)

	err = testEnv.Backend.SetUserIdentity(i)
	require.NoError(t, err)

	return testEnv, i.Id()
}

const (
	testBugTitle   = "this is a bug title"
	testBugMessage = "this is a bug message"
)

func NewTestEnvAndBug(t *testing.T) (*execenv.Env, entity.Id) {
	t.Helper()

	testEnv, _ := NewTestEnvAndUser(t)

	b, _, err := testEnv.Backend.NewBug(testBugTitle, testBugMessage)
	require.NoError(t, err)

	return testEnv, b.Id()
}

const (
	testCommentMessage = "this is a bug comment"
)

func NewTestEnvAndBugWithComment(t *testing.T) (*execenv.Env, entity.Id, entity.CombinedId) {
	t.Helper()

	env, bugID := NewTestEnvAndBug(t)

	b, err := env.Backend.ResolveBug(bugID)
	require.NoError(t, err)

	commentId, _, err := b.AddComment(testCommentMessage)
	require.NoError(t, err)

	return env, bugID, commentId
}