From c0a2da8bab4c08acf061bbe3d5056de9b52a6fb1 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Wed, 13 May 2020 19:46:49 +0200 Subject: [PATCH] Backend: Add tests fixtures --- internal/entity/file_fixtures.go | 8 +++--- internal/entity/fixtures.go | 1 + internal/entity/lens_fixtures.go | 46 +++++++++++++++++++++++++++++++ internal/entity/photo_fixtures.go | 34 +++++++++++------------ 4 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 internal/entity/lens_fixtures.go diff --git a/internal/entity/file_fixtures.go b/internal/entity/file_fixtures.go index 0934199b4..6607f735d 100644 --- a/internal/entity/file_fixtures.go +++ b/internal/entity/file_fixtures.go @@ -22,11 +22,11 @@ var FileFixtures = map[string]File{ FileSidecar: false, FileVideo: false, FileMissing: false, - FileDuplicate: false, - FilePortrait: false, + FileDuplicate: true, + FilePortrait: true, FileWidth: 3648, FileHeight: 2736, - FileOrientation: 1, + FileOrientation: 0, FileAspectRatio: 1.33333, FileMainColor: "green", FileColors: "929299991", @@ -191,7 +191,7 @@ var FileFixtures = map[string]File{ FileColors: "266111000", FileLuminance: "DC42844C8", FileDiff: 800, - FileChroma: 26, + FileChroma: 4, FileNotes: "", FileError: "", Share: []FileShare{}, diff --git a/internal/entity/fixtures.go b/internal/entity/fixtures.go index 30b7d9646..af280e779 100644 --- a/internal/entity/fixtures.go +++ b/internal/entity/fixtures.go @@ -18,4 +18,5 @@ func CreateTestFixtures() { CreatePlaceFixtures() CreateFileShareFixtures() CreateFileSyncFixtures() + CreateLensFixtures() } diff --git a/internal/entity/lens_fixtures.go b/internal/entity/lens_fixtures.go new file mode 100644 index 000000000..b7be4c906 --- /dev/null +++ b/internal/entity/lens_fixtures.go @@ -0,0 +1,46 @@ +package entity + +import ( + "time" +) + +type LensMap map[string]Lens + +func (m LensMap) Get(name string) Lens { + if result, ok := m[name]; ok { + return result + } + + return *NewLens(name, "") +} + +func (m LensMap) Pointer(name string) *Lens { + if result, ok := m[name]; ok { + return &result + } + + return NewLens(name, "") +} + +var LensFixtures = LensMap{ + "lens-f-380": { + ID: 1000000, + LensSlug: "lens-f-380", + LensModel: "F380", + LensMake: "Apple", + LensType: "", + LensOwner: "Test", + LensDescription: "", + LensNotes: "Notes", + CreatedAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC), + UpdatedAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC), + DeletedAt: nil, + }, +} + +// CreateLensFixtures inserts known entities into the database for testing. +func CreateLensFixtures() { + for _, entity := range LensFixtures { + Db().Create(&entity) + } +} diff --git a/internal/entity/photo_fixtures.go b/internal/entity/photo_fixtures.go index 476e38e57..fc10a0a53 100644 --- a/internal/entity/photo_fixtures.go +++ b/internal/entity/photo_fixtures.go @@ -45,7 +45,7 @@ var PhotoFixtures = PhotoMap{ PhotoAltitude: 0, PhotoIso: 0, PhotoFocalLength: 0, - PhotoFNumber: 0, + PhotoFNumber: 5, PhotoExposure: "", CameraID: 0, CameraSerial: "", @@ -61,9 +61,9 @@ var PhotoFixtures = PhotoMap{ Description: DescriptionFixtures.Get("lake", 1000000), DescriptionSrc: "", Camera: CameraFixtures.Pointer("canon-eos-6d"), - Lens: nil, + Lens: LensFixtures.Pointer("lens-f-380"), Location: nil, - Place: nil, + Place: PlaceFixtures.Pointer("teotihuacan"), Links: []Link{}, Keywords: []Keyword{}, Albums: []Album{ @@ -115,7 +115,7 @@ var PhotoFixtures = PhotoMap{ Description: Description{}, DescriptionSrc: "", Camera: CameraFixtures.Pointer("canon-eos-6d"), - Lens: nil, + Lens: LensFixtures.Pointer("lens-f-380"), Location: nil, Place: nil, Links: []Link{}, @@ -164,7 +164,7 @@ var PhotoFixtures = PhotoMap{ Description: Description{}, DescriptionSrc: "", Camera: nil, - Lens: nil, + Lens: LensFixtures.Pointer("lens-f-380"), Location: nil, Place: nil, Links: []Link{}, @@ -264,10 +264,10 @@ var PhotoFixtures = PhotoMap{ PhotoMonth: 7, Description: Description{}, DescriptionSrc: "", - Camera: nil, - Lens: nil, - Location: nil, - Place: nil, + Camera: CameraFixtures.Pointer("canon-eos-6d"), + Lens: LensFixtures.Pointer("lens-f-380"), + Location: &LocationFixturesMexico, + Place: PlaceFixtures.Pointer("teotihuacan"), Links: []Link{}, Keywords: []Keyword{ KeywordFixtures.Get("bridge"), @@ -317,10 +317,10 @@ var PhotoFixtures = PhotoMap{ PhotoMonth: 7, Description: Description{}, DescriptionSrc: "", - Camera: nil, - Lens: nil, - Location: nil, - Place: nil, + Camera: CameraFixtures.Pointer("canon-eos-6d"), + Lens: LensFixtures.Pointer("lens-f-380"), + Location: &LocationFixturesMexico, + Place: PlaceFixtures.Pointer("teotihuacan"), Links: []Link{}, Keywords: []Keyword{}, Albums: []Album{}, @@ -905,10 +905,10 @@ var PhotoFixtures = PhotoMap{ PhotoMonth: 0, Description: DescriptionFixtures.Get("lake", 1000015), DescriptionSrc: "location", - Camera: nil, - Lens: nil, - Location: nil, - Place: nil, + Camera: CameraFixtures.Pointer("canon-eos-6d"), + Lens: LensFixtures.Pointer("lens-f-380"), + Location: &LocationFixturesMexico, + Place: PlaceFixtures.Pointer("teotihuacan"), Links: []Link{}, Keywords: []Keyword{}, Albums: []Album{},