photoprism/internal/form/search_accounts_test.go
Michael Mayer d8e0364dbb Search: Ignore public album filter if "Private" feat is disabled #2570
This needs to be very well tested and discussed, as these changes can
lead to private photos being accidentally published. Thank you!

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-08-01 15:57:19 +02:00

84 lines
1.8 KiB
Go

package form
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAccountSearchForm(t *testing.T) {
form := &SearchAccounts{}
assert.IsType(t, new(SearchAccounts), form)
}
func TestAccountSearch_GetQuery(t *testing.T) {
form := &SearchAccounts{Query: "q: webdav, share:true, sync:false, status:test"}
r := form.GetQuery()
assert.Equal(t, "q: webdav, share:true, sync:false, status:test", r)
}
func TestAccountSearch_SetQuery(t *testing.T) {
form := &SearchAccounts{}
assert.Equal(t, "", form.GetQuery())
form.SetQuery("query test")
assert.Equal(t, "query test", form.GetQuery())
}
func TestAccountSearch_ParseQueryString(t *testing.T) {
t.Run("valid query", func(t *testing.T) {
form := &SearchAccounts{Query: "q: webdäv share:true sync:false status:test"}
err := form.ParseQueryString()
if err != nil {
t.FailNow()
}
// log.Debugf("%+v\n", form)
assert.Equal(t, "webdäv", form.Query)
assert.Equal(t, true, form.Share)
assert.Equal(t, false, form.Sync)
assert.Equal(t, 0, form.Count)
})
t.Run("query for invalid filter", func(t *testing.T) {
form := &SearchAccounts{Query: "xxx:false"}
err := form.ParseQueryString()
if err == nil {
t.FailNow()
}
// log.Debugf("%+v\n", form)
assert.Equal(t, "unknown filter: xxx", err.Error())
})
t.Run("query for sync with uncommon bool value", func(t *testing.T) {
form := &SearchAccounts{Query: "sync:cat"}
err := form.ParseQueryString()
if err != nil {
t.Fatal("err should be nil")
}
assert.True(t, form.Sync)
})
t.Run("query for count with invalid type", func(t *testing.T) {
form := &SearchAlbums{Query: "count:cat"}
err := form.ParseQueryString()
assert.Error(t, err)
})
}
func TestNewAccountSearch(t *testing.T) {
r := NewAccountSearch("holiday")
assert.IsType(t, SearchAccounts{}, r)
}