Files
memos/server/api/memo_comment_relations_test.go
T
johnnyjoygh 8b61d2e9d6 feat(memos)!: treat a comment as a memo with a parent
ListMemos returns comments; a feed narrows to top-level memos with the
filter `parent == null`. A comment is created by CreateMemo with
memo.parent, read through Memo.parent, and counted by the new
Memo.comment_count. ListMemoComments, CreateMemoComment and
MemoRelation.Type.COMMENT are removed, along with the two MCP comment
tools. Storage is unchanged: a comment is still one COMMENT row in
memo_relation.

The memo filter gains `parent` and `name`. User stats count comments
unless their filter excludes them. Memo.comment_count takes field 13 and
the fields after it move to 14 through 18.

Web: memo lists leave comments out unless "Include comments" is on. It
and Compact mode move from the Timeline view options to Settings >
Preferences > This device and apply to every memo list. A comment shown
in a list names its parent on a strip above its card, and the parents of
a page of comments are fetched with one request.
2026-11-22 12:42:06 +08:00

54 lines
1.9 KiB
Go

package api
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
apipb "github.com/usememos/memos/proto/gen/api"
"github.com/usememos/memos/store"
)
// TestCreateMemo_CommentReturnsParent verifies that a memo created with a
// parent is returned as a comment on it: the response (and the
// memo.comment.created webhook payload built from the same memo) names the
// parent, the link is not repeated as a relation, and the parent counts the
// comment. Regression test for usememos/memos#6081.
func TestCreateMemo_CommentReturnsParent(t *testing.T) {
ctx := context.Background()
svc := newIntegrationService(t)
author, err := svc.Store.CreateUser(ctx, &store.User{
Username: "author", Role: store.RoleAdmin, Email: "author@example.com",
})
require.NoError(t, err)
authorCtx := userCtx(ctx, author.ID)
parent, err := svc.CreateMemo(authorCtx, &apipb.CreateMemoRequest{
Memo: &apipb.Memo{Content: "parent memo", Visibility: apipb.Visibility_PUBLIC},
})
require.NoError(t, err)
comment, err := svc.CreateMemo(authorCtx, &apipb.CreateMemoRequest{
Memo: &apipb.Memo{Parent: new(parent.Name), Content: "a comment", Visibility: apipb.Visibility_PUBLIC},
})
require.NoError(t, err)
assert.Equal(t, parent.Name, comment.GetParent(), "comment memo should name its parent")
assert.Empty(t, comment.Relations, "the parent link is not a relation")
assert.Zero(t, comment.CommentCount)
reloadedComment, err := svc.GetMemo(authorCtx, &apipb.GetMemoRequest{Name: comment.Name})
require.NoError(t, err)
assert.Equal(t, parent.Name, reloadedComment.GetParent())
assert.Empty(t, reloadedComment.Relations)
reloadedParent, err := svc.GetMemo(authorCtx, &apipb.GetMemoRequest{Name: parent.Name})
require.NoError(t, err)
assert.Nil(t, reloadedParent.Parent)
assert.Empty(t, reloadedParent.Relations)
assert.EqualValues(t, 1, reloadedParent.CommentCount)
}