memos/test/store/memo_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2023-04-03 09:53:36 +08:00
package teststore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
2023-09-17 22:55:13 +08:00
2023-05-25 21:50:37 +08:00
"github.com/usememos/memos/store"
2023-04-03 09:53:36 +08:00
)
func TestMemoStore(t *testing.T) {
ctx := context.Background()
2023-05-25 21:50:37 +08:00
ts := NewTestingStore(ctx, t)
user, err := createTestingHostUser(ctx, ts)
2023-04-03 09:53:36 +08:00
require.NoError(t, err)
memoCreate := &store.Memo{
2023-04-03 09:53:36 +08:00
CreatorID: user.ID,
Content: "test_content",
2023-05-25 21:50:37 +08:00
Visibility: store.Public,
2023-04-03 09:53:36 +08:00
}
2023-05-25 21:50:37 +08:00
memo, err := ts.CreateMemo(ctx, memoCreate)
2023-04-03 09:53:36 +08:00
require.NoError(t, err)
require.Equal(t, memoCreate.Content, memo.Content)
memoPatchContent := "test_content_2"
memoPatch := &store.UpdateMemo{
2023-04-03 09:53:36 +08:00
ID: memo.ID,
Content: &memoPatchContent,
}
2023-05-25 21:50:37 +08:00
err = ts.UpdateMemo(ctx, memoPatch)
2023-04-03 09:53:36 +08:00
require.NoError(t, err)
memo, err = ts.GetMemo(ctx, &store.FindMemo{
2023-05-25 21:50:37 +08:00
ID: &memo.ID,
})
require.NoError(t, err)
2023-07-06 22:53:38 +08:00
require.NotNil(t, memo)
memoList, err := ts.ListMemos(ctx, &store.FindMemo{
2023-04-03 09:53:36 +08:00
CreatorID: &user.ID,
})
require.NoError(t, err)
require.Equal(t, 1, len(memoList))
require.Equal(t, memo, memoList[0])
err = ts.DeleteMemo(ctx, &store.DeleteMemo{
2023-04-03 09:53:36 +08:00
ID: memo.ID,
})
require.NoError(t, err)
}