2021-09-18 15:32:39 +02:00
|
|
|
package search
|
2021-09-02 16:12:31 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2021-09-18 15:32:39 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2021-09-02 16:12:31 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
func TestSubjects(t *testing.T) {
|
2021-09-02 16:12:31 +02:00
|
|
|
t.Run("FindAll", func(t *testing.T) {
|
2021-09-18 15:32:39 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson})
|
2021-09-02 16:12:31 +02:00
|
|
|
assert.NoError(t, err)
|
2021-09-17 18:51:24 +02:00
|
|
|
// t.Logf("Subjects: %#v", results)
|
2021-09-02 16:12:31 +02:00
|
|
|
assert.LessOrEqual(t, 3, len(results))
|
|
|
|
})
|
2021-09-20 13:12:28 +02:00
|
|
|
t.Run("Find 2 subjects, sort by count", func(t *testing.T) {
|
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Count: 2, Order: "count"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Greater(t, results[0].FileCount, results[1].FileCount)
|
|
|
|
assert.Equal(t, 2, len(results))
|
|
|
|
})
|
|
|
|
t.Run("FindAll sort by name", func(t *testing.T) {
|
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Order: "name"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "Actor A", results[0].SubjName)
|
|
|
|
assert.LessOrEqual(t, 3, len(results))
|
|
|
|
})
|
|
|
|
t.Run("sort by added", func(t *testing.T) {
|
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Order: "added"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "Jane Doe", results[0].SubjName)
|
|
|
|
assert.LessOrEqual(t, 3, len(results))
|
|
|
|
})
|
|
|
|
t.Run("sort by relevance", func(t *testing.T) {
|
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Order: "relevance"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "John Doe", results[0].SubjName)
|
|
|
|
assert.LessOrEqual(t, 3, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search favorite", func(t *testing.T) {
|
2021-10-06 15:27:17 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Favorite: "yes"})
|
2021-09-20 13:12:28 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "John Doe", results[0].SubjName)
|
|
|
|
assert.LessOrEqual(t, 1, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search private", func(t *testing.T) {
|
2021-10-06 15:27:17 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Private: "true"})
|
2021-09-20 13:12:28 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, 0, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search excluded", func(t *testing.T) {
|
2021-10-06 15:27:17 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Excluded: "ja"})
|
2021-09-20 13:12:28 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, 0, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search file count >2", func(t *testing.T) {
|
2021-10-22 16:03:50 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Files: 2, Excluded: "no"})
|
2021-09-20 13:12:28 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.LessOrEqual(t, 1, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search for alias", func(t *testing.T) {
|
2021-10-22 16:03:50 +02:00
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, Query: "Powell", Favorite: "no", Private: "no"})
|
2021-09-20 13:12:28 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "Dangling Subject", results[0].SubjName)
|
|
|
|
assert.LessOrEqual(t, 1, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search for ID", func(t *testing.T) {
|
|
|
|
results, err := Subjects(form.SubjectSearch{Type: entity.SubjPerson, ID: "jqy3y652h8njw0sx"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
assert.Equal(t, "Joe Biden", results[0].SubjName)
|
|
|
|
assert.Equal(t, 1, len(results))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubjectUIDs(t *testing.T) {
|
|
|
|
t.Run("search for alias", func(t *testing.T) {
|
|
|
|
results, _, _ := SubjectUIDs("Powell")
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
//t.Logf("Names: %#v", names)
|
|
|
|
assert.Equal(t, 1, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search for not existing name", func(t *testing.T) {
|
|
|
|
results, _, _ := SubjectUIDs("Anonymous")
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
//t.Logf("Names: %#v", names)
|
|
|
|
assert.Equal(t, 0, len(results))
|
|
|
|
})
|
|
|
|
t.Run("search with empty string", func(t *testing.T) {
|
|
|
|
results, _, _ := SubjectUIDs("")
|
|
|
|
//t.Logf("Subjects: %#v", results)
|
|
|
|
//t.Logf("Names: %#v", names)
|
|
|
|
assert.Equal(t, 0, len(results))
|
|
|
|
})
|
2021-09-02 16:12:31 +02:00
|
|
|
}
|