diff --git a/chat/channel.go b/chat/channel.go index 68fee01..94916de 100644 --- a/chat/channel.go +++ b/chat/channel.go @@ -168,7 +168,7 @@ func (ch *Channel) NamesPrefix(prefix string) []string { members := ch.members.ListPrefix(prefix) names := make([]string, len(members)) for i, u := range members { - names[i] = u.(*User).Name() + names[i] = u.(*Member).User.Name() } return names } diff --git a/chat/channel_test.go b/chat/channel_test.go index 2532fb2..10e990d 100644 --- a/chat/channel_test.go +++ b/chat/channel_test.go @@ -56,3 +56,29 @@ func TestChannelJoin(t *testing.T) { t.Errorf("Got: `%s`; Expected: `%s`", actual, expected) } } + +func TestChannelNames(t *testing.T) { + var expected, actual []byte + + s := &MockScreen{} + u := NewUser("foo") + + ch := NewChannel() + go ch.Serve() + defer ch.Close() + + err := ch.Join(u) + if err != nil { + t.Fatal(err) + } + + <-ch.broadcast + + ch.Send(ParseInput("/names", u)) + u.ConsumeOne(s) + expected = []byte("-> 1 connected: foo" + Newline) + s.Read(&actual) + if !reflect.DeepEqual(actual, expected) { + t.Errorf("Got: `%s`; Expected: `%s`", actual, expected) + } +}