mirror of
https://github.com/usememos/memos.git
synced 2024-11-15 03:07:04 +08:00
9c18960f47
* skeleton of postgres skeleton * Adding Postgres specific db schema sql * user test passed * memo store test passed * tag is working * update user setting test done * activity test done * idp test passed * inbox test done * memo_organizer, UNTESTED * memo relation test passed * webhook test passed * system setting test passed * passed storage test * pass resource test * migration_history done * fix memo_relation_test * fixing server memo_relation test * passes memo relation server test * paess memo test * final manual testing done * final fixes * final fixes cleanup * sync schema * lint * lint * lint * lint * lint
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package teststore
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/usememos/memos/store"
|
|
)
|
|
|
|
func TestMemoStore(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: "test_content",
|
|
Visibility: store.Public,
|
|
}
|
|
memo, err := ts.CreateMemo(ctx, memoCreate)
|
|
require.NoError(t, err)
|
|
require.Equal(t, memoCreate.Content, memo.Content)
|
|
memoPatchContent := "test_content_2"
|
|
memoPatch := &store.UpdateMemo{
|
|
ID: memo.ID,
|
|
Content: &memoPatchContent,
|
|
}
|
|
err = ts.UpdateMemo(ctx, memoPatch)
|
|
require.NoError(t, err)
|
|
memo, err = ts.GetMemo(ctx, &store.FindMemo{
|
|
ID: &memo.ID,
|
|
})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, memo)
|
|
memoList, err := ts.ListMemos(ctx, &store.FindMemo{
|
|
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{
|
|
ID: memo.ID,
|
|
})
|
|
require.NoError(t, err)
|
|
memoList, err = ts.ListMemos(ctx, &store.FindMemo{
|
|
CreatorID: &user.ID,
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, len(memoList))
|
|
|
|
memoList, err = ts.ListMemos(ctx, &store.FindMemo{
|
|
CreatorID: &user.ID,
|
|
VisibilityList: []store.Visibility{
|
|
store.Public,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, len(memoList))
|
|
}
|