Products: chat command filter, request signing, saved state
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2190230f81
commit
0c4f6caec1
4 files changed
+313
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package products
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func community(id int64) bool { return id >= 2000000000 }
|
||||
|
||||
func TestStripCommand(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
in, out string
|
||||
empty, outfit bool
|
||||
products string
|
||||
}{
|
||||
{"*use 80 123 2000000001 456", "*use 80 123 456", false, true, "[2000000001]"},
|
||||
{"*use 2000000001", "*use", true, false, "[2000000001]"},
|
||||
{"*putOnOutfit 5 2000000002 2000000003", "*putOnOutfit 5", false, false, "[2000000002 2000000003]"},
|
||||
{"*remove 2000000001", "*remove", true, false, "[2000000001]"},
|
||||
{"*use 80 123", "*use 80 123", false, true, "[]"},
|
||||
{"hello 2000000001", "hello 2000000001", false, false, "[]"},
|
||||
{"*imvu:setRoomState c...", "*imvu:setRoomState c...", false, false, "[]"},
|
||||
} {
|
||||
r := stripCommand(c.in, community)
|
||||
if r.text != c.out || r.empty != c.empty || r.outfit != c.outfit || fmt.Sprint(r.products) != c.products {
|
||||
t.Errorf("%q: got %+v", c.in, r)
|
||||
}
|
||||
if r.changed != (len(r.products) > 0) {
|
||||
t.Errorf("%q: changed %v", c.in, r.changed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatMessage(t *testing.T) {
|
||||
m, ok := parseChatMessage([]byte(`{"to": 0, "message": "*use 80 2000000001", "userId": 392, "chatId": 77}`))
|
||||
if !ok || m.text != "*use 80 2000000001" || m.userID != 392 {
|
||||
t.Fatalf("%+v %v", m, ok)
|
||||
}
|
||||
out := string(m.withText("*use 80"))
|
||||
if out != `{"chatId":77,"message":"*use 80","to":0,"userId":392}` {
|
||||
t.Fatal(out)
|
||||
}
|
||||
if _, ok := parseChatMessage([]byte(`not json`)); ok {
|
||||
t.Fatal("parsed non-JSON")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user