Backend: Add unit tests for internal/api
This commit is contained in:
parent
5866ba307f
commit
2db97ef168
2 changed files with 20 additions and 0 deletions
|
@ -25,4 +25,12 @@ func TestPhotoUnstack(t *testing.T) {
|
|||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
// t.Logf("RESP: %s", r.Body.String())
|
||||
})
|
||||
|
||||
t.Run("not existing file", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
PhotoUnstack(router)
|
||||
r := PerformRequest(app, "POST", "/api/v1/photos/pt9jtdre2lvl0yh7/files/xxx/unstack")
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
// t.Logf("RESP: %s", r.Body.String())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -22,6 +22,18 @@ func TestCreateSession(t *testing.T) {
|
|||
r := PerformRequestWithBody(app, "POST", "/api/v1/session", `{"username": 123, "password": "xxx"}`)
|
||||
assert.Equal(t, http.StatusBadRequest, r.Code)
|
||||
})
|
||||
t.Run("invalid token", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
CreateSession(router)
|
||||
r := PerformRequestWithBody(app, "POST", "/api/v1/session", `{"username": "admin", "password": "photoprism", "token": "xxx"}`)
|
||||
assert.Equal(t, http.StatusBadRequest, r.Code)
|
||||
})
|
||||
t.Run("valid token", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
CreateSession(router)
|
||||
r := PerformRequestWithBody(app, "POST", "/api/v1/session", `{"username": "admin", "password": "photoprism", "token": "1jxf3jfn2k"}`)
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("invalid password", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
CreateSession(router)
|
||||
|
|
Loading…
Reference in a new issue