mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(wiki,notification): guard wiki edit renames, show real revision totals and tidy notification view
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
6 files changed
+145
-24
No files matched your search
@@ -20,12 +20,19 @@ func TestWikiEditRenamesAndKeepsTheContent(t *testing.T) {
|
||||
_, _ = w.Write([]byte(`{"title":"New Title","content_base64":"S2VlcCBtZQ=="}`))
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/api/v1/repos/alice/x/wiki/page/New Title" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"title":"Old Title","content_base64":"S2VlcCBtZQ=="}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, diagnostics := repoTTYDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "edit", "Old Title", "--title", "New Title", "-R", "alice/x", "--no-input"}))
|
||||
require.Equal(t, []string{"GET /api/v1/repos/alice/x/wiki/page/Old Title", "PATCH /api/v1/repos/alice/x/wiki/page/Old Title"}, requests)
|
||||
require.Equal(t, []string{
|
||||
"GET /api/v1/repos/alice/x/wiki/page/Old Title", "GET /api/v1/repos/alice/x/wiki/page/Old Title",
|
||||
"GET /api/v1/repos/alice/x/wiki/page/New Title", "PATCH /api/v1/repos/alice/x/wiki/page/Old Title",
|
||||
}, requests)
|
||||
require.Empty(t, out.String())
|
||||
require.Equal(t, "✓ Renamed wiki page \"Old Title\" to \"New Title\" in alice/x\n", diagnostics.String())
|
||||
err := Execute(context.Background(), deps, []string{"wiki", "edit", "Home", "-R", "alice/x"})
|
||||
@@ -65,3 +72,43 @@ func TestWikiViewAndCreate(t *testing.T) {
|
||||
require.Equal(t, "https://gitea.test/alice/x/wiki/Page-Two\n", out.String())
|
||||
require.Equal(t, "✓ Created wiki page \"Page Two\" in alice/x\n", diagnostics.String())
|
||||
}
|
||||
|
||||
func TestWikiEditRefusesToOverwriteOrCreate(t *testing.T) {
|
||||
patched := 0
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.Method == http.MethodPatch:
|
||||
patched++
|
||||
_, _ = w.Write([]byte(`{"title":"Getting Started","content_base64":"eA=="}`))
|
||||
case r.URL.Path == "/api/v1/repos/alice/x/wiki/page/Draft":
|
||||
_, _ = w.Write([]byte(`{"title":"Draft","content_base64":"ZHJhZnQ="}`))
|
||||
case r.URL.Path == "/api/v1/repos/alice/x/wiki/page/Page B":
|
||||
_, _ = w.Write([]byte(`{"title":"Page B","content_base64":"Yg=="}`))
|
||||
case r.URL.Path == "/api/v1/repos/alice/x/wiki/page/Getting-Started":
|
||||
_, _ = w.Write([]byte(`{"title":"Getting Started","content_base64":"Zw=="}`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, _, diagnostics := repoTTYDeps(t, server.URL)
|
||||
err := Execute(context.Background(), deps, []string{"wiki", "edit", "Draft", "--title", "Page B", "-R", "alice/x", "--no-input"})
|
||||
require.ErrorContains(t, err, `wiki page "Page B" already exists in alice/x`)
|
||||
err = Execute(context.Background(), deps, []string{"wiki", "edit", "Drfat", "--body", "x", "-R", "alice/x", "--no-input"})
|
||||
require.ErrorContains(t, err, `wiki page "Drfat" not found`)
|
||||
require.Zero(t, patched, "neither refused edit may reach the PATCH")
|
||||
// Editing by the URL slug is not a rename.
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "edit", "Getting-Started", "--body", "x", "-R", "alice/x", "--no-input"}))
|
||||
require.Equal(t, "✓ Edited wiki page \"Getting Started\" in alice/x\n", diagnostics.String())
|
||||
require.Equal(t, 1, patched)
|
||||
}
|
||||
|
||||
func TestWikiRevisionsCountsTheWholeHistory(t *testing.T) {
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"commits":[{"sha":"abc","message":"Edit","author":{"name":"alice","date":"2026-10-11T18:00:00Z"}}],"count":56}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := repoTTYDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "revisions", "Home", "-R", "alice/x"}))
|
||||
require.Contains(t, out.String(), "Showing 1 of 56 revisions of wiki page \"Home\" · next: --page 2")
|
||||
}
|
||||
Reference in new issue
Block a user