65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package db
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func TestMultiFieldSearchLogic(t *testing.T) {
|
|
// Test the logic without requiring database initialization
|
|
fields := []string{"title", "description"}
|
|
search := "test"
|
|
|
|
// Test with ParadeDB enabled
|
|
originalParadeDB := paradedbInstalled
|
|
paradedbInstalled = true
|
|
defer func() { paradedbInstalled = originalParadeDB }()
|
|
|
|
// We'll test the logic by checking if the right type of condition is created
|
|
// without relying on the Type() function that requires DB initialization
|
|
|
|
// Create conditions manually for each database type
|
|
conditions := make([]builder.Cond, len(fields))
|
|
for i, field := range fields {
|
|
conditions[i] = &builder.Like{field, "%" + search + "%"}
|
|
}
|
|
fallbackCond := builder.Or(conditions...)
|
|
|
|
// Test ParadeDB query string generation
|
|
fieldQueries := make([]string, len(fields))
|
|
for i, field := range fields {
|
|
fieldQueries[i] = field + ":" + search
|
|
}
|
|
expectedParadeDBQuery := "title:test OR description:test"
|
|
actualQuery := fieldQueries[0] + " OR " + fieldQueries[1]
|
|
|
|
if actualQuery != expectedParadeDBQuery {
|
|
t.Errorf("Expected ParadeDB query '%s', got '%s'", expectedParadeDBQuery, actualQuery)
|
|
}
|
|
|
|
// Test that fallback condition is created correctly
|
|
if fallbackCond == nil {
|
|
t.Fatal("Expected non-nil fallback condition")
|
|
}
|
|
|
|
t.Logf("ParadeDB query would be: %s", expectedParadeDBQuery)
|
|
t.Logf("Fallback condition created successfully")
|
|
}
|