Backend: Add unit tests for internal/query

This commit is contained in:
Theresa Gresch 2020-07-13 11:11:52 +02:00
parent f18ac917ab
commit b21433479e
4 changed files with 111 additions and 2 deletions

View file

@ -105,6 +105,25 @@ var AlbumFixtures = AlbumMap{
UpdatedAt: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC),
DeletedAt: nil,
},
"emptyMoment": {
ID: 1000005,
CoverUID: "",
AlbumUID: "at7axuzitogaaiax",
AlbumSlug: "empty-moment",
AlbumType: AlbumMoment,
AlbumTitle: "Empty Moment",
AlbumCategory: "Fun",
AlbumLocation: "Favorite Park",
AlbumDescription: "",
AlbumNotes: "",
AlbumOrder: "name",
AlbumTemplate: "",
AlbumFilter: "",
AlbumFavorite: false,
CreatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
UpdatedAt: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC),
DeletedAt: nil,
},
}
// CreateAlbumFixtures inserts known entities into the database for testing.

View file

@ -81,6 +81,17 @@ func TestMediaFile_Exif_JPEG(t *testing.T) {
t.Logf("UTC: %s", info.TakenAt.String())
t.Logf("Local: %s", info.TakenAtLocal.String())
})
t.Run("blue-go-video.mp4", func(t *testing.T) {
img, err := NewMediaFile(conf.ExamplesPath() + "/blue-go-video.mp4")
assert.Nil(t, err)
info := img.MetaData()
assert.Empty(t, err)
assert.IsType(t, meta.Data{}, info)
})
}
func TestMediaFile_Exif_DNG(t *testing.T) {

View file

@ -53,6 +53,28 @@ func TestAccounts(t *testing.T) {
assert.LessOrEqual(t, 1, len(r))
for _, r := range r {
assert.IsType(t, entity.Account{}, r)
}
})
t.Run("find accounts count > max results", func(t *testing.T) {
f := form.AccountSearch{
Query: "",
Status: "test",
Count: 100000,
Offset: 0,
Order: "",
}
r, err := AccountSearch(f)
if err != nil {
t.Fatal(err)
}
//t.Logf("accounts: %+v", r)
assert.LessOrEqual(t, 1, len(r))
for _, r := range r {
assert.IsType(t, entity.Account{}, r)
}

View file

@ -26,8 +26,8 @@ func TestAlbumByUID(t *testing.T) {
})
}
func TestAlbumThumbByUID(t *testing.T) {
t.Run("existing uid", func(t *testing.T) {
func TestAlbumCoverByUID(t *testing.T) {
t.Run("existing uid default album", func(t *testing.T) {
file, err := AlbumCoverByUID("at9lxuqxpogaaba8")
if err != nil {
@ -37,6 +37,24 @@ func TestAlbumThumbByUID(t *testing.T) {
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("existing uid folder album", func(t *testing.T) {
file, err := AlbumCoverByUID("at1lxuqipogaaba1")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "bridge2.jpg", file.FileName)
})
t.Run("existing uid empty moment album", func(t *testing.T) {
file, err := AlbumCoverByUID("at7axuzitogaaiax")
assert.Equal(t, "found no cover for moment", err.Error())
assert.Equal(t, "", file.FileName)
})
t.Run("not existing uid", func(t *testing.T) {
file, err := AlbumCoverByUID("3765")
assert.Error(t, err, "record not found")
@ -138,4 +156,43 @@ func TestAlbumSearch(t *testing.T) {
assert.Equal(t, 1, len(result))
assert.Equal(t, "christmas2030", result[0].AlbumSlug)
})
t.Run("search with multiple filters", func(t *testing.T) {
f := form.AlbumSearch{
Query: "",
Type: "moment",
Category: "Fun",
Location: "Favorite Park",
Title: "Empty Moment",
Count: 0,
Offset: 0,
Order: "",
}
result, err := AlbumSearch(f)
if err != nil {
t.Fatal(err)
}
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) {
f := form.AlbumSearch{
Year: 100,
Month: 100,
Day: 100,
Count: 0,
Offset: 0,
Order: "",
}
result, err := AlbumSearch(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 0, len(result))
})
}