memo_relation_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestMemoRelationStore(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. UID: "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. relatedMemoCreate := &store.Memo{
  23. UID: "related-memo",
  24. CreatorID: user.ID,
  25. Content: "related memo content",
  26. Visibility: store.Public,
  27. }
  28. relatedMemo, err := ts.CreateMemo(ctx, relatedMemoCreate)
  29. require.NoError(t, err)
  30. require.Equal(t, relatedMemoCreate.Content, relatedMemo.Content)
  31. commentMemoCreate := &store.Memo{
  32. UID: "comment-memo",
  33. CreatorID: user.ID,
  34. Content: "comment memo content",
  35. Visibility: store.Public,
  36. }
  37. commentMemo, err := ts.CreateMemo(ctx, commentMemoCreate)
  38. require.NoError(t, err)
  39. require.Equal(t, commentMemoCreate.Content, commentMemo.Content)
  40. // Reference relation.
  41. referenceRelation := &store.MemoRelation{
  42. MemoID: memo.ID,
  43. RelatedMemoID: relatedMemo.ID,
  44. Type: store.MemoRelationReference,
  45. }
  46. _, err = ts.UpsertMemoRelation(ctx, referenceRelation)
  47. require.NoError(t, err)
  48. // Comment relation.
  49. commentRelation := &store.MemoRelation{
  50. MemoID: memo.ID,
  51. RelatedMemoID: commentMemo.ID,
  52. Type: store.MemoRelationComment,
  53. }
  54. _, err = ts.UpsertMemoRelation(ctx, commentRelation)
  55. require.NoError(t, err)
  56. ts.Close()
  57. }