Backend: Add tests to internal/entity
This commit is contained in:
parent
c0c0c96c30
commit
a136945470
5 changed files with 157 additions and 8 deletions
26
internal/entity/file_share_test.go
Normal file
26
internal/entity/file_share_test.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileShare_TableName(t *testing.T) {
|
||||
fileShare := &FileShare{}
|
||||
assert.Equal(t, "files_share", fileShare.TableName())
|
||||
}
|
||||
|
||||
func TestNewFileShare(t *testing.T) {
|
||||
r := NewFileShare(123, 123, "test")
|
||||
assert.IsType(t, &FileShare{}, r)
|
||||
assert.Equal(t, uint(0x7b), r.FileID)
|
||||
assert.Equal(t, uint(0x7b), r.AccountID)
|
||||
assert.Equal(t, "test", r.RemoteName)
|
||||
assert.Equal(t, "new", r.Status)
|
||||
}
|
||||
|
||||
func TestFileShare_FirstOrCreate(t *testing.T) {
|
||||
fileShare := &FileShare{FileID: 123}
|
||||
r := fileShare.FirstOrCreate()
|
||||
assert.Equal(t, uint(0x7b), r.FileID)
|
||||
}
|
25
internal/entity/file_sync_test.go
Normal file
25
internal/entity/file_sync_test.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileSync_TableName(t *testing.T) {
|
||||
fileSync := &FileSync{}
|
||||
assert.Equal(t, "files_sync", fileSync.TableName())
|
||||
}
|
||||
|
||||
func TestNewFileSync(t *testing.T) {
|
||||
r := NewFileSync(123, "test")
|
||||
assert.IsType(t, &FileSync{}, r)
|
||||
assert.Equal(t, uint(0x7b), r.AccountID)
|
||||
assert.Equal(t, "test", r.RemoteName)
|
||||
assert.Equal(t, "new", r.Status)
|
||||
}
|
||||
|
||||
func TestFileSync_FirstOrCreate(t *testing.T) {
|
||||
fileSync := &FileSync{AccountID: 123}
|
||||
r := fileSync.FirstOrCreate()
|
||||
assert.Equal(t, uint(0x7b), r.AccountID)
|
||||
}
|
|
@ -67,3 +67,10 @@ func TestFile_Changed(t *testing.T) {
|
|||
assert.Equal(t, false, file.Changed(500, time))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFile_Purge(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
file := &File{Photo: nil, FileType: "jpg", FileSize: 500}
|
||||
assert.Equal(t, nil, file.Purge())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -18,3 +18,9 @@ func TestNewKeyword(t *testing.T) {
|
|||
assert.Equal(t, false, keyword.Skip)
|
||||
})
|
||||
}
|
||||
|
||||
func TestKeyword_FirstOrCreate(t *testing.T) {
|
||||
keyword := NewKeyword("food")
|
||||
r := keyword.FirstOrCreate()
|
||||
assert.Equal(t, "food", r.Keyword)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/internal/classify"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -22,15 +23,99 @@ func TestNewLabel(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLabel_SetName(t *testing.T) {
|
||||
entity := LabelFixtures["landscape"]
|
||||
t.Run("set name", func(t *testing.T) {
|
||||
entity := LabelFixtures["landscape"]
|
||||
|
||||
assert.Equal(t, "Landscape", entity.LabelName)
|
||||
assert.Equal(t, "landscape", entity.LabelSlug)
|
||||
assert.Equal(t, "landscape", entity.CustomSlug)
|
||||
assert.Equal(t, "Landscape", entity.LabelName)
|
||||
assert.Equal(t, "landscape", entity.LabelSlug)
|
||||
assert.Equal(t, "landscape", entity.CustomSlug)
|
||||
|
||||
entity.SetName("Landschaft")
|
||||
entity.SetName("Landschaft")
|
||||
|
||||
assert.Equal(t, "Landschaft", entity.LabelName)
|
||||
assert.Equal(t, "landscape", entity.LabelSlug)
|
||||
assert.Equal(t, "landschaft", entity.CustomSlug)
|
||||
assert.Equal(t, "Landschaft", entity.LabelName)
|
||||
assert.Equal(t, "landscape", entity.LabelSlug)
|
||||
assert.Equal(t, "landschaft", entity.CustomSlug)
|
||||
})
|
||||
|
||||
t.Run("new name empty", func(t *testing.T) {
|
||||
entity := LabelFixtures["flower"]
|
||||
|
||||
assert.Equal(t, "Flower", entity.LabelName)
|
||||
assert.Equal(t, "flower", entity.LabelSlug)
|
||||
assert.Equal(t, "flower", entity.CustomSlug)
|
||||
|
||||
entity.SetName("")
|
||||
|
||||
assert.Equal(t, "Flower", entity.LabelName)
|
||||
assert.Equal(t, "flower", entity.LabelSlug)
|
||||
assert.Equal(t, "flower", entity.CustomSlug)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLabel_FirstOrCreate(t *testing.T) {
|
||||
r := LabelFixtureFlower.FirstOrCreate()
|
||||
assert.Equal(t, "Flower", r.LabelName)
|
||||
assert.Equal(t, "flower", r.LabelSlug)
|
||||
}
|
||||
|
||||
func TestLabel_Update(t *testing.T) {
|
||||
t.Run("update priority and label slug", func(t *testing.T) {
|
||||
classifyLabel := &classify.Label{Name: "classify", Uncertainty: 30, Source: "manual", Priority: 5}
|
||||
Label := &Label{LabelName: "label", LabelSlug: "", CustomSlug: "customslug", LabelPriority: 4}
|
||||
|
||||
assert.Equal(t, 4, Label.LabelPriority)
|
||||
assert.Equal(t, "", Label.LabelSlug)
|
||||
assert.Equal(t, "customslug", Label.CustomSlug)
|
||||
assert.Equal(t, "label", Label.LabelName)
|
||||
|
||||
err := Label.Update(*classifyLabel)
|
||||
if err != nil {
|
||||
t.Fatal("error")
|
||||
}
|
||||
|
||||
assert.Equal(t, 5, Label.LabelPriority)
|
||||
assert.Equal(t, "customslug", Label.LabelSlug)
|
||||
assert.Equal(t, "classify", Label.CustomSlug)
|
||||
assert.Equal(t, "Classify", Label.LabelName)
|
||||
})
|
||||
t.Run("update custom slug", func(t *testing.T) {
|
||||
classifyLabel := &classify.Label{Name: "classify", Uncertainty: 30, Source: "manual", Priority: 5}
|
||||
Label := &Label{LabelName: "label12", LabelSlug: "labelslug", CustomSlug: "", LabelPriority: 5}
|
||||
|
||||
assert.Equal(t, 5, Label.LabelPriority)
|
||||
assert.Equal(t, "labelslug", Label.LabelSlug)
|
||||
assert.Equal(t, "", Label.CustomSlug)
|
||||
assert.Equal(t, "label12", Label.LabelName)
|
||||
|
||||
err := Label.Update(*classifyLabel)
|
||||
if err != nil {
|
||||
t.Fatal("error")
|
||||
}
|
||||
|
||||
assert.Equal(t, 5, Label.LabelPriority)
|
||||
assert.Equal(t, "labelslug", Label.LabelSlug)
|
||||
assert.Equal(t, "classify", Label.CustomSlug)
|
||||
assert.Equal(t, "Classify", Label.LabelName)
|
||||
|
||||
})
|
||||
t.Run("update name and Categories", func(t *testing.T) {
|
||||
classifyLabel := &classify.Label{Name: "classify", Uncertainty: 30, Source: "manual", Priority: 5}
|
||||
Label := &Label{LabelName: "label34", LabelSlug: "labelslug2", CustomSlug: "labelslug2", LabelPriority: 5, LabelCategories: []*Label{&LabelFixtureFlower}}
|
||||
|
||||
assert.Equal(t, 5, Label.LabelPriority)
|
||||
assert.Equal(t, "labelslug2", Label.LabelSlug)
|
||||
assert.Equal(t, "labelslug2", Label.CustomSlug)
|
||||
assert.Equal(t, "label34", Label.LabelName)
|
||||
|
||||
err := Label.Update(*classifyLabel)
|
||||
if err != nil {
|
||||
t.Fatal("error")
|
||||
}
|
||||
|
||||
assert.Equal(t, 5, Label.LabelPriority)
|
||||
assert.Equal(t, "labelslug2", Label.LabelSlug)
|
||||
assert.Equal(t, "classify", Label.CustomSlug)
|
||||
assert.Equal(t, "Classify", Label.LabelName)
|
||||
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue