reaction_test.go 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestReactionStore(t *testing.T) {
  9. ctx := context.Background()
  10. ts := NewTestingStore(ctx, t)
  11. user, err := createTestingHostUser(ctx, ts)
  12. require.NoError(t, err)
  13. contentID := "test_content_id"
  14. reaction, err := ts.UpsertReaction(ctx, &store.Reaction{
  15. CreatorID: user.ID,
  16. ContentID: contentID,
  17. ReactionType: "💗",
  18. })
  19. require.NoError(t, err)
  20. require.NotNil(t, reaction)
  21. require.NotEmpty(t, reaction.ID)
  22. reactions, err := ts.ListReactions(ctx, &store.FindReaction{
  23. ContentID: &contentID,
  24. })
  25. require.NoError(t, err)
  26. require.Len(t, reactions, 1)
  27. require.Equal(t, reaction, reactions[0])
  28. err = ts.DeleteReaction(ctx, &store.DeleteReaction{
  29. ID: reaction.ID,
  30. })
  31. require.NoError(t, err)
  32. reactions, err = ts.ListReactions(ctx, &store.FindReaction{
  33. ContentID: &contentID,
  34. })
  35. require.NoError(t, err)
  36. require.Len(t, reactions, 0)
  37. ts.Close()
  38. }