mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	| @@ -35,7 +35,8 @@ func TestAPINotification(t *testing.T) { | ||||
| 	// -- GET /notifications -- | ||||
| 	// 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)) | ||||
| 	req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?since=%s", since)). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp := MakeRequest(t, req, http.StatusOK) | ||||
| 	var apiNL []api.NotificationThread | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
| @@ -46,7 +47,8 @@ func TestAPINotification(t *testing.T) { | ||||
| 	// test filter | ||||
| 	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)) | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=%s&before=%s", "true", before)). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
|  | ||||
| @@ -62,7 +64,8 @@ func TestAPINotification(t *testing.T) { | ||||
| 	assert.False(t, apiNL[2].Pinned) | ||||
|  | ||||
| 	// -- 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)) | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread", user2.Name, repo1.Name)). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
|  | ||||
| @@ -70,7 +73,8 @@ func TestAPINotification(t *testing.T) { | ||||
| 	assert.EqualValues(t, 4, apiNL[0].ID) | ||||
|  | ||||
| 	// -- 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)) | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&status-types=pinned", user2.Name, repo1.Name)). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
|  | ||||
| @@ -86,11 +90,13 @@ 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)) | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d", 1)). | ||||
| 		AddTokenAuth(token) | ||||
| 	MakeRequest(t, req, http.StatusForbidden) | ||||
|  | ||||
| 	// get own | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token)) | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d", thread5.ID)). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	var apiN api.NotificationThread | ||||
| 	DecodeJSON(t, resp, &apiN) | ||||
| @@ -110,28 +116,33 @@ func TestAPINotification(t *testing.T) { | ||||
| 	}{} | ||||
|  | ||||
| 	// -- check notifications -- | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token)) | ||||
| 	req = NewRequest(t, "GET", "/api/v1/notifications/new"). | ||||
| 		AddTokenAuth(token) | ||||
| 	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)) | ||||
| 	req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread"). | ||||
| 		AddTokenAuth(token) | ||||
| 	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)) | ||||
| 	req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?last_read_at=%s", user2.Name, repo1.Name, lastReadAt)). | ||||
| 		AddTokenAuth(token) | ||||
| 	MakeRequest(t, req, http.StatusResetContent) | ||||
|  | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token)) | ||||
| 	req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread"). | ||||
| 		AddTokenAuth(token) | ||||
| 	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)) | ||||
| 	req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d", thread5.ID)). | ||||
| 		AddTokenAuth(token) | ||||
| 	MakeRequest(t, req, http.StatusResetContent) | ||||
|  | ||||
| 	assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status) | ||||
| @@ -139,7 +150,8 @@ func TestAPINotification(t *testing.T) { | ||||
| 	assert.Equal(t, activities_model.NotificationStatusRead, thread5.Status) | ||||
|  | ||||
| 	// -- check notifications -- | ||||
| 	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token)) | ||||
| 	req = NewRequest(t, "GET", "/api/v1/notifications/new"). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	DecodeJSON(t, resp, &new) | ||||
| 	assert.True(t, new.New == 0) | ||||
| @@ -155,7 +167,8 @@ func TestAPINotificationPUT(t *testing.T) { | ||||
| 	token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteNotification) | ||||
|  | ||||
| 	// Check notifications are as expected | ||||
| 	req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=true&token=%s", token)) | ||||
| 	req := NewRequest(t, "GET", "/api/v1/notifications?all=true"). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp := MakeRequest(t, req, http.StatusOK) | ||||
| 	var apiNL []api.NotificationThread | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
| @@ -178,7 +191,8 @@ func TestAPINotificationPUT(t *testing.T) { | ||||
| 	// Notification ID 2 is the only one with status-type read & pinned | ||||
| 	// 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)) | ||||
| 	req = NewRequest(t, "PUT", "/api/v1/notifications?status-types=read&status-type=pinned&to-status=unread"). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusResetContent) | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
| 	assert.Len(t, apiNL, 1) | ||||
| @@ -189,7 +203,8 @@ 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)) | ||||
| 	req = NewRequest(t, "GET", "/api/v1/notifications?all=true"). | ||||
| 		AddTokenAuth(token) | ||||
| 	resp = MakeRequest(t, req, http.StatusOK) | ||||
| 	DecodeJSON(t, resp, &apiNL) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user