memos/test/store/memo_relation_test.go

63 lines
1.7 KiB
Go
Raw Normal View History

package teststore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
2023-09-17 22:55:13 +08:00
"github.com/usememos/memos/store"
)
func TestMemoRelationStore(t *testing.T) {
ctx := context.Background()
ts := NewTestingStore(ctx, t)
user, err := createTestingHostUser(ctx, ts)
require.NoError(t, err)
memoCreate := &store.Memo{
2024-01-20 23:48:35 +08:00
ResourceName: "main-memo",
CreatorID: user.ID,
Content: "main memo content",
Visibility: store.Public,
}
memo, err := ts.CreateMemo(ctx, memoCreate)
require.NoError(t, err)
require.Equal(t, memoCreate.Content, memo.Content)
2023-10-03 00:47:34 +08:00
relatedMemoCreate := &store.Memo{
2024-01-20 23:48:35 +08:00
ResourceName: "related-memo",
CreatorID: user.ID,
Content: "related memo content",
Visibility: store.Public,
}
2023-10-03 00:47:34 +08:00
relatedMemo, err := ts.CreateMemo(ctx, relatedMemoCreate)
require.NoError(t, err)
2023-10-03 00:47:34 +08:00
require.Equal(t, relatedMemoCreate.Content, relatedMemo.Content)
commentMemoCreate := &store.Memo{
2024-01-20 23:48:35 +08:00
ResourceName: "comment-memo",
CreatorID: user.ID,
Content: "comment memo content",
Visibility: store.Public,
2023-10-03 00:47:34 +08:00
}
commentMemo, err := ts.CreateMemo(ctx, commentMemoCreate)
require.NoError(t, err)
require.Equal(t, commentMemoCreate.Content, commentMemo.Content)
// Reference relation.
referenceRelation := &store.MemoRelation{
MemoID: memo.ID,
2023-10-03 00:47:34 +08:00
RelatedMemoID: relatedMemo.ID,
Type: store.MemoRelationReference,
}
2023-10-03 00:47:34 +08:00
_, err = ts.UpsertMemoRelation(ctx, referenceRelation)
require.NoError(t, err)
2023-10-03 00:47:34 +08:00
// Comment relation.
commentRelation := &store.MemoRelation{
MemoID: memo.ID,
RelatedMemoID: commentMemo.ID,
Type: store.MemoRelationComment,
}
_, err = ts.UpsertMemoRelation(ctx, commentRelation)
require.NoError(t, err)
ts.Close()
}