test: add result count assertions for ParadeDB search tests

Address review feedback: assert exact result counts when ParadeDB is
active. fuzzy(1, prefix=true) broadens matches via edit distance,
returning 6 projects for "TEST10", 14 tasks for "number #17", and
12 projects for "Test1".
This commit is contained in:
kolaente
2026-03-05 11:26:05 +01:00
parent b69705e64b
commit c7c63e8ead
3 changed files with 17 additions and 8 deletions

View File

@@ -533,9 +533,9 @@ func TestProject_ReadAll(t *testing.T) {
ls := projects3.([]*Project)
if db.ParadeDBAvailable() {
// ParadeDB fuzzy prefix matching returns more results
// (e.g. "TEST10" also matches "test1", "test11", etc.)
require.NotEmpty(t, ls)
// ParadeDB fuzzy(1, prefix=true) on "TEST10" also matches
// "test1", "test11", "test19", "test30" (edit distance 1), etc.
require.Len(t, ls, 6)
projectIDs := make([]int64, len(ls))
for i, p := range ls {
projectIDs[i] = p.ID

View File

@@ -1783,8 +1783,8 @@ func TestTaskCollection_ReadAll(t *testing.T) {
}
if db.ParadeDBAvailable() {
// ParadeDB fuzzy prefix matching returns more results than ILIKE,
// so we only check that expected tasks are contained in results.
// ParadeDB fuzzy(1, prefix=true) on "17" also matches tokens within
// edit distance 1 ("1", "7", "10"-"19", "27", "47"), returning more results.
t.Run("search for task index", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
@@ -1794,6 +1794,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
got, _, _, err := lt.ReadAll(s, &user.User{ID: 1}, "number #17", 0, 50)
require.NoError(t, err)
gotTasks := got.([]*Task)
require.Len(t, gotTasks, 14)
gotIDs := make([]int64, len(gotTasks))
for i, tsk := range gotTasks {
gotIDs[i] = tsk.ID

View File

@@ -17,6 +17,7 @@
package webtests
import (
"encoding/json"
"net/url"
"testing"
@@ -51,9 +52,16 @@ func TestProject(t *testing.T) {
rec, err := testHandler.testReadAllWithUser(url.Values{"s": []string{"Test1"}}, nil)
require.NoError(t, err)
assert.Contains(t, rec.Body.String(), `Test1`)
if !db.ParadeDBAvailable() {
// ParadeDB fuzzy(1, prefix=true) matches Test2, Test3, etc.
// (edit distance 1 from "Test1"), so only check exclusions without ParadeDB.
var projects []models.Project
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &projects))
if db.ParadeDBAvailable() {
// ParadeDB fuzzy(1, prefix=true) on "Test1" also matches
// Test2-Test9 (edit distance 1), Test10+ (prefix), etc.
require.Len(t, projects, 12)
} else {
require.Len(t, projects, 2)
assert.NotContains(t, rec.Body.String(), `Test2`)
assert.NotContains(t, rec.Body.String(), `Test3`)
assert.NotContains(t, rec.Body.String(), `Test4`)