v0.35.0 e86dbd6

pending_issue_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8	"time"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12
13	"bnema.dev/ermite/internal/domain"
14)
15
16func TestPendingIssueID(t *testing.T) {
17	t.Parallel()
18	id, err := domain.NewPendingIssueID()
19	require.NoError(t, err)
20	assert.Len(t, id.String(), domain.PendingIssueIDLen)
21	got, err := domain.ParsePendingIssueID(id.String())
22	require.NoError(t, err)
23	assert.Equal(t, id, got)
24	other, err := domain.NewPendingIssueID()
25	require.NoError(t, err)
26	assert.NotEqual(t, id, other)
27
28	for _, bad := range []string{
29		"", "short", strings.ToUpper(id.String()), id.String() + "a", id.String()[:25] + "1",
30		strings.Repeat("a", 25) + "b", // spare bits set
31		strings.Repeat("a", 24) + "=a", "../" + strings.Repeat("a", 23),
32	} {
33		_, err := domain.ParsePendingIssueID(bad)
34		assert.ErrorIs(t, err, domain.ErrInvalid, "%q", bad)
35	}
36	_, err = domain.ParsePendingIssueID(strings.Repeat("a", 26))
37	assert.NoError(t, err)
38}
39
40func TestParsePendingAuthor(t *testing.T) {
41	t.Parallel()
42	got, err := domain.ParsePendingAuthor("")
43	require.NoError(t, err)
44	assert.Empty(t, got)
45	got, err = domain.ParsePendingAuthor("Al\u202ee\x01x")
46	require.NoError(t, err)
47	assert.Equal(t, "Alex", got)
48	_, err = domain.ParsePendingAuthor(strings.Repeat("a", 41))
49	assert.Error(t, err)
50	_, err = domain.ParsePendingAuthor("\xff")
51	assert.Error(t, err)
52	got, err = domain.ParsePendingAuthor(strings.Repeat("é", 40))
53	require.NoError(t, err)
54	assert.Len(t, []rune(got), 40)
55}
56
57func TestIssueSubmittedKind(t *testing.T) {
58	t.Parallel()
59	assert.Equal(t, "issue.submitted", domain.IssueSubmitted{}.EventKind())
60}
61
62func TestSubmissionLimitsAreTheDocumentedOnes(t *testing.T) {
63	t.Parallel()
64	assert.Equal(t, 3, domain.SubmitPerHour)
65	assert.Equal(t, 10, domain.SubmitPerDay)
66	assert.Equal(t, 200, domain.MaxPendingIssues)
67	assert.Equal(t, 30*24*time.Hour, domain.BanDuration)
68}
69
70func TestApprovedIssue(t *testing.T) {
71	t.Parallel()
72	at := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
73	now := at.Add(time.Hour)
74	title, err := domain.ParseIssueTitle("t")
75	require.NoError(t, err)
76	repo, err := domain.ParseRepoName("proj")
77	require.NoError(t, err)
78
79	named := domain.ApprovedIssue(domain.PendingIssue{Repo: repo, Title: title, Author: "Alex", CreatedAt: at}, now)
80	assert.Equal(t, domain.IssueStateOpen, named.State)
81	assert.Equal(t, "Alex", named.Author)
82	assert.True(t, named.External)
83	assert.Equal(t, repo, named.Repo)
84	assert.Equal(t, at, named.CreatedAt)
85	assert.Equal(t, now, named.UpdatedAt)
86	assert.Zero(t, named.Number, "the store numbers it")
87
88	anon := domain.ApprovedIssue(domain.PendingIssue{Repo: repo, Title: title, CreatedAt: at}, now)
89	assert.Equal(t, domain.AnonymousAuthor, anon.Author)
90}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 45

↑↓ moveenter openesc close