2020-07-13 17:25:27 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
|
2020-07-13 17:25:27 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-01-08 12:20:41 +01:00
|
|
|
func TestAlbumCover(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("InvalidType", func(t *testing.T) {
|
2020-07-13 17:25:27 +02:00
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
AlbumCover(router)
|
2020-07-13 17:25:27 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba7/t/"+conf.PreviewToken()+"/xxx")
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
2021-10-05 18:42:39 +02:00
|
|
|
t.Run("album contains no photos (because is not existing)", func(t *testing.T) {
|
2020-07-13 17:25:27 +02:00
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
AlbumCover(router)
|
2020-07-13 17:25:27 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/albums/987-986435/t/"+conf.PreviewToken()+"/tile_500")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
t.Run("album: could not find original", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
AlbumCover(router)
|
2021-03-10 16:55:55 +01:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba9/t/"+conf.PreviewToken()+"/tile_500")
|
2020-07-13 17:25:27 +02:00
|
|
|
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-03-10 16:55:55 +01:00
|
|
|
AlbumCover(router)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/t/xxx/tile_500")
|
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
|
|
|
})
|
2020-07-13 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-08 12:20:41 +01:00
|
|
|
func TestLabelCover(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("InvalidType", func(t *testing.T) {
|
2020-07-13 17:25:27 +02:00
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
LabelCover(router)
|
2020-07-13 17:25:27 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c2/t/"+conf.PreviewToken()+"/xxx")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
t.Run("invalid label", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
LabelCover(router)
|
2020-07-13 17:25:27 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/labels/xxx/t/"+conf.PreviewToken()+"/tile_500")
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
t.Run("could not find original", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2021-01-08 12:20:41 +01:00
|
|
|
LabelCover(router)
|
2021-03-10 16:55:55 +01:00
|
|
|
//r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/"+conf.PreviewToken()+"/tile_500")
|
|
|
|
//lt9k3pw1wowuy3c2
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c2/t/"+conf.PreviewToken()+"/tile_500")
|
2020-07-13 17:25:27 +02:00
|
|
|
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-03-10 16:55:55 +01:00
|
|
|
LabelCover(router)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/xxx/tile_500")
|
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
|
|
|
})
|
2020-07-13 17:25:27 +02:00
|
|
|
}
|