2021-03-10 11:30:26 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2021-04-19 13:48:46 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-10-13 22:11:02 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2021-03-10 11:30:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetFolderCover(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("NoCover", func(t *testing.T) {
|
2021-03-10 11:30:26 +01:00
|
|
|
app, router, conf := NewApiTest()
|
2021-09-05 13:48:53 +02:00
|
|
|
FolderCover(router)
|
2021-03-10 11:30:26 +01:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/t/dqo63pn35k2d495z/"+conf.PreviewToken()+"/tile_500")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("InvalidType", func(t *testing.T) {
|
2021-03-10 11:30:26 +01:00
|
|
|
app, router, conf := NewApiTest()
|
2021-09-05 13:48:53 +02:00
|
|
|
FolderCover(router)
|
2021-03-10 11:30:26 +01:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/t/dqo63pn35k2d495z/"+conf.PreviewToken()+"/xxx")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("InvalidToken", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
|
|
|
conf.SetAuthMode(config.AuthModePasswd)
|
|
|
|
defer conf.SetAuthMode(config.AuthModePublic)
|
2021-09-05 13:48:53 +02:00
|
|
|
FolderCover(router)
|
2021-03-10 11:30:26 +01:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/t/dqo63pn35k2d495z/xxx/tile_500")
|
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
|
|
|
})
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("NotFound", func(t *testing.T) {
|
2021-03-10 11:30:26 +01:00
|
|
|
app, router, conf := NewApiTest()
|
2021-09-05 13:48:53 +02:00
|
|
|
FolderCover(router)
|
2021-03-10 11:30:26 +01:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/folders/t/dqo63pn2f87f02oi/"+conf.PreviewToken()+"/fit_7680")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
}
|