Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

1.6 KB
Raw Blame
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"
)

// TestCreateMemoComment_ReturnsParentRelation verifies that the memo returned by
// CreateMemoComment carries the COMMENT relation to its parent memo. The comment
// memo is converted before the relation is created, so without an explicit reload
// the returned memo (and the memo.comment.created webhook payload built from it)
// would have an empty Relations slice. Regression test for usememos/memos#6081.
func TestCreateMemoComment_ReturnsParentRelation(t *testing.T) {
	ctx := context.Background()
	svc := newIntegrationService(t)

	author, err := svc.Store.CreateUser(ctx, &store.User{
		Username: "author", Role: store.RoleAdmin, Email: "[email protected]",
	})
	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.CreateMemoComment(authorCtx, &apipb.CreateMemoCommentRequest{
		Parent:  parent.Name,
		Comment: &apipb.Memo{Content: "a comment", Visibility: apipb.Visibility_PUBLIC},
	})
	require.NoError(t, err)

	require.Len(t, comment.Relations, 1, "comment memo should carry its parent relation")
	rel := comment.Relations[0]
	assert.Equal(t, apipb.MemoRelation_COMMENT, rel.Type)
	require.NotNil(t, rel.Memo)
	require.NotNil(t, rel.RelatedMemo)
	assert.Equal(t, comment.Name, rel.Memo.Name)
	assert.Equal(t, parent.Name, rel.RelatedMemo.Name)
}