2
0
mirror of https://github.com/FluuxIO/go-xmpp synced 2024-11-11 07:11:03 +00:00
go-xmpp/stanza/msg_receipts_test.go

43 lines
1.0 KiB
Go
Raw Normal View History

package stanza_test
2019-06-04 15:04:25 +00:00
import (
"encoding/xml"
"testing"
2019-06-26 15:28:54 +00:00
"gosrc.io/xmpp/stanza"
2019-06-04 15:04:25 +00:00
)
func TestDecodeRequest(t *testing.T) {
str := `<message
from='northumberland@shakespeare.lit/westminster'
id='richard2-4.1.247'
to='kingrichard@royalty.england.lit/throne'>
<body>My lord, dispatch; read o'er these articles.</body>
<request xmlns='urn:xmpp:receipts'/>
</message>`
2019-06-26 15:28:54 +00:00
parsedMessage := stanza.Message{}
2019-06-04 15:04:25 +00:00
if err := xml.Unmarshal([]byte(str), &parsedMessage); err != nil {
t.Errorf("message receipt unmarshall error: %v", err)
return
}
if parsedMessage.Body != "My lord, dispatch; read o'er these articles." {
t.Errorf("Unexpected body: '%s'", parsedMessage.Body)
}
if len(parsedMessage.Extensions) < 1 {
t.Errorf("no extension found on parsed message")
return
}
switch ext := parsedMessage.Extensions[0].(type) {
2019-06-26 15:28:54 +00:00
case *stanza.ReceiptRequest:
2019-06-04 15:04:25 +00:00
if ext.XMLName.Local != "request" {
t.Errorf("unexpected extension: %s:%s", ext.XMLName.Space, ext.XMLName.Local)
}
default:
t.Errorf("could not find receipts extension")
}
}