2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-05-16 04:03:55 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFile_DownloadFileName(t *testing.T) {
|
2019-12-17 18:26:13 +01:00
|
|
|
t.Run("photo with title", func(t *testing.T) {
|
2020-04-20 20:07:58 +02:00
|
|
|
photo := &Photo{TakenAtLocal: time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), PhotoTitle: "Berlin / Morning Mood"}
|
|
|
|
file := &File{Photo: photo, FileType: "jpg", FileUUID: "foobar345678765"}
|
2019-05-16 04:03:55 +02:00
|
|
|
|
2020-04-01 12:00:45 +02:00
|
|
|
filename := file.ShareFileName()
|
2019-05-16 04:03:55 +02:00
|
|
|
|
2020-04-20 20:07:58 +02:00
|
|
|
assert.Contains(t, filename, "20190115-000000-Berlin-Morning-Mood")
|
|
|
|
assert.Contains(t, filename, ".jpg")
|
2019-12-17 18:26:13 +01:00
|
|
|
})
|
|
|
|
t.Run("photo without title", func(t *testing.T) {
|
2020-04-20 20:07:58 +02:00
|
|
|
photo := &Photo{TakenAtLocal: time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), PhotoTitle: ""}
|
|
|
|
file := &File{Photo: photo, FileType: "jpg", PhotoUUID: "123", FileUUID: "foobar345678765"}
|
2019-12-17 18:26:13 +01:00
|
|
|
|
2020-04-01 12:00:45 +02:00
|
|
|
filename := file.ShareFileName()
|
2019-12-17 18:26:13 +01:00
|
|
|
|
2020-04-20 20:07:58 +02:00
|
|
|
assert.Contains(t, filename, "20190115-000000-123")
|
|
|
|
assert.Contains(t, filename, ".jpg")
|
2019-12-17 18:26:13 +01:00
|
|
|
})
|
|
|
|
t.Run("photo without photo", func(t *testing.T) {
|
2020-04-20 20:07:58 +02:00
|
|
|
file := &File{Photo: nil, FileType: "jpg", FileHash: "123Hash", FileUUID: "foobar345678765"}
|
2019-12-17 18:26:13 +01:00
|
|
|
|
2020-04-01 12:00:45 +02:00
|
|
|
filename := file.ShareFileName()
|
2019-12-17 18:26:13 +01:00
|
|
|
|
|
|
|
assert.Equal(t, "123Hash.jpg", filename)
|
|
|
|
})
|
2019-05-16 04:03:55 +02:00
|
|
|
}
|