|
|
@@ -27,7 +27,9 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
// room participants (except the sender)
|
|
|
expectSNACToParticipants wire.SNACMessage
|
|
|
expectOutput *wire.SNACMessage
|
|
|
- wantErr error
|
|
|
+ // randRollDie generates result of rolling a die
|
|
|
+ randRollDie func(sides int) int
|
|
|
+ wantErr error
|
|
|
}{
|
|
|
{
|
|
|
name: "send chat room message, expect acknowledgement to sender client",
|
|
|
@@ -50,10 +52,12 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
Tag: wire.ChatTLVEnableReflectionFlag,
|
|
|
Value: []byte{},
|
|
|
},
|
|
|
- {
|
|
|
- Tag: wire.ChatTLVMessageInformation,
|
|
|
- Value: []byte{},
|
|
|
- },
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -77,7 +81,12 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
wire.NewTLVBE(wire.ChatTLVSenderInformation,
|
|
|
newTestSession("user_sending_chat_msg", sessOptCannedSignonTime).TLVUserInfo()),
|
|
|
wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
- wire.NewTLVBE(wire.ChatTLVMessageInformation, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -100,15 +109,19 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
wire.NewTLVBE(wire.ChatTLVSenderInformation,
|
|
|
newTestSession("user_sending_chat_msg", sessOptCannedSignonTime).TLVUserInfo()),
|
|
|
wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
- wire.NewTLVBE(wire.ChatTLVMessageInformation, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
- name: "send chat room message with macOS client 4.0.9 bug containing bad channel ID, expect message to " +
|
|
|
- "client on MIME channel",
|
|
|
+ name: "send die roll",
|
|
|
userSession: newTestSession("user_sending_chat_msg", sessOptCannedSignonTime,
|
|
|
sessOptChatRoomCookie("the-chat-cookie")),
|
|
|
inputSNAC: wire.SNACMessage{
|
|
|
@@ -117,7 +130,7 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
},
|
|
|
Body: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
|
|
|
Cookie: 1234,
|
|
|
- Channel: math.MaxUint16,
|
|
|
+ Channel: 14,
|
|
|
TLVRestBlock: wire.TLVRestBlock{
|
|
|
TLVList: wire.TLVList{
|
|
|
{
|
|
|
@@ -125,9 +138,112 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
Value: []byte{},
|
|
|
},
|
|
|
{
|
|
|
- Tag: wire.ChatTLVMessageInformation,
|
|
|
+ Tag: wire.ChatTLVEnableReflectionFlag,
|
|
|
+ Value: []byte{},
|
|
|
+ },
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">//roll-dice3-sides8</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mockParams: mockParams{
|
|
|
+ chatMessageRelayerParams: chatMessageRelayerParams{
|
|
|
+ chatRelayToAllExceptParams: chatRelayToAllExceptParams{
|
|
|
+ {
|
|
|
+ screenName: state.NewIdentScreenName("user_sending_chat_msg"),
|
|
|
+ cookie: "the-chat-cookie",
|
|
|
+ message: wire.SNACMessage{
|
|
|
+ Frame: wire.SNACFrame{
|
|
|
+ FoodGroup: wire.Chat,
|
|
|
+ SubGroup: wire.ChatChannelMsgToClient,
|
|
|
+ },
|
|
|
+ Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
|
|
|
+ Cookie: 1234,
|
|
|
+ Channel: 14,
|
|
|
+ TLVRestBlock: wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVSenderInformation, sessOnlineHost.TLVUserInfo()),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoEncoding, "us-ascii"),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoLang, "en"),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">user_sending_chat_msg rolled 3 8-sided dice: 2 4 8</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ expectOutput: &wire.SNACMessage{
|
|
|
+ Frame: wire.SNACFrame{
|
|
|
+ FoodGroup: wire.Chat,
|
|
|
+ SubGroup: wire.ChatChannelMsgToClient,
|
|
|
+ RequestID: 1234,
|
|
|
+ },
|
|
|
+ Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
|
|
|
+ Cookie: 1234,
|
|
|
+ Channel: 14,
|
|
|
+ TLVRestBlock: wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVSenderInformation, sessOnlineHost.TLVUserInfo()),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoEncoding, "us-ascii"),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoLang, "en"),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">user_sending_chat_msg rolled 3 8-sided dice: 2 4 8</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ randRollDie: func() func(sides int) int {
|
|
|
+ // return multiples of 2 starting with 2
|
|
|
+ val := 2
|
|
|
+ return func(sides int) int {
|
|
|
+ ret := val
|
|
|
+ val *= 2
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }(),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "send chat room message with macOS client 4.0.9 bug containing bad channel ID, expect message to " +
|
|
|
+ "client on MIME channel",
|
|
|
+ userSession: newTestSession("user_sending_chat_msg", sessOptCannedSignonTime,
|
|
|
+ sessOptChatRoomCookie("the-chat-cookie")),
|
|
|
+ inputSNAC: wire.SNACMessage{
|
|
|
+ Frame: wire.SNACFrame{
|
|
|
+ RequestID: 1234,
|
|
|
+ },
|
|
|
+ Body: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
|
|
|
+ Cookie: 1234,
|
|
|
+ Channel: math.MaxUint16,
|
|
|
+ TLVRestBlock: wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ {
|
|
|
+ Tag: wire.ChatTLVPublicWhisperFlag,
|
|
|
Value: []byte{},
|
|
|
},
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -151,7 +267,12 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
wire.NewTLVBE(wire.ChatTLVSenderInformation,
|
|
|
newTestSession("user_sending_chat_msg", sessOptCannedSignonTime).TLVUserInfo()),
|
|
|
wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
- wire.NewTLVBE(wire.ChatTLVMessageInformation, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -179,10 +300,12 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
Tag: wire.ChatTLVPublicWhisperFlag,
|
|
|
Value: []byte{},
|
|
|
},
|
|
|
- {
|
|
|
- Tag: wire.ChatTLVMessageInformation,
|
|
|
- Value: []byte{},
|
|
|
- },
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -206,7 +329,12 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
wire.NewTLVBE(wire.ChatTLVSenderInformation,
|
|
|
newTestSession("user_sending_chat_msg", sessOptCannedSignonTime).TLVUserInfo()),
|
|
|
wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
|
|
|
- wire.NewTLVBE(wire.ChatTLVMessageInformation, []byte{}),
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
|
|
|
+ TLVList: wire.TLVList{
|
|
|
+ wire.NewTLVBE(wire.ChatTLVMessageInfoText,
|
|
|
+ "<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
|
|
|
+ },
|
|
|
+ }),
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -227,6 +355,7 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
svc := NewChatService(chatMessageRelayer)
|
|
|
+ svc.randRollDie = tc.randRollDie
|
|
|
outputSNAC, err := svc.ChannelMsgToHost(context.Background(), tc.userSession, tc.inputSNAC.Frame,
|
|
|
tc.inputSNAC.Body.(wire.SNAC_0x0E_0x05_ChatChannelMsgToHost))
|
|
|
assert.ErrorIs(t, err, tc.wantErr)
|
|
|
@@ -234,3 +363,48 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestParseDiceCommand(t *testing.T) {
|
|
|
+ tests := []struct {
|
|
|
+ input []byte
|
|
|
+ expectedValid bool
|
|
|
+ expectedDice int
|
|
|
+ expectedSides int
|
|
|
+ }{
|
|
|
+ {[]byte("//roll-sides999-dice15"), true, 15, 999},
|
|
|
+ {[]byte("//roll-sides999-dice15 "), true, 15, 999},
|
|
|
+ {[]byte("//roll-SIDES999-DICE15"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides999-sides15"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides999-dice15 as I was saying"), false, 0, 0},
|
|
|
+ {[]byte("i'm gonna roll some dice //roll-sides999-dice15"), false, 0, 0},
|
|
|
+ {[]byte("//roll-dice15-sides999"), true, 15, 999},
|
|
|
+ {[]byte("//roll-dice15"), true, 15, 6},
|
|
|
+ {[]byte("//roll-dice0"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides0"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides999"), true, 2, 999},
|
|
|
+ {[]byte("//roll-dice16"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides1000"), false, 0, 0},
|
|
|
+ {[]byte("//roll-dice-5"), false, 0, 0},
|
|
|
+ {[]byte("//roll-sides-9"), false, 0, 0},
|
|
|
+ {[]byte("//roll"), true, 2, 6},
|
|
|
+ {[]byte("invalid input"), false, 0, 0},
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, test := range tests {
|
|
|
+ t.Run(string(test.input), func(t *testing.T) {
|
|
|
+ valid, dice, sides := parseDiceCommand(test.input)
|
|
|
+
|
|
|
+ if valid != test.expectedValid {
|
|
|
+ t.Errorf("For input '%s', expected valid = %v, got %v", test.input, test.expectedValid, valid)
|
|
|
+ }
|
|
|
+
|
|
|
+ if dice != test.expectedDice {
|
|
|
+ t.Errorf("For input '%s', expected dice = %d, got %d", test.input, test.expectedDice, dice)
|
|
|
+ }
|
|
|
+
|
|
|
+ if sides != test.expectedSides {
|
|
|
+ t.Errorf("For input '%s', expected sides = %d, got %d", test.input, test.expectedSides, sides)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|