Files
pipu-music/services/api/internal/search/translit_test.go
T
mrleo1nidandClaude Opus 5.5 fbbe5d7528
ci / api / api (push) Successful in 18s
ci / db / db (push) Successful in 30s
feat(search): personalize suggestions by listening history (M6)
Suggest fetches three times as many candidates and reranks them in the API:
what the user plays, finishes and likes moves up a few positions and what they
dislike moves down, with Meilisearch relevance still the base order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 22:55:07 +03:00

36 lines
1.2 KiB
Go

package search
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestTranslit(t *testing.T) {
assert.Equal(t, "kino", Translit("Кино"))
assert.Equal(t, "shchedrin", Translit("Щедрин"))
assert.Equal(t, "кино", Translit("Kino"))
assert.Equal(t, "щедрин", Translit("shchedrin"))
assert.Equal(t, "", Translit("1984"))
}
func TestSwitchLayout(t *testing.T) {
assert.Equal(t, "привет", SwitchLayout("ghbdtn"))
assert.Equal(t, "hello", SwitchLayout("руддщ"))
assert.Equal(t, "кино", SwitchLayout("rbyj"))
assert.Equal(t, "", SwitchLayout("123"))
}
func TestPersonalizeLiftsFamiliarAndSinksDisliked(t *testing.T) {
liked, disliked := uuid.New(), uuid.New()
other := []string{uuid.NewString(), uuid.NewString(), uuid.NewString()}
found := []string{other[0], disliked.String(), other[1], other[2], liked.String()}
aff := map[uuid.UUID]float64{liked: 30, disliked: -10}
got := personalize(found, aff, 3)
assert.Equal(t, []string{liked.String(), other[0], other[1]}, got)
assert.Equal(t, found[:2], personalize(found, nil, 2), "без вкуса — порядок релевантности")
}