memo_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestMemoStore(t *testing.T) {
  9. ctx := context.Background()
  10. ts := NewTestingStore(ctx, t)
  11. user, err := createTestingHostUser(ctx, ts)
  12. require.NoError(t, err)
  13. memoCreate := &store.Memo{
  14. CreatorID: user.ID,
  15. Content: "test_content",
  16. Visibility: store.Public,
  17. }
  18. memo, err := ts.CreateMemo(ctx, memoCreate)
  19. require.NoError(t, err)
  20. require.Equal(t, memoCreate.Content, memo.Content)
  21. memoPatchContent := "test_content_2"
  22. memoPatch := &store.UpdateMemo{
  23. ID: memo.ID,
  24. Content: &memoPatchContent,
  25. }
  26. err = ts.UpdateMemo(ctx, memoPatch)
  27. require.NoError(t, err)
  28. memo, err = ts.GetMemo(ctx, &store.FindMemo{
  29. ID: &memo.ID,
  30. })
  31. require.NoError(t, err)
  32. require.NotNil(t, memo)
  33. memoList, err := ts.ListMemos(ctx, &store.FindMemo{
  34. CreatorID: &user.ID,
  35. })
  36. require.NoError(t, err)
  37. require.Equal(t, 1, len(memoList))
  38. require.Equal(t, memo, memoList[0])
  39. err = ts.DeleteMemo(ctx, &store.DeleteMemo{
  40. ID: memo.ID,
  41. })
  42. require.NoError(t, err)
  43. }