photoprism/internal/search/subjects_test.go

108 lines
3.9 KiB
Go
Raw Normal View History

package search
2021-09-02 16:12:31 +02:00
import (
"testing"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
2021-09-02 16:12:31 +02:00
"github.com/stretchr/testify/assert"
)
func TestSubjects(t *testing.T) {
2021-09-02 16:12:31 +02:00
t.Run("FindAll", func(t *testing.T) {
results, err := Subjects(form.SearchSubjects{Type: entity.SubjPerson})
2021-09-02 16:12:31 +02:00
assert.NoError(t, err)
// 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.SearchSubjects{Type: entity.SubjPerson, Count: 2, Order: "count"})
2021-09-20 13:12:28 +02:00
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.SearchSubjects{Type: entity.SubjPerson, Order: "name"})
2021-09-20 13:12:28 +02:00
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.SearchSubjects{Type: entity.SubjPerson, Order: "added"})
2021-09-20 13:12:28 +02:00
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.SearchSubjects{Type: entity.SubjPerson, Order: "relevance"})
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, 3, len(results))
})
t.Run("search favorite", func(t *testing.T) {
results, err := Subjects(form.SearchSubjects{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) {
results, err := Subjects(form.SearchSubjects{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) {
results, err := Subjects(form.SearchSubjects{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) {
results, err := Subjects(form.SearchSubjects{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) {
results, err := Subjects(form.SearchSubjects{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.SearchSubjects{Type: entity.SubjPerson, UID: "js6sg6b2h8njw0sx"})
2021-09-20 13:12:28 +02:00
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
}