Tests: address changes from merge, fixture updates,

This commit is contained in:
Keith Martin 2025-12-03 00:01:22 +10:00
parent 075d400070
commit d0b68e5ce0
5 changed files with 82 additions and 29 deletions

View file

@ -88,7 +88,7 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(61), count)
assert.Equal(t, int64(75), count) // Count instances of LabelFixtures.PhotoLabel in photo_fixtures.go
})
t.Run("PhotoCounts", func(t *testing.T) {
@ -98,7 +98,7 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(59), count)
assert.Equal(t, int64(62), count) // Count instances of \tID: (regex search) in photo_fixtures.go
})
t.Run("AlbumCounts", func(t *testing.T) {
@ -138,7 +138,7 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(28), count)
assert.Equal(t, int64(34), count) // Count instances of PhotoUID: in photo_album_fixtures.go
})
t.Run("FolderCounts", func(t *testing.T) {
@ -158,7 +158,7 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(72), count)
assert.Equal(t, int64(76), count) // Count instances of \tID: (regex) in file_fixtures.go and subtract 1 for the fixture without a photoid.
})
t.Run("KeywordCounts", func(t *testing.T) {
@ -178,7 +178,7 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(35), count)
assert.Equal(t, int64(41), count) // hard to derive from code if people add entries via photo_fixtures.go
})
t.Run("CategoryCounts", func(t *testing.T) {
@ -308,6 +308,6 @@ func TestInit(t *testing.T) {
stmt.Model(m).Count(&count)
assert.Equal(t, int64(57), count)
assert.Equal(t, int64(60), count) // Count instances of Details: in photo_fixtures.go
})
}

View file

@ -95,7 +95,7 @@ func TestKeyword_Updates(t *testing.T) {
if err != nil {
assert.Error(t, err)
assert.ErrorContains(t, err, "id value required but not provided")
assert.ErrorContains(t, err, "keyword ID must not be empty - you may have found a bug")
} else {
assert.Fail(t, "error was expected but not set")
}
@ -128,7 +128,7 @@ func TestKeyword_Update(t *testing.T) {
err := keyword.Update("Keyword", "new-name")
assert.Error(t, err)
assert.ErrorContains(t, err, "id value required but not provided")
assert.ErrorContains(t, err, "keyword ID must not be empty - you may have found a bug")
})
}

View file

@ -119,10 +119,8 @@ var PhotoKeywordFixtures = PhotoKeywordMap{
PhotoID: 1000045,
KeywordID: 10000018,
},
"30": {
PhotoID: 1000045,
KeywordID: 10000018,
},
/* "30": { // Duplicate of 29.
}, */
"31": {
PhotoID: 1000036,
KeywordID: 10000015,
@ -131,6 +129,46 @@ var PhotoKeywordFixtures = PhotoKeywordMap{
PhotoID: 1000036,
KeywordID: 1000001,
},
"33": {
PhotoID: 1000059,
KeywordID: 1000000,
},
"34": {
PhotoID: 1000059,
KeywordID: 1000002,
},
"35": {
PhotoID: 1000057,
KeywordID: 1000000,
},
"36": {
PhotoID: 1000057,
KeywordID: 1000001,
},
"37": {
PhotoID: 1000052,
KeywordID: 10000025,
},
"38": {
PhotoID: 1000058,
KeywordID: 1000000,
},
"39": {
PhotoID: 1000058,
KeywordID: 1000001,
},
"40": {
PhotoID: 1000050,
KeywordID: 10000025,
},
"41": {
PhotoID: 1000004,
KeywordID: 1000002,
},
"42": {
PhotoID: 1000051,
KeywordID: 10000025,
},
}
// CreatePhotoKeywordFixtures inserts known entities into the database for testing.

View file

@ -33,7 +33,7 @@ func TestPhotosFilterKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 5)
assert.Len(t, photos, 8)
})
t.Run("BPipeKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -46,7 +46,7 @@ func TestPhotosFilterKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BWhitespacePipeWhitespaceKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -59,7 +59,7 @@ func TestPhotosFilterKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BOrKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -72,7 +72,7 @@ func TestPhotosFilterKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BOrKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -85,7 +85,7 @@ func TestPhotosFilterKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BAmpersandKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -536,7 +536,7 @@ func TestPhotosQueryKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 5)
assert.Len(t, photos, 8)
})
t.Run("BPipeKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -549,7 +549,7 @@ func TestPhotosQueryKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BWhitespacePipeWhitespaceKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -562,7 +562,7 @@ func TestPhotosQueryKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BOrKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -575,7 +575,7 @@ func TestPhotosQueryKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BOrKuh", func(t *testing.T) {
var f form.SearchPhotos
@ -588,7 +588,7 @@ func TestPhotosQueryKeywords(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 6)
assert.Len(t, photos, 9)
})
t.Run("BAmpersandKuh", func(t *testing.T) {
var f form.SearchPhotos

View file

@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
@ -21,13 +22,27 @@ func TestPhotosFilterLabel(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Len(t, photos, 3)
if len(photos) > 0 {
assert.Equal(t, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").ID, photos[0].ID)
assert.Equal(t, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").CameraID, photos[0].CameraID)
assert.Equal(t, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").CellID, photos[0].CellID)
assert.Equal(t, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").LensID, photos[0].LensID)
assert.Equal(t, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").PhotoCaption, photos[0].PhotoCaption)
require.Len(t, photos, 3)
for i := range len(photos) {
fixture := ""
switch photos[i].ID {
case entity.PhotoFixtures.Pointer("19800101_000002_D640C559").ID:
fixture = "19800101_000002_D640C559"
case entity.PhotoFixtures.Pointer("Photo56").ID:
fixture = "Photo56"
case entity.PhotoFixtures.Pointer("Photo57").ID:
fixture = "Photo57"
default:
assert.Len(t, photos, 0)
t.Logf("Unable to match id in expected photos %d against %d %d %d", photos[i].ID, entity.PhotoFixtures.Pointer("19800101_000002_D640C559").ID, entity.PhotoFixtures.Pointer("Photo56").ID, entity.PhotoFixtures.Pointer("Photo57").ID)
t.Fail()
}
assert.Equal(t, entity.PhotoFixtures.Pointer(fixture).ID, photos[i].ID)
assert.Equal(t, entity.PhotoFixtures.Pointer(fixture).CameraID, photos[i].CameraID)
assert.Equal(t, entity.PhotoFixtures.Pointer(fixture).CellID, photos[i].CellID)
assert.Equal(t, entity.PhotoFixtures.Pointer(fixture).LensID, photos[i].LensID)
assert.Equal(t, entity.PhotoFixtures.Pointer(fixture).PhotoCaption, photos[i].PhotoCaption)
}
})
t.Run("Cake", func(t *testing.T) {