feat(channel): 跨平台 IM 接入抽象契约(UnifiedMessage/PlatformAdapter/Capabilities/Actor 身份)
This commit is contained in:
1 parent
a21176ec0a
commit
c52ddfd9c7
8 files changed
+767
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package adapter
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCapabilitiesNormalizeFillsZeroNumerics(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
caps := Capabilities{Image: true, Proactive: true}.Normalize()
|
||||
|
||||
if caps.MaxMessageLength != defaultMaxMessageLength {
|
||||
t.Errorf("MaxMessageLength = %d, want %d", caps.MaxMessageLength, defaultMaxMessageLength)
|
||||
}
|
||||
if caps.RecommendBurstMax != defaultRecommendBurstMax {
|
||||
t.Errorf("RecommendBurstMax = %d, want %d", caps.RecommendBurstMax, defaultRecommendBurstMax)
|
||||
}
|
||||
// Boolean fields must be preserved, not overwritten by normalization.
|
||||
if !caps.Image || !caps.Proactive {
|
||||
t.Errorf("booleans changed by Normalize: %+v", caps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapabilitiesNormalizePreservesExplicit(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
caps := Capabilities{MaxMessageLength: 100, RecommendBurstMax: 5}.Normalize()
|
||||
|
||||
if caps.MaxMessageLength != 100 {
|
||||
t.Errorf("MaxMessageLength = %d, want 100 (explicit preserved)", caps.MaxMessageLength)
|
||||
}
|
||||
if caps.RecommendBurstMax != 5 {
|
||||
t.Errorf("RecommendBurstMax = %d, want 5 (explicit preserved)", caps.RecommendBurstMax)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultCapabilities(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
caps := DefaultCapabilities()
|
||||
|
||||
if caps.MaxMessageLength != defaultMaxMessageLength {
|
||||
t.Errorf("MaxMessageLength = %d, want %d", caps.MaxMessageLength, defaultMaxMessageLength)
|
||||
}
|
||||
if !caps.Markdown || !caps.Image {
|
||||
t.Errorf("expected markdown+image by default, got %+v", caps)
|
||||
}
|
||||
if caps.Voice || caps.Reaction || caps.TypingHint || caps.Proactive {
|
||||
t.Errorf("expected rich/proactive features off by default, got %+v", caps)
|
||||
}
|
||||
if caps.RecommendBurstMax != defaultRecommendBurstMax {
|
||||
t.Errorf("RecommendBurstMax = %d, want %d", caps.RecommendBurstMax, defaultRecommendBurstMax)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user