Backend: Add unit tests for internal/api
This commit is contained in:
parent
8989c987a2
commit
a5987a0b33
|
@ -25,4 +25,10 @@ func TestGetDownload(t *testing.T) {
|
|||
r := PerformRequest(app, "GET", "/api/v1/dl/3cad9168fa6acc5c5c2965ddf6ec465ca42fd818?t="+conf.DownloadToken())
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
})
|
||||
t.Run("invalid download token", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
GetDownload(router)
|
||||
r := PerformRequest(app, "GET", "/api/v1/dl/3cad9168fa6acc5c5c2965ddf6ec465ca42fd818?t=xxx")
|
||||
assert.Equal(t, http.StatusForbidden, r.Code)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ func TestLikeLabel(t *testing.T) {
|
|||
t.Run("like existing label", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
GetLabels(router)
|
||||
r2 := PerformRequest(app, "GET", "/api/v1/labels?count=1&q=likeLabel")
|
||||
r2 := PerformRequest(app, "GET", "/api/v1/labels?count=3&q=likeLabel")
|
||||
t.Log(r2.Body.String())
|
||||
val := gjson.Get(r2.Body.String(), `#(Slug=="likeLabel").Favorite`)
|
||||
assert.Equal(t, "false", val.String())
|
||||
|
@ -73,11 +73,19 @@ func TestLikeLabel(t *testing.T) {
|
|||
r := PerformRequest(app, "POST", "/api/v1/labels/lt9k3pw1wowuy3c9/like")
|
||||
t.Log(r.Body.String())
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
r3 := PerformRequest(app, "GET", "/api/v1/labels?count=1&q=likeLabel")
|
||||
|
||||
r3 := PerformRequest(app, "GET", "/api/v1/labels?count=3&q=likeLabel")
|
||||
t.Log(r3.Body.String())
|
||||
val2 := gjson.Get(r3.Body.String(), `#(Slug=="likeLabel").Favorite`)
|
||||
assert.Equal(t, "true", val2.String())
|
||||
})
|
||||
t.Run("like existing label with prio < 0", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
LikeLabel(router)
|
||||
r := PerformRequest(app, "POST", "/api/v1/labels/lt9k3pw1wowuy311/like")
|
||||
t.Log(r.Body.String())
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
@ -107,4 +115,11 @@ func TestDislikeLabel(t *testing.T) {
|
|||
val2 := gjson.Get(r3.Body.String(), `#(Slug=="landscape").Favorite`)
|
||||
assert.Equal(t, "false", val2.String())
|
||||
})
|
||||
|
||||
t.Run("dislike existing label with prio < 0", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
DislikeLabel(router)
|
||||
r := PerformRequest(app, "DELETE", "/api/v1/labels/lt9k3pw1wowuy312/like")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ var LabelFixtures = LabelMap{
|
|||
},
|
||||
"no-jpeg": {
|
||||
ID: 1000008,
|
||||
LabelUID: "lt9k3aa1wowuy3c5",
|
||||
LabelUID: "lt9k3aa1wowuy310",
|
||||
LabelSlug: "no-jpeg",
|
||||
CustomSlug: "no-jpeg",
|
||||
LabelName: "NO JPEG",
|
||||
|
@ -181,6 +181,40 @@ var LabelFixtures = LabelMap{
|
|||
DeletedAt: nil,
|
||||
New: false,
|
||||
},
|
||||
"apilikeLabel": {
|
||||
ID: 1000009,
|
||||
LabelUID: "lt9k3pw1wowuy311",
|
||||
LabelSlug: "apilikeLabel",
|
||||
CustomSlug: "apilikeLabel",
|
||||
LabelName: "apilikeLabel",
|
||||
LabelPriority: -1,
|
||||
LabelFavorite: false,
|
||||
LabelDescription: "",
|
||||
LabelNotes: "",
|
||||
PhotoCount: 1,
|
||||
LabelCategories: []*Label{},
|
||||
CreatedAt: Timestamp(),
|
||||
UpdatedAt: Timestamp(),
|
||||
DeletedAt: nil,
|
||||
New: false,
|
||||
},
|
||||
"apidislikeLabel": {
|
||||
ID: 1000010,
|
||||
LabelUID: "lt9k3pw1wowuy312",
|
||||
LabelSlug: "apidislikeLabel",
|
||||
CustomSlug: "apidislikeLabel",
|
||||
LabelName: "apidislikeLabel",
|
||||
LabelPriority: -2,
|
||||
LabelFavorite: true,
|
||||
LabelDescription: "",
|
||||
LabelNotes: "",
|
||||
PhotoCount: 1,
|
||||
LabelCategories: []*Label{},
|
||||
CreatedAt: Timestamp(),
|
||||
UpdatedAt: Timestamp(),
|
||||
DeletedAt: nil,
|
||||
New: false,
|
||||
},
|
||||
}
|
||||
|
||||
// CreateLabelFixtures inserts known entities into the database for testing.
|
||||
|
|
Loading…
Reference in a new issue