Tests: Add tests for internal/api
This commit is contained in:
parent
c0d5da40e1
commit
816aca7420
4 changed files with 52 additions and 4 deletions
|
@ -19,3 +19,21 @@ func TestGetConfig(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetConfigOptions(t *testing.T) {
|
||||
t.Run("unauthorised", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
GetConfigOptions(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/config/options")
|
||||
assert.Equal(t, http.StatusUnauthorized, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSaveConfigOptions(t *testing.T) {
|
||||
t.Run("unauthorised", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
SaveConfigOptions(router)
|
||||
r := PerformRequest(app, "POST", "/api/v1/config/options")
|
||||
assert.Equal(t, http.StatusUnauthorized, r.Code)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -24,9 +24,15 @@ func TestAlbumCover(t *testing.T) {
|
|||
t.Run("album: could not find original", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
AlbumCover(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/t/"+conf.PreviewToken()+"/tile_500")
|
||||
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba9/t/"+conf.PreviewToken()+"/tile_500")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("invalid token", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
AlbumCover(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/t/xxx/tile_500")
|
||||
assert.Equal(t, http.StatusForbidden, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLabelCover(t *testing.T) {
|
||||
|
@ -46,7 +52,15 @@ func TestLabelCover(t *testing.T) {
|
|||
t.Run("could not find original", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
LabelCover(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/"+conf.PreviewToken()+"/tile_500")
|
||||
//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")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("invalid token", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
LabelCover(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/xxx/tile_500")
|
||||
assert.Equal(t, http.StatusForbidden, r.Code)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,12 +16,20 @@ func TestDeleteFile(t *testing.T) {
|
|||
r := PerformRequest(app, "DELETE", "/api/v1/photos/5678/files/23456hbg")
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
})
|
||||
/*t.Run("delete primary file", func(t *testing.T) {
|
||||
t.Run("delete primary file", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
|
||||
DeleteFile(router)
|
||||
|
||||
r := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh7/files/ft8es39w45bnlqdw")
|
||||
assert.Equal(t, http.StatusInternalServerError, r.Code)
|
||||
})
|
||||
t.Run("try to delete file", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
|
||||
DeleteFile(router)
|
||||
|
||||
r := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh8/files/ft9es39w45bnlqdw")
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
})*/
|
||||
})
|
||||
}
|
||||
|
|
|
@ -233,6 +233,14 @@ func TestTime(t *testing.T) {
|
|||
result := Time("2020-01-00.jpg")
|
||||
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", result.String())
|
||||
})
|
||||
t.Run("IMG-20191120-WA0001.jpg", func(t *testing.T) {
|
||||
result := Time("IMG-20191120-WA0001.jpg")
|
||||
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", result.String())
|
||||
})
|
||||
t.Run("VID-20191120-WA0001.jpg", func(t *testing.T) {
|
||||
result := Time("VID-20191120-WA0001.jpg")
|
||||
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", result.String())
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsTime(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue