mirror of
https://github.com/usememos/memos.git
synced 2024-11-15 11:17:58 +08:00
5bcbbd4c52
It's just a matter of explicitly closing the database, so that TempDir.removeAll doesn't fail.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package teststore
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"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{
|
|
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)
|
|
relatedMemoCreate := &store.Memo{
|
|
CreatorID: user.ID,
|
|
Content: "related memo content",
|
|
Visibility: store.Public,
|
|
}
|
|
relatedMemo, err := ts.CreateMemo(ctx, relatedMemoCreate)
|
|
require.NoError(t, err)
|
|
require.Equal(t, relatedMemoCreate.Content, relatedMemo.Content)
|
|
commentMemoCreate := &store.Memo{
|
|
CreatorID: user.ID,
|
|
Content: "comment memo content",
|
|
Visibility: store.Public,
|
|
}
|
|
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,
|
|
RelatedMemoID: relatedMemo.ID,
|
|
Type: store.MemoRelationReference,
|
|
}
|
|
_, err = ts.UpsertMemoRelation(ctx, referenceRelation)
|
|
require.NoError(t, err)
|
|
// 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()
|
|
}
|