Backend: Add unit tests for internal/query

This commit is contained in:
Theresa Gresch 2020-07-13 11:40:49 +02:00
parent b21433479e
commit f71dd8359f
4 changed files with 83 additions and 4 deletions

View file

@ -177,11 +177,11 @@ func TestAlbumSearch(t *testing.T) {
assert.Equal(t, 1, len(result))
assert.Equal(t, "Empty Moment", result[0].AlbumTitle)
})
t.Run("search for unknown year/month/day", func(t *testing.T) {
t.Run("search for year/month/day", func(t *testing.T) {
f := form.AlbumSearch{
Year: 100,
Month: 100,
Day: 100,
Year: 2021,
Month: 10,
Day: 3,
Count: 0,
Offset: 0,
Order: "",

View file

@ -0,0 +1,17 @@
package query
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCounts_Refresh(t *testing.T) {
counts := Counts{Cameras: 0, Photos: 0}
assert.Equal(t, counts.Cameras, 0)
assert.Equal(t, counts.Photos, 0)
counts.Refresh()
assert.Greater(t, counts.Cameras, 0)
assert.Greater(t, counts.Photos, 0)
assert.Greater(t, counts.Albums, 0)
}

View file

@ -0,0 +1,14 @@
package query
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestErrors(t *testing.T) {
errors, err := Errors(1000, 0, "notexistingErrorString")
if err != nil {
t.Fatal(err)
}
assert.Empty(t, errors)
}

View file

@ -17,6 +17,17 @@ func TestFilesByPath(t *testing.T) {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(files))
})
t.Run("files found - path starting with /", func(t *testing.T) {
files, err := FilesByPath(10, 0, entity.RootOriginals, "/2016/11")
t.Logf("files: %+v", files)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(files))
})
}
@ -32,6 +43,16 @@ func TestExistingFiles(t *testing.T) {
}
assert.LessOrEqual(t, 5, len(files))
})
t.Run("files found - includeMissing false", func(t *testing.T) {
files, err := Files(1000, 0, "/", false)
t.Logf("files: %+v", files)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 5, len(files))
})
t.Run("search for files path", func(t *testing.T) {
files, err := Files(1000, 0, "Photos", true)
@ -83,6 +104,24 @@ func TestFileByPhotoUID(t *testing.T) {
})
}
func TestVideoByPhotoUID(t *testing.T) {
t.Run("files found", func(t *testing.T) {
file, err := VideoByPhotoUID("pt9jtdre2lvl0yh0")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "bridge.mp4", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := VideoByPhotoUID("111")
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestFileByUID(t *testing.T) {
t.Run("files found", func(t *testing.T) {
file, err := FileByUID("ft8es39w45bnlqdw")
@ -135,3 +174,12 @@ func TestSetPhotoPrimary(t *testing.T) {
//TODO How to assert
//assert.Equal(t, true, entity.FileFixturesExampleXMP.FilePrimary)
}
func TestSetFileError(t *testing.T) {
assert.Equal(t, "", entity.FileFixturesExampleXMP.FileError)
SetFileError("ft2es49whhbnlqdn", "errorFromTest")
//TODO How to assert
//assert.Equal(t, true, entity.FileFixturesExampleXMP.FilePrimary)
}