2024-02-07 23:40:23 +08:00
|
|
|
package teststore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
storepb "github.com/usememos/memos/proto/gen/store"
|
|
|
|
"github.com/usememos/memos/store"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReactionStore(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
ts := NewTestingStore(ctx, t)
|
|
|
|
|
|
|
|
user, err := createTestingHostUser(ctx, ts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
contentID := "test_content_id"
|
2024-04-13 11:54:37 +08:00
|
|
|
reaction, err := ts.UpsertReaction(ctx, &store.Reaction{
|
|
|
|
CreatorID: user.ID,
|
|
|
|
ContentID: contentID,
|
|
|
|
ReactionType: storepb.ReactionType_HEART,
|
2024-02-07 23:40:23 +08:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, reaction)
|
2024-04-13 11:54:37 +08:00
|
|
|
require.NotEmpty(t, reaction.ID)
|
2024-02-07 23:40:23 +08:00
|
|
|
|
|
|
|
reactions, err := ts.ListReactions(ctx, &store.FindReaction{
|
|
|
|
ContentID: &contentID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, reactions, 1)
|
|
|
|
require.Equal(t, reaction, reactions[0])
|
|
|
|
|
|
|
|
err = ts.DeleteReaction(ctx, &store.DeleteReaction{
|
2024-04-13 11:54:37 +08:00
|
|
|
ID: reaction.ID,
|
2024-02-07 23:40:23 +08:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
reactions, err = ts.ListReactions(ctx, &store.FindReaction{
|
|
|
|
ContentID: &contentID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, reactions, 0)
|
|
|
|
|
|
|
|
ts.Close()
|
|
|
|
}
|