memo_organizer_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestMemoOrganizerStore(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. ResourceName: "main-memo",
  15. CreatorID: user.ID,
  16. Content: "main memo content",
  17. Visibility: store.Public,
  18. }
  19. memo, err := ts.CreateMemo(ctx, memoCreate)
  20. require.NoError(t, err)
  21. require.Equal(t, memoCreate.Content, memo.Content)
  22. memoOrganizer, err := ts.UpsertMemoOrganizer(ctx, &store.MemoOrganizer{
  23. MemoID: memo.ID,
  24. UserID: user.ID,
  25. Pinned: true,
  26. })
  27. require.NoError(t, err)
  28. require.NotNil(t, memoOrganizer)
  29. require.Equal(t, memo.ID, memoOrganizer.MemoID)
  30. require.Equal(t, user.ID, memoOrganizer.UserID)
  31. require.Equal(t, true, memoOrganizer.Pinned)
  32. memoOrganizerTemp, err := ts.GetMemoOrganizer(ctx, &store.FindMemoOrganizer{
  33. MemoID: memo.ID,
  34. })
  35. require.NoError(t, err)
  36. require.Equal(t, memoOrganizer, memoOrganizerTemp)
  37. memoOrganizerTemp, err = ts.UpsertMemoOrganizer(ctx, &store.MemoOrganizer{
  38. MemoID: memo.ID,
  39. UserID: user.ID,
  40. Pinned: false,
  41. })
  42. require.NoError(t, err)
  43. require.NotNil(t, memoOrganizerTemp)
  44. require.Equal(t, memo.ID, memoOrganizerTemp.MemoID)
  45. require.Equal(t, user.ID, memoOrganizerTemp.UserID)
  46. require.Equal(t, false, memoOrganizerTemp.Pinned)
  47. err = ts.DeleteMemoOrganizer(ctx, &store.DeleteMemoOrganizer{
  48. MemoID: &memo.ID,
  49. UserID: &user.ID,
  50. })
  51. require.NoError(t, err)
  52. memoOrganizers, err := ts.ListMemoOrganizer(ctx, &store.FindMemoOrganizer{
  53. UserID: user.ID,
  54. })
  55. require.NoError(t, err)
  56. require.Equal(t, 0, len(memoOrganizers))
  57. ts.Close()
  58. }