aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bug/testenv/testenv.go
blob: 10f20950ddf817049f1af62f6ec5c35718d62368 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
}