ci / api / api (push) Canceled after 0s
ci / module boundaries / boundaries (push) Canceled after 0s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Canceled after 11m29s
ci / db / db (push) Canceled after 11m22s
ci / mobile / mobile (Metro-бандл Android) (push) Canceled after 6m43s
ci / recommender / recommender (push) Canceled after 6m47s
ci / ts / ts (packages + web) (push) Canceled after 1s
52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
package social
|
|
|
|
import (
|
|
"context"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"pipu/api/internal/api/gen"
|
|
"pipu/api/internal/auth"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMessageValidation(t *testing.T) {
|
|
id := uuid.New()
|
|
for _, m := range []gen.SendDirectMessage{
|
|
{Id: id, Text: " \n ", AttachmentKind: "none"},
|
|
{Text: "hello", AttachmentKind: "none"},
|
|
{Id: id, Text: strings.Repeat("я", 4001), AttachmentKind: "none"},
|
|
{Id: id, Text: "hello", AttachmentKind: "url", AttachmentId: &id},
|
|
{Id: id, AttachmentKind: "playlist"},
|
|
{Id: id, Text: "hello", AttachmentKind: "none", AttachmentId: &id},
|
|
} {
|
|
require.Error(t, validateMessage(m))
|
|
}
|
|
require.NoError(t, validateMessage(gen.SendDirectMessage{Id: id, Text: strings.Repeat("я", 4000), AttachmentKind: "none"}))
|
|
require.NoError(t, validateMessage(gen.SendDirectMessage{Id: id, AttachmentKind: "track", AttachmentId: &id}))
|
|
}
|
|
func TestHandlersRequireIdentityAndRejectSelf(t *testing.T) {
|
|
h := &Handler{}
|
|
_, e := h.GetSocial(context.Background(), gen.GetSocialRequestObject{})
|
|
require.Error(t, e)
|
|
id := uuid.New()
|
|
ctx := auth.WithPrincipal(context.Background(), auth.Principal{UserID: id})
|
|
_, e = h.SocialAction(ctx, gen.SocialActionRequestObject{Body: &gen.SocialAction{Action: "request", TargetId: id}})
|
|
require.Error(t, e)
|
|
_, e = h.SendDirectMessage(ctx, gen.SendDirectMessageRequestObject{PeerId: id})
|
|
require.Error(t, e)
|
|
_, e = h.SearchPeople(ctx, gen.SearchPeopleRequestObject{Params: gen.SearchPeopleParams{Q: " "}})
|
|
require.Error(t, e)
|
|
}
|
|
|
|
func TestListeningAudienceAndReactionValidation(t *testing.T) {
|
|
require.False(t, audienceAllows("nobody", true))
|
|
require.False(t, audienceAllows("friends", false))
|
|
require.True(t, audienceAllows("friends", true))
|
|
require.True(t, audienceAllows("everyone", false))
|
|
require.False(t, audienceAllows("unexpected", true))
|
|
require.True(t, validEmoji("❤️"))
|
|
require.False(t, validEmoji("<script>"))
|
|
require.Error(t, validateActivity(gen.ListeningActivityInput{DeviceId: uuid.New(), Sequence: 1, Playing: true, Context: "wave"}))
|
|
}
|