sync: 0.7.2 from main (6164dced8d3ab8f9bcce9bf333fb4e8663760ff1)
This commit is contained in:
1 parent
0f9ef308d2
commit
9337afc47e
74 files changed
+11173
-4687
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -325,3 +326,61 @@ func TestParseJID(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCanonicalJID locks in the fix for the silent typing-indicator / receipt
|
||||
// drop: ParseJID (via CreateJID) prefixes phone numbers with "+", which is
|
||||
// tolerated by message sending (usync normalizes it) but breaks RAW nodes
|
||||
// (chatstate, read receipts, reactions). CanonicalJID must strip that "+" while
|
||||
// leaving already-canonical JIDs (LID, group, digits-only) untouched.
|
||||
func TestCanonicalJID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectedJID string // canonical JID expected after ParseJID -> CanonicalJID
|
||||
}{
|
||||
{
|
||||
name: "BR phone strips the leading +",
|
||||
input: "554187083284",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "US phone strips the leading +",
|
||||
input: "15551234567",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "Already-canonical JID is unchanged",
|
||||
input: "[email protected]",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "LID JID is left untouched",
|
||||
input: "15883309207561@lid",
|
||||
expectedJID: "15883309207561@lid",
|
||||
},
|
||||
{
|
||||
name: "Group JID is left untouched",
|
||||
input: "[email protected]",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
jid, ok := ParseJID(tt.input)
|
||||
if !ok {
|
||||
t.Fatalf("ParseJID(%q) failed", tt.input)
|
||||
}
|
||||
|
||||
canonical := CanonicalJID(jid)
|
||||
|
||||
if got := canonical.String(); got != tt.expectedJID {
|
||||
t.Errorf("CanonicalJID for input %q = %q, want %q", tt.input, got, tt.expectedJID)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(canonical.User, "+") {
|
||||
t.Errorf("CanonicalJID for input %q still has '+' in User: %q", tt.input, canonical.User)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user