Decode the API's actual fields in neoirc-cli (closes #146)
check / check (push) Waiting to run
check / check (push) Waiting to run
The CLI read the poll cursor from `lastId` while the server sends `last_id`, so the cursor stayed at 0 and every poll returned the whole queue at once. It now reads `last_id`. /names decodes the member objects the server sends and prints each nick with `@` for an operator or `+` for a voiced member. /list prints each channel's name and topic, since the server sends no member count. StateResponse.Channels decodes channel objects. /topic with no text prints a usage line and sends nothing, because the HTTP API has no topic query and a TOPIC without text gets 461. The help says "Set topic". The client tests serve the bodies the handlers send, so a wrong JSON tag in types.go fails a test; another test covers the /names prefixes. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
api "sneak.berlin/go/neoirc/internal/cli/api"
|
||||
)
|
||||
|
||||
func TestMemberPrefix(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
member api.Member
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "operator",
|
||||
member: api.Member{Nick: "alice", IsOperator: true},
|
||||
want: "@",
|
||||
},
|
||||
{
|
||||
name: "voiced member",
|
||||
member: api.Member{Nick: "bob", IsVoiced: true},
|
||||
want: "+",
|
||||
},
|
||||
{
|
||||
name: "voiced operator",
|
||||
member: api.Member{
|
||||
Nick: "Carol", IsOperator: true, IsVoiced: true,
|
||||
},
|
||||
want: "@",
|
||||
},
|
||||
{
|
||||
name: "plain member",
|
||||
member: api.Member{Nick: "dave"},
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := memberPrefix(test.member)
|
||||
if got != test.want {
|
||||
t.Fatalf("got %q, want %q", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user