-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix rendering non-members on the dashboard (#238)
* fix rendering non-members on the dashboard fixes #236 * remove alias or feedref code from template doing this in the template was hard to read and inefficient. also: rename OnlineMembers to OnlineUsers since it is a misnomer. There are other connected peers in a room in certain privacy modes.
- Loading branch information
Showing
4 changed files
with
119 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package admin | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/ssb-ngi-pointer/go-ssb-room/v2/roomdb" | ||
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web/router" | ||
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web/webassert" | ||
"github.com/stretchr/testify/assert" | ||
refs "go.mindeco.de/ssb-refs" | ||
) | ||
|
||
func TestDashboardSimple(t *testing.T) { | ||
ts := newSession(t) | ||
a := assert.New(t) | ||
|
||
testRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)} | ||
ts.RoomState.AddEndpoint(testRef, nil) // 1 online | ||
ts.MembersDB.CountReturns(4, nil) // 4 members | ||
ts.InvitesDB.CountReturns(3, nil) // 3 invites | ||
ts.DeniedKeysDB.CountReturns(2, nil) // 2 banned | ||
|
||
dashURL := ts.URLTo(router.AdminDashboard) | ||
|
||
html, resp := ts.Client.GetHTML(dashURL) | ||
a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code") | ||
|
||
a.Equal("1", html.Find("#online-count").Text()) | ||
a.Equal("4", html.Find("#member-count").Text()) | ||
a.Equal("3", html.Find("#invite-count").Text()) | ||
a.Equal("2", html.Find("#denied-count").Text()) | ||
|
||
webassert.Localized(t, html, []webassert.LocalizedElement{ | ||
{"title", "AdminDashboardTitle"}, | ||
}) | ||
} | ||
|
||
// make sure the dashboard renders when someone is connected that is not a member | ||
func TestDashboardWithVisitors(t *testing.T) { | ||
ts := newSession(t) | ||
a := assert.New(t) | ||
|
||
visitorRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)} | ||
memberRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{1}, 32)} | ||
ts.RoomState.AddEndpoint(visitorRef, nil) | ||
ts.RoomState.AddEndpoint(memberRef, nil) | ||
|
||
ts.MembersDB.CountReturns(1, nil) | ||
// return a member for the member but not for the visitor | ||
ts.MembersDB.GetByFeedStub = func(ctx context.Context, r refs.FeedRef) (roomdb.Member, error) { | ||
if r.Equal(&memberRef) { | ||
return roomdb.Member{ID: 23, Role: roomdb.RoleMember, PubKey: r}, nil | ||
} | ||
return roomdb.Member{}, roomdb.ErrNotFound | ||
} | ||
|
||
dashURL := ts.URLTo(router.AdminDashboard) | ||
|
||
html, resp := ts.Client.GetHTML(dashURL) | ||
a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code") | ||
|
||
a.Equal("2", html.Find("#online-count").Text()) | ||
a.Equal("1", html.Find("#member-count").Text()) | ||
|
||
memberList := html.Find("#connected-list a") | ||
a.Equal(2, memberList.Length()) | ||
|
||
htmlVisitor := memberList.Eq(0) | ||
a.Equal(visitorRef.Ref(), htmlVisitor.Text()) | ||
gotLink, has := htmlVisitor.Attr("href") | ||
a.False(has, "visitor should not have a link to a details page: %v", gotLink) | ||
|
||
htmlMember := memberList.Eq(1) | ||
a.Equal(memberRef.Ref(), htmlMember.Text()) | ||
gotLink, has = htmlMember.Attr("href") | ||
a.True(has, "member should have a link to a details page") | ||
wantLink := ts.URLTo(router.AdminMemberDetails, "id", 23) | ||
a.Equal(wantLink.String(), gotLink) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters