diff options
author | singuliere <35190819+singuliere@users.noreply.github.com> | 2021-12-03 20:20:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 20:20:41 +0100 |
commit | 1a78e23355de554a360f65c1a4808ae812a68809 (patch) | |
tree | 4f5590bef1d7480125cbf0591a7d15a607e5d779 /integrations | |
parent | 4f81c7dffe5ee10bfe7bf1889e1795515c759861 (diff) | |
download | gitea-1a78e23355de554a360f65c1a4808ae812a68809.tar.gz gitea-1a78e23355de554a360f65c1a4808ae812a68809.zip |
tests: more integration tests for notifications (#17845)
Verify that multiple status-types are taken into account as expected.
Refs: https://github.com/go-gitea/gitea/issues/16796
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_notification_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/integrations/api_notification_test.go b/integrations/api_notification_test.go index 182e9829cb..e3f39b363c 100644 --- a/integrations/api_notification_test.go +++ b/integrations/api_notification_test.go @@ -64,6 +64,19 @@ func TestAPINotification(t *testing.T) { assert.Len(t, apiNL, 1) 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)) + resp = session.MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiNL) + + assert.Len(t, apiNL, 2) + assert.EqualValues(t, 4, apiNL[0].ID) + assert.True(t, apiNL[0].Unread) + assert.False(t, apiNL[0].Pinned) + assert.EqualValues(t, 3, apiNL[1].ID) + assert.False(t, apiNL[1].Unread) + assert.True(t, apiNL[1].Pinned) + // -- GET /notifications/threads/{id} -- // get forbidden req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", 1, token)) @@ -122,3 +135,57 @@ func TestAPINotification(t *testing.T) { DecodeJSON(t, resp, &new) assert.True(t, new.New == 0) } + +func TestAPINotificationPUT(t *testing.T) { + defer prepareTestEnv(t)() + + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) + thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification) + assert.NoError(t, thread5.LoadAttributes()) + session := loginUser(t, user2.Name) + token := getTokenForLoggedInUser(t, session) + + // 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) + var apiNL []api.NotificationThread + DecodeJSON(t, resp, &apiNL) + + assert.Len(t, apiNL, 4) + assert.EqualValues(t, 5, apiNL[0].ID) + assert.True(t, apiNL[0].Unread) + assert.False(t, apiNL[0].Pinned) + assert.EqualValues(t, 4, apiNL[1].ID) + assert.True(t, apiNL[1].Unread) + assert.False(t, apiNL[1].Pinned) + assert.EqualValues(t, 3, apiNL[2].ID) + assert.False(t, apiNL[2].Unread) + assert.True(t, apiNL[2].Pinned) + assert.EqualValues(t, 2, apiNL[3].ID) + assert.False(t, apiNL[3].Unread) + assert.False(t, apiNL[3].Pinned) + + // + // 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)) + resp = session.MakeRequest(t, req, http.StatusResetContent) + DecodeJSON(t, resp, &apiNL) + assert.Len(t, apiNL, 1) + assert.EqualValues(t, 2, apiNL[0].ID) + assert.True(t, apiNL[0].Unread) + assert.False(t, apiNL[0].Pinned) + + // + // 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) + DecodeJSON(t, resp, &apiNL) + + assert.Len(t, apiNL, 4) + assert.EqualValues(t, 2, apiNL[0].ID) + assert.True(t, apiNL[0].Unread) + assert.False(t, apiNL[0].Pinned) +} |