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