-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotifications_test.go
More file actions
33 lines (28 loc) · 957 Bytes
/
notifications_test.go
File metadata and controls
33 lines (28 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/shurcooL/notifications/fs"
"golang.org/x/net/webdav"
)
// Test that visiting /notificationsv1 without being logged in
// redirects to /login.
func TestNotificationsV1RedirectsLogin(t *testing.T) {
mux := http.NewServeMux()
users, _, err := newUsersService(webdav.NewMemFS())
if err != nil {
t.Fatal(err)
}
initNotifications(mux, fs.NewService(webdav.NewMemFS(), users), nil, users, nil)
req := httptest.NewRequest(http.MethodGet, "/notificationsv1", nil)
rr := httptest.NewRecorder()
mux.ServeHTTP(rr, req)
resp := rr.Result()
if got, want := resp.StatusCode, http.StatusSeeOther; got != want {
t.Errorf("got status code %d %s, want %d %s", got, http.StatusText(got), want, http.StatusText(want))
}
if got, want := resp.Header.Get("Location"), "/login?return=%2Fnotificationsv1"; got != want {
t.Errorf("got Location header %q, want %q", got, want)
}
}