@@ -64,6 +64,19 @@ func TestAPINotification(t *testing.T) {
6464 assert .Len (t , apiNL , 1 )
6565 assert .EqualValues (t , 4 , apiNL [0 ].ID )
6666
67+ // -- GET /repos/{owner}/{repo}/notifications -- multiple status-types
68+ 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 ))
69+ resp = session .MakeRequest (t , req , http .StatusOK )
70+ DecodeJSON (t , resp , & apiNL )
71+
72+ assert .Len (t , apiNL , 2 )
73+ assert .EqualValues (t , 4 , apiNL [0 ].ID )
74+ assert .True (t , apiNL [0 ].Unread )
75+ assert .False (t , apiNL [0 ].Pinned )
76+ assert .EqualValues (t , 3 , apiNL [1 ].ID )
77+ assert .False (t , apiNL [1 ].Unread )
78+ assert .True (t , apiNL [1 ].Pinned )
79+
6780 // -- GET /notifications/threads/{id} --
6881 // get forbidden
6982 req = NewRequest (t , "GET" , fmt .Sprintf ("/api/v1/notifications/threads/%d?token=%s" , 1 , token ))
@@ -122,3 +135,57 @@ func TestAPINotification(t *testing.T) {
122135 DecodeJSON (t , resp , & new )
123136 assert .True (t , new .New == 0 )
124137}
138+
139+ func TestAPINotificationPUT (t * testing.T ) {
140+ defer prepareTestEnv (t )()
141+
142+ user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }).(* user_model.User )
143+ thread5 := unittest .AssertExistsAndLoadBean (t , & models.Notification {ID : 5 }).(* models.Notification )
144+ assert .NoError (t , thread5 .LoadAttributes ())
145+ session := loginUser (t , user2 .Name )
146+ token := getTokenForLoggedInUser (t , session )
147+
148+ // Check notifications are as expected
149+ req := NewRequest (t , "GET" , fmt .Sprintf ("/api/v1/notifications?all=true&token=%s" , token ))
150+ resp := session .MakeRequest (t , req , http .StatusOK )
151+ var apiNL []api.NotificationThread
152+ DecodeJSON (t , resp , & apiNL )
153+
154+ assert .Len (t , apiNL , 4 )
155+ assert .EqualValues (t , 5 , apiNL [0 ].ID )
156+ assert .True (t , apiNL [0 ].Unread )
157+ assert .False (t , apiNL [0 ].Pinned )
158+ assert .EqualValues (t , 4 , apiNL [1 ].ID )
159+ assert .True (t , apiNL [1 ].Unread )
160+ assert .False (t , apiNL [1 ].Pinned )
161+ assert .EqualValues (t , 3 , apiNL [2 ].ID )
162+ assert .False (t , apiNL [2 ].Unread )
163+ assert .True (t , apiNL [2 ].Pinned )
164+ assert .EqualValues (t , 2 , apiNL [3 ].ID )
165+ assert .False (t , apiNL [3 ].Unread )
166+ assert .False (t , apiNL [3 ].Pinned )
167+
168+ //
169+ // Notification ID 2 is the only one with status-type read & pinned
170+ // change it to unread.
171+ //
172+ req = NewRequest (t , "PUT" , fmt .Sprintf ("/api/v1/notifications?status-types=read&status-type=pinned&to-status=unread&token=%s" , token ))
173+ resp = session .MakeRequest (t , req , http .StatusResetContent )
174+ DecodeJSON (t , resp , & apiNL )
175+ assert .Len (t , apiNL , 1 )
176+ assert .EqualValues (t , 2 , apiNL [0 ].ID )
177+ assert .True (t , apiNL [0 ].Unread )
178+ assert .False (t , apiNL [0 ].Pinned )
179+
180+ //
181+ // Now nofication ID 2 is the first in the list and is unread.
182+ //
183+ req = NewRequest (t , "GET" , fmt .Sprintf ("/api/v1/notifications?all=true&token=%s" , token ))
184+ resp = session .MakeRequest (t , req , http .StatusOK )
185+ DecodeJSON (t , resp , & apiNL )
186+
187+ assert .Len (t , apiNL , 4 )
188+ assert .EqualValues (t , 2 , apiNL [0 ].ID )
189+ assert .True (t , apiNL [0 ].Unread )
190+ assert .False (t , apiNL [0 ].Pinned )
191+ }
0 commit comments