3c7b8278ce
- usePermissions ORs current user roles + @everyone only (not all server roles) - cache myRolesByServer; load on active server; refresh after self role edit - gate/notify @everyone and @channel; plain @username push; special mention UI - refresh FEATURE_PARITY (DMs exist; drop stale critical gaps) - README production deploy notes dumpster.service - unit tests for permission bits and broadcast mention tokens
39 lines
1017 B
Go
39 lines
1017 B
Go
package message
|
|
|
|
import "testing"
|
|
|
|
func TestHasBroadcastToken(t *testing.T) {
|
|
cases := []struct {
|
|
content string
|
|
token string
|
|
want bool
|
|
}{
|
|
{"hello @everyone", "everyone", true},
|
|
{"@everyone hi", "everyone", true},
|
|
{"@EVERYONE", "everyone", true},
|
|
{"@everyone!", "everyone", true},
|
|
{"@everyoneelse", "everyone", false},
|
|
{"noteveryone", "everyone", false},
|
|
{"@channel", "channel", true},
|
|
{"ping @channel please", "channel", true},
|
|
{"@channeling", "channel", false},
|
|
{"", "everyone", false},
|
|
{"@", "everyone", false},
|
|
}
|
|
for _, tc := range cases {
|
|
got := hasBroadcastToken(tc.content, tc.token)
|
|
if got != tc.want {
|
|
t.Errorf("hasBroadcastToken(%q, %q) = %v, want %v", tc.content, tc.token, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsUsernameChar(t *testing.T) {
|
|
if !isUsernameChar('a') || !isUsernameChar('9') || !isUsernameChar('_') {
|
|
t.Fatal("expected alnum/_")
|
|
}
|
|
if isUsernameChar(' ') || isUsernameChar('!') || isUsernameChar('@') {
|
|
t.Fatal("unexpected username chars")
|
|
}
|
|
}
|