Backend: Add tests to internal/query
This commit is contained in:
parent
bd3426ae51
commit
a123726d28
267
internal/query/photo_results_test.go
Normal file
267
internal/query/photo_results_test.go
Normal file
|
@ -0,0 +1,267 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPhotosResults_Merged(t *testing.T) {
|
||||
|
||||
result1 := PhotosResult{
|
||||
ID: 111111,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
DeletedAt: time.Time{},
|
||||
TakenAt: time.Time{},
|
||||
TakenAtLocal: time.Time{},
|
||||
TakenSrc: "",
|
||||
TimeZone: "",
|
||||
PhotoUUID: "",
|
||||
PhotoPath: "",
|
||||
PhotoName: "",
|
||||
PhotoTitle: "Photo1",
|
||||
PhotoYear: 0,
|
||||
PhotoMonth: 0,
|
||||
PhotoCountry: "",
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoIso: 0,
|
||||
PhotoFocalLength: 0,
|
||||
PhotoFNumber: 0,
|
||||
PhotoExposure: "",
|
||||
PhotoQuality: 0,
|
||||
PhotoResolution: 0,
|
||||
Merged: false,
|
||||
CameraID: 0,
|
||||
CameraModel: "",
|
||||
CameraMake: "",
|
||||
LensID: 0,
|
||||
LensModel: "",
|
||||
LensMake: "",
|
||||
LocationID: "",
|
||||
PlaceID: "",
|
||||
LocLabel: "",
|
||||
LocCity: "",
|
||||
LocState: "",
|
||||
LocCountry: "",
|
||||
FileID: 0,
|
||||
FileUUID: "",
|
||||
FilePrimary: false,
|
||||
FileMissing: false,
|
||||
FileName: "",
|
||||
FileHash: "",
|
||||
FileType: "",
|
||||
FileMime: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
FileOrientation: 0,
|
||||
FileAspectRatio: 0,
|
||||
FileColors: "",
|
||||
FileChroma: 0,
|
||||
FileLuminance: "",
|
||||
FileDiff: 0,
|
||||
Files: nil,
|
||||
}
|
||||
|
||||
result2 := PhotosResult{
|
||||
ID: 22222,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
DeletedAt: time.Time{},
|
||||
TakenAt: time.Time{},
|
||||
TakenAtLocal: time.Time{},
|
||||
TakenSrc: "",
|
||||
TimeZone: "",
|
||||
PhotoUUID: "",
|
||||
PhotoPath: "",
|
||||
PhotoName: "",
|
||||
PhotoTitle: "Photo2",
|
||||
PhotoYear: 0,
|
||||
PhotoMonth: 0,
|
||||
PhotoCountry: "",
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoIso: 0,
|
||||
PhotoFocalLength: 0,
|
||||
PhotoFNumber: 0,
|
||||
PhotoExposure: "",
|
||||
PhotoQuality: 0,
|
||||
PhotoResolution: 0,
|
||||
Merged: false,
|
||||
CameraID: 0,
|
||||
CameraModel: "",
|
||||
CameraMake: "",
|
||||
LensID: 0,
|
||||
LensModel: "",
|
||||
LensMake: "",
|
||||
LocationID: "",
|
||||
PlaceID: "",
|
||||
LocLabel: "",
|
||||
LocCity: "",
|
||||
LocState: "",
|
||||
LocCountry: "",
|
||||
FileID: 0,
|
||||
FileUUID: "",
|
||||
FilePrimary: false,
|
||||
FileMissing: false,
|
||||
FileName: "",
|
||||
FileHash: "",
|
||||
FileType: "",
|
||||
FileMime: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
FileOrientation: 0,
|
||||
FileAspectRatio: 0,
|
||||
FileColors: "",
|
||||
FileChroma: 0,
|
||||
FileLuminance: "",
|
||||
FileDiff: 0,
|
||||
Files: nil,
|
||||
}
|
||||
|
||||
results := PhotosResults{result1, result2}
|
||||
|
||||
merged, int, err := results.Merged()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, 2, int)
|
||||
t.Log(merged)
|
||||
}
|
||||
|
||||
func TestPhotosResult_ShareFileName(t *testing.T) {
|
||||
t.Run("with photo title", func(t *testing.T) {
|
||||
result1 := PhotosResult{
|
||||
ID: 111111,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
DeletedAt: time.Time{},
|
||||
TakenAt: time.Date(2015, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||
TakenAtLocal: time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||
TakenSrc: "",
|
||||
TimeZone: "",
|
||||
PhotoUUID: "uuid123",
|
||||
PhotoPath: "",
|
||||
PhotoName: "",
|
||||
PhotoTitle: "PhotoTitle123",
|
||||
PhotoYear: 0,
|
||||
PhotoMonth: 0,
|
||||
PhotoCountry: "",
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoIso: 0,
|
||||
PhotoFocalLength: 0,
|
||||
PhotoFNumber: 0,
|
||||
PhotoExposure: "",
|
||||
PhotoQuality: 0,
|
||||
PhotoResolution: 0,
|
||||
Merged: false,
|
||||
CameraID: 0,
|
||||
CameraModel: "",
|
||||
CameraMake: "",
|
||||
LensID: 0,
|
||||
LensModel: "",
|
||||
LensMake: "",
|
||||
LocationID: "",
|
||||
PlaceID: "",
|
||||
LocLabel: "",
|
||||
LocCity: "",
|
||||
LocState: "",
|
||||
LocCountry: "",
|
||||
FileID: 0,
|
||||
FileUUID: "",
|
||||
FilePrimary: false,
|
||||
FileMissing: false,
|
||||
FileName: "",
|
||||
FileHash: "",
|
||||
FileType: "",
|
||||
FileMime: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
FileOrientation: 0,
|
||||
FileAspectRatio: 0,
|
||||
FileColors: "",
|
||||
FileChroma: 0,
|
||||
FileLuminance: "",
|
||||
FileDiff: 0,
|
||||
Files: nil,
|
||||
}
|
||||
|
||||
r := result1.ShareFileName()
|
||||
assert.Contains(t, r, "20131111-090718-Phototitle123")
|
||||
})
|
||||
t.Run("without photo title", func(t *testing.T) {
|
||||
result1 := PhotosResult{
|
||||
ID: 111111,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
DeletedAt: time.Time{},
|
||||
TakenAt: time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||
TakenAtLocal: time.Date(2015, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||
TakenSrc: "",
|
||||
TimeZone: "",
|
||||
PhotoUUID: "uuid123",
|
||||
PhotoPath: "",
|
||||
PhotoName: "",
|
||||
PhotoTitle: "",
|
||||
PhotoYear: 0,
|
||||
PhotoMonth: 0,
|
||||
PhotoCountry: "",
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoIso: 0,
|
||||
PhotoFocalLength: 0,
|
||||
PhotoFNumber: 0,
|
||||
PhotoExposure: "",
|
||||
PhotoQuality: 0,
|
||||
PhotoResolution: 0,
|
||||
Merged: false,
|
||||
CameraID: 0,
|
||||
CameraModel: "",
|
||||
CameraMake: "",
|
||||
LensID: 0,
|
||||
LensModel: "",
|
||||
LensMake: "",
|
||||
LocationID: "",
|
||||
PlaceID: "",
|
||||
LocLabel: "",
|
||||
LocCity: "",
|
||||
LocState: "",
|
||||
LocCountry: "",
|
||||
FileID: 0,
|
||||
FileUUID: "",
|
||||
FilePrimary: false,
|
||||
FileMissing: false,
|
||||
FileName: "",
|
||||
FileHash: "",
|
||||
FileType: "",
|
||||
FileMime: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
FileOrientation: 0,
|
||||
FileAspectRatio: 0,
|
||||
FileColors: "",
|
||||
FileChroma: 0,
|
||||
FileLuminance: "",
|
||||
FileDiff: 0,
|
||||
Files: nil,
|
||||
}
|
||||
|
||||
r := result1.ShareFileName()
|
||||
assert.Contains(t, r, "20151111-090718-uuid123")
|
||||
})
|
||||
}
|
30
internal/query/selection_test.go
Normal file
30
internal/query/selection_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPhotoSelection(t *testing.T) {
|
||||
t.Run("no photos selected", func(t *testing.T) {
|
||||
f := form.Selection{
|
||||
Photos: []string{},
|
||||
}
|
||||
r, err := PhotoSelection(f)
|
||||
assert.Equal(t, "no photos selected", err.Error())
|
||||
assert.Empty(t, r)
|
||||
})
|
||||
t.Run("photos selected", func(t *testing.T) {
|
||||
f := form.Selection{
|
||||
Photos: []string{"pt9jtdre2lvl0yh7", "pt9jtdre2lvl0yh8"},
|
||||
}
|
||||
r, err := PhotoSelection(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, 2, len(r))
|
||||
assert.IsType(t, []entity.Photo{}, r)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue