Backend: Add unit tests

This commit is contained in:
Theresa Gresch 2020-10-20 10:07:27 +02:00
parent 7b9f21207e
commit c72ddbedcb
6 changed files with 65 additions and 26 deletions

View file

@ -260,16 +260,6 @@ func TestFile_Panorama(t *testing.T) {
})
}
/*func TestFile_PrimaryFile(t *testing.T) {
t.Run("return primary file", func(t *testing.T) {
file, err := PrimaryFile("pt9jtdre2lvl0y11")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "ft8es39w45bnlqdw", file.FileUID)
})
}*/
func TestFile_Delete(t *testing.T) {
t.Run("permanently", func(t *testing.T) {
file := &File{FileType: "jpg", FileSize: 500, FileName: "ToBePermanentlyDeleted", FileRoot: "", PhotoID: 5678}

View file

@ -899,14 +899,3 @@ func TestPhoto_Links(t *testing.T) {
assert.Equal(t, "7jxf3jfn2k", links[0].LinkToken)
})
}
/*func TestPhoto_PrimaryFile(t *testing.T) {
t.Run("return", func(t *testing.T) {
photo := PhotoFixtures.Pointer("Photo04")
file, err := photo.PrimaryFile()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "ft8es39w45bnlqdw", file.FileUID)
})
}*/

View file

@ -0,0 +1,17 @@
package form
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFeedback_Empty(t *testing.T) {
t.Run("true", func(t *testing.T) {
feedback := Feedback{}
assert.True(t, feedback.Empty())
})
t.Run("false", func(t *testing.T) {
feedback := Feedback{Message: "I found a bug", Category: "Bug Report", UserEmail: "test@test.com"}
assert.False(t, feedback.Empty())
})
}

View file

@ -52,4 +52,14 @@ func TestData_AutoAddKeywords(t *testing.T) {
assert.Equal(t, "", data.Keywords)
})
t.Run("ignore because too short", func(t *testing.T) {
data := NewData()
assert.Equal(t, "", data.Keywords)
data.AutoAddKeywords("es")
assert.Equal(t, "", data.Keywords)
})
}

View file

@ -137,3 +137,19 @@ func TestSanitizeDescription(t *testing.T) {
}
})
}
func TestSanitizeUID(t *testing.T) {
t.Run("77d9a719ede3f95915abd081d7b7cb2c", func(t *testing.T) {
result := SanitizeUID("77d9a719ede3f95915abd081d7b7CB2c")
assert.Equal(t, "77d9a719ede3f95915abd081d7b7cb2c", result)
})
t.Run("77d", func(t *testing.T) {
result := SanitizeUID("77d")
assert.Equal(t, "", result)
})
t.Run(":77d9a719ede3f95915abd081d7b7cb2c", func(t *testing.T) {
result := SanitizeUID(":77d9a719ede3f95915abd081d7b7CB2c")
assert.Equal(t, "77d9a719ede3f95915abd081d7b7cb2c", result)
})
}

View file

@ -6,9 +6,26 @@ import (
)
func TestErrors(t *testing.T) {
errors, err := Errors(1000, 0, "notexistingErrorString")
if err != nil {
t.Fatal(err)
}
assert.Empty(t, errors)
t.Run("not existing", func(t *testing.T) {
errors, err := Errors(1000, 0, "notexistingErrorString")
if err != nil {
t.Fatal(err)
}
assert.Empty(t, errors)
})
t.Run("error", func(t *testing.T) {
errors, err := Errors(1000, 0, "error")
if err != nil {
t.Fatal(err)
}
assert.Empty(t, errors)
})
t.Run("warning", func(t *testing.T) {
errors, err := Errors(1000, 0, "warning")
if err != nil {
t.Fatal(err)
}
assert.Empty(t, errors)
})
}