package xmpp_test
import (
"encoding/xml"
"testing"
"gosrc.io/xmpp"
)
// https://xmpp.org/extensions/xep-0045.html#example-27
func TestMucPassword(t *testing.T) {
str := `
cauldronburn
`
var parsedPresence xmpp.Presence
if err := xml.Unmarshal([]byte(str), &parsedPresence); err != nil {
t.Errorf("Unmarshal(%s) returned error", str)
}
var muc xmpp.MucPresence
if ok := parsedPresence.Get(&muc); !ok {
t.Error("muc presence extension was not found")
}
if muc.Password != "cauldronburn" {
t.Errorf("incorrect password: '%s'", muc.Password)
}
}
// https://xmpp.org/extensions/xep-0045.html#example-37
func TestMucHistory(t *testing.T) {
str := `
`
var parsedPresence xmpp.Presence
if err := xml.Unmarshal([]byte(str), &parsedPresence); err != nil {
t.Errorf("Unmarshal(%s) returned error", str)
}
var muc xmpp.MucPresence
if ok := parsedPresence.Get(&muc); !ok {
t.Error("muc presence extension was not found")
}
if *muc.History.MaxStanzas != 20 {
t.Errorf("incorrect max stanza: '%d'", muc.History.MaxStanzas)
}
}
// https://xmpp.org/extensions/xep-0045.html#example-37
func TestMucNoHistory(t *testing.T) {
str := "" +
"" +
"" +
"" +
""
maxstanzas := 0
pres := xmpp.Presence{Attrs: xmpp.Attrs{
From: "hag66@shakespeare.lit/pda",
Id: "n13mt3l",
To: "coven@chat.shakespeare.lit/thirdwitch",
},
Extensions: []xmpp.PresExtension{
xmpp.MucPresence{
History: xmpp.History{MaxStanzas: &maxstanzas},
},
},
}
data, err := xml.Marshal(&pres)
if err != nil {
t.Error("error on encode:", err)
}
if string(data) != str {
t.Errorf("incorrect stanza: \n%s\n%s", str, data)
}
}