Remove session in api tests (#21984)

It's no meaning to request an API route with session.
This commit is contained in:
2022-12-02 11:39:42 +08:00
committed by GitHub
parent 665d02efaf
commit df676a47d0
46 changed files with 387 additions and 433 deletions

View File

@ -33,7 +33,7 @@ func TestAPINotification(t *testing.T) {
// test filter
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?since=%s&token=%s", since, token))
resp := session.MakeRequest(t, req, http.StatusOK)
resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
@ -44,7 +44,7 @@ func TestAPINotification(t *testing.T) {
before := "2000-01-01T01%3A06%3A59%2B00%3A00" // 946688819
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=%s&before=%s&token=%s", "true", before, token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 3)
@ -60,7 +60,7 @@ func TestAPINotification(t *testing.T) {
// -- GET /repos/{owner}/{repo}/notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&token=%s", user2.Name, repo1.Name, token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
@ -68,7 +68,7 @@ func TestAPINotification(t *testing.T) {
// -- GET /repos/{owner}/{repo}/notifications -- multiple status-types
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&status-types=pinned&token=%s", user2.Name, repo1.Name, token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 2)
@ -82,11 +82,11 @@ func TestAPINotification(t *testing.T) {
// -- GET /notifications/threads/{id} --
// get forbidden
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", 1, token))
session.MakeRequest(t, req, http.StatusForbidden)
MakeRequest(t, req, http.StatusForbidden)
// get own
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
var apiN api.NotificationThread
DecodeJSON(t, resp, &apiN)
@ -104,28 +104,28 @@ func TestAPINotification(t *testing.T) {
// -- check notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &new)
assert.True(t, new.New > 0)
// -- mark notifications as read --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 2)
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ...
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?last_read_at=%s&token=%s", user2.Name, repo1.Name, lastReadAt, token))
session.MakeRequest(t, req, http.StatusResetContent)
MakeRequest(t, req, http.StatusResetContent)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
// -- PATCH /notifications/threads/{id} --
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
session.MakeRequest(t, req, http.StatusResetContent)
MakeRequest(t, req, http.StatusResetContent)
assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status)
thread5 = unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
@ -133,7 +133,7 @@ func TestAPINotification(t *testing.T) {
// -- check notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &new)
assert.True(t, new.New == 0)
}
@ -149,7 +149,7 @@ func TestAPINotificationPUT(t *testing.T) {
// Check notifications are as expected
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=true&token=%s", token))
resp := session.MakeRequest(t, req, http.StatusOK)
resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
@ -172,7 +172,7 @@ func TestAPINotificationPUT(t *testing.T) {
// change it to unread.
//
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/notifications?status-types=read&status-type=pinned&to-status=unread&token=%s", token))
resp = session.MakeRequest(t, req, http.StatusResetContent)
resp = MakeRequest(t, req, http.StatusResetContent)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 1)
assert.EqualValues(t, 2, apiNL[0].ID)
@ -183,7 +183,7 @@ func TestAPINotificationPUT(t *testing.T) {
// Now nofication ID 2 is the first in the list and is unread.
//
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=true&token=%s", token))
resp = session.MakeRequest(t, req, http.StatusOK)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
assert.Len(t, apiNL, 4)