2020-05-22 16:29:12 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetFoldersOriginals(t *testing.T) {
|
|
|
|
t.Run("flat", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2020-05-22 19:25:53 +02:00
|
|
|
_ = conf.CreateDirectories()
|
2020-07-16 15:43:23 +02:00
|
|
|
expected, err := fs.Dirs(conf.OriginalsPath(), false, true)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
GetFoldersOriginals(router)
|
2020-05-22 16:29:12 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/originals")
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
// t.Logf("RESPONSE: %s", r.Body.Bytes())
|
|
|
|
|
|
|
|
var resp FoldersResponse
|
|
|
|
err = json.Unmarshal(r.Body.Bytes(), &resp)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
folders := resp.Folders
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
if len(folders) != len(expected) {
|
2020-05-22 16:29:12 +02:00
|
|
|
t.Fatalf("response contains %d folders", len(folders))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(folders) == 0 {
|
|
|
|
// There are no existing folders, that's ok.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, folder := range folders {
|
|
|
|
assert.Equal(t, "", folder.FolderDescription)
|
|
|
|
assert.Equal(t, entity.TypeDefault, folder.FolderType)
|
|
|
|
assert.Equal(t, entity.SortOrderName, folder.FolderOrder)
|
2020-06-07 10:09:35 +02:00
|
|
|
assert.Equal(t, entity.RootOriginals, folder.Root)
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.IsType(t, "", folder.FolderUID)
|
2020-05-22 16:29:12 +02:00
|
|
|
assert.Equal(t, false, folder.FolderFavorite)
|
|
|
|
assert.Equal(t, false, folder.FolderIgnore)
|
|
|
|
assert.Equal(t, false, folder.FolderWatch)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("recursive", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2020-05-22 19:25:53 +02:00
|
|
|
_ = conf.CreateDirectories()
|
2020-07-16 15:43:23 +02:00
|
|
|
expected, err := fs.Dirs(conf.OriginalsPath(), true, true)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-06-25 14:54:04 +02:00
|
|
|
GetFoldersOriginals(router)
|
2020-05-22 16:29:12 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/originals?recursive=true")
|
2020-05-24 22:16:06 +02:00
|
|
|
|
|
|
|
// t.Logf("RESPONSE: %s", r.Body.Bytes())
|
|
|
|
|
|
|
|
var resp FoldersResponse
|
|
|
|
err = json.Unmarshal(r.Body.Bytes(), &resp)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
folders := resp.Folders
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
if len(folders) != len(expected) {
|
2020-05-22 16:29:12 +02:00
|
|
|
t.Fatalf("response contains %d folders", len(folders))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, folder := range folders {
|
|
|
|
assert.Equal(t, "", folder.FolderDescription)
|
|
|
|
assert.Equal(t, entity.TypeDefault, folder.FolderType)
|
|
|
|
assert.Equal(t, entity.SortOrderName, folder.FolderOrder)
|
2020-06-07 10:09:35 +02:00
|
|
|
assert.Equal(t, entity.RootOriginals, folder.Root)
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.IsType(t, "", folder.FolderUID)
|
2020-05-22 16:29:12 +02:00
|
|
|
assert.Equal(t, false, folder.FolderFavorite)
|
|
|
|
assert.Equal(t, false, folder.FolderIgnore)
|
|
|
|
assert.Equal(t, false, folder.FolderWatch)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFoldersImport(t *testing.T) {
|
|
|
|
t.Run("flat", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2020-05-22 19:25:53 +02:00
|
|
|
_ = conf.CreateDirectories()
|
2020-07-16 15:43:23 +02:00
|
|
|
expected, err := fs.Dirs(conf.ImportPath(), false, true)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
GetFoldersImport(router)
|
2020-05-22 16:29:12 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/import")
|
2020-05-24 22:16:06 +02:00
|
|
|
|
|
|
|
// t.Logf("RESPONSE: %s", r.Body.Bytes())
|
|
|
|
|
|
|
|
var resp FoldersResponse
|
|
|
|
err = json.Unmarshal(r.Body.Bytes(), &resp)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
folders := resp.Folders
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
if len(folders) != len(expected) {
|
2020-05-22 16:29:12 +02:00
|
|
|
t.Fatalf("response contains %d folders", len(folders))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(folders) == 0 {
|
|
|
|
// There are no existing folders, that's ok.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, folder := range folders {
|
|
|
|
assert.Equal(t, "", folder.FolderDescription)
|
|
|
|
assert.Equal(t, entity.TypeDefault, folder.FolderType)
|
|
|
|
assert.Equal(t, entity.SortOrderName, folder.FolderOrder)
|
2020-05-24 22:16:06 +02:00
|
|
|
assert.Equal(t, entity.RootImport, folder.Root)
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.IsType(t, "", folder.FolderUID)
|
2020-05-22 16:29:12 +02:00
|
|
|
assert.Equal(t, false, folder.FolderFavorite)
|
|
|
|
assert.Equal(t, false, folder.FolderIgnore)
|
|
|
|
assert.Equal(t, false, folder.FolderWatch)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
t.Run("recursive", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2020-05-22 19:25:53 +02:00
|
|
|
_ = conf.CreateDirectories()
|
2020-07-16 15:43:23 +02:00
|
|
|
expected, err := fs.Dirs(conf.ImportPath(), true, true)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-05-23 20:58:58 +02:00
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
GetFoldersImport(router)
|
2020-05-22 16:29:12 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/import?recursive=true")
|
2020-05-24 22:16:06 +02:00
|
|
|
|
|
|
|
var resp FoldersResponse
|
|
|
|
err = json.Unmarshal(r.Body.Bytes(), &resp)
|
2020-05-22 16:29:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
folders := resp.Folders
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
if len(folders) != len(expected) {
|
2020-05-22 16:29:12 +02:00
|
|
|
t.Fatalf("response contains %d folders", len(folders))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, folder := range folders {
|
|
|
|
assert.Equal(t, "", folder.FolderDescription)
|
|
|
|
assert.Equal(t, entity.TypeDefault, folder.FolderType)
|
|
|
|
assert.Equal(t, entity.SortOrderName, folder.FolderOrder)
|
2020-05-24 22:16:06 +02:00
|
|
|
assert.Equal(t, entity.RootImport, folder.Root)
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.IsType(t, "", folder.FolderUID)
|
2020-05-22 16:29:12 +02:00
|
|
|
assert.Equal(t, false, folder.FolderFavorite)
|
|
|
|
assert.Equal(t, false, folder.FolderIgnore)
|
|
|
|
assert.Equal(t, false, folder.FolderWatch)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|