Tests: Add unit tests
This commit is contained in:
parent
83d10ea00e
commit
19699c49c0
4 changed files with 137 additions and 0 deletions
|
@ -19,6 +19,18 @@ func TestSearchPhotosGeo(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "Jens Mander", form.Subjects)
|
||||
})
|
||||
t.Run("subject", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "subject:\"Jens\""}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Jens", form.Subject)
|
||||
assert.Equal(t, "", form.Person)
|
||||
})
|
||||
t.Run("id", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "id:\"ii3e4567-e89b-hdgtr\""}
|
||||
|
||||
|
@ -56,6 +68,32 @@ func TestSearchPhotosGeo(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "Foo Bar", form.Keywords)
|
||||
})
|
||||
t.Run("path", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "path:123abc/,EFG"}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
// log.Debugf("%+v\n", form)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "123abc/,EFG", form.Path)
|
||||
})
|
||||
t.Run("name", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "name:filename.jpg"}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
// log.Debugf("%+v\n", form)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "filename", form.Name)
|
||||
})
|
||||
t.Run("valid query", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "q:\"fooBar baz\" before:2019-01-15 dist:25000 lat:33.45343166666667"}
|
||||
|
||||
|
@ -90,6 +128,21 @@ func TestSearchPhotosGeo(t *testing.T) {
|
|||
assert.Equal(t, uint(0x61a8), form.Dist)
|
||||
assert.Equal(t, float32(33.45343), form.Lat)
|
||||
})
|
||||
t.Run("valid query with filter", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "keywords:cat title:\"fooBar baz\"", Filter: "keywords:dog"}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
// log.Debugf("%+v\n", form)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "dog", form.Keywords)
|
||||
assert.Equal(t, "keywords:dog", form.Filter)
|
||||
assert.Equal(t, "fooBar baz", form.Title)
|
||||
})
|
||||
t.Run("PortraitLandscapeSquare", func(t *testing.T) {
|
||||
form := &SearchPhotosGeo{Query: "portrait:true landscape:yes square:jo"}
|
||||
|
||||
|
@ -204,3 +257,16 @@ func TestNewSearchPhotosGeo(t *testing.T) {
|
|||
r := NewSearchPhotosGeo("Berlin")
|
||||
assert.IsType(t, SearchPhotosGeo{}, r)
|
||||
}
|
||||
|
||||
func TestSearchPhotosGeo_FindUidOnly(t *testing.T) {
|
||||
t.Run("true", func(t *testing.T) {
|
||||
f := &SearchPhotosGeo{UID: "priqwb43p5dh7777"}
|
||||
|
||||
assert.True(t, f.FindUidOnly())
|
||||
})
|
||||
t.Run("false", func(t *testing.T) {
|
||||
f := &SearchPhotosGeo{Query: "label:cat", UID: "priqwb43p5dh7777"}
|
||||
|
||||
assert.False(t, f.FindUidOnly())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -25,6 +25,18 @@ func TestParseQueryString(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "Jens & Mander", form.Subjects)
|
||||
})
|
||||
t.Run("subject", func(t *testing.T) {
|
||||
form := &SearchPhotos{Query: "subject:\"Jens\""}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Jens", form.Subject)
|
||||
assert.Equal(t, "", form.Person)
|
||||
})
|
||||
t.Run("aliases", func(t *testing.T) {
|
||||
form := &SearchPhotos{Query: "people:\"Jens & Mander\" folder:Foo person:Bar"}
|
||||
|
||||
|
@ -786,3 +798,16 @@ func TestSearchPhotos_Unserialize(t *testing.T) {
|
|||
assert.Equal(t, "ariqwb43p5dh5555", f.Album)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSearchPhotos_FindUidOnly(t *testing.T) {
|
||||
t.Run("true", func(t *testing.T) {
|
||||
f := &SearchPhotos{UID: "priqwb43p5dh7777"}
|
||||
|
||||
assert.True(t, f.FindUidOnly())
|
||||
})
|
||||
t.Run("false", func(t *testing.T) {
|
||||
f := &SearchPhotos{Query: "label:cat", UID: "priqwb43p5dh7777"}
|
||||
|
||||
assert.False(t, f.FindUidOnly())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,6 +6,17 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLogin_Email(t *testing.T) {
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
form := &Login{UserEmail: "", Password: "passwd", AuthToken: ""}
|
||||
assert.Equal(t, "", form.Email())
|
||||
})
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
form := &Login{UserEmail: "test@test.com", UserName: "John", Password: "passwd", AuthToken: "123"}
|
||||
assert.Equal(t, "test@test.com", form.Email())
|
||||
})
|
||||
}
|
||||
|
||||
func TestLogin_HasToken(t *testing.T) {
|
||||
t.Run("false", func(t *testing.T) {
|
||||
form := &Login{UserEmail: "test@test.com", UserName: "John", Password: "passwd", AuthToken: ""}
|
||||
|
|
|
@ -3,6 +3,8 @@ package form
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/authn"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -29,6 +31,17 @@ func TestUser_Username(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestUser_Provider(t *testing.T) {
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", AuthProvider: ""}
|
||||
assert.Equal(t, authn.ProviderDefault, form.Provider())
|
||||
})
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", AuthProvider: "local"}
|
||||
assert.Equal(t, authn.ProviderLocal, form.Provider())
|
||||
})
|
||||
}
|
||||
|
||||
func TestUser_Email(t *testing.T) {
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
form := &User{UserName: "foobar", UserEmail: "", Password: "passwd"}
|
||||
|
@ -43,3 +56,25 @@ func TestUser_Email(t *testing.T) {
|
|||
assert.Equal(t, "", form.Email())
|
||||
})
|
||||
}
|
||||
|
||||
func TestUser_Role(t *testing.T) {
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", UserRole: ""}
|
||||
assert.Equal(t, "", form.Role())
|
||||
})
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", UserRole: "admin"}
|
||||
assert.Equal(t, "admin", form.Role())
|
||||
})
|
||||
t.Run("Invalid", func(t *testing.T) {
|
||||
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", UserRole: "ad&*min"}
|
||||
assert.Equal(t, "admin", form.Role())
|
||||
})
|
||||
}
|
||||
|
||||
func TestUser_Attr(t *testing.T) {
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", UserAttr: ""}
|
||||
assert.Equal(t, "", form.Attr())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue