diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-14 23:11:04 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-14 23:11:04 +0300 |
commit | 736abcb5bc3a7e2c0f1f1dfd3052cb6153b60d02 (patch) | |
tree | d98db15053f0889f999ae60e0fd67be8c3a963f9 /xmpp/component_test.go | |
parent | 47cf94ad01b4db8749c55c1a1dca50c9b94daf02 (diff) |
Send presence for recovered sessions
Diffstat (limited to 'xmpp/component_test.go')
-rw-r--r-- | xmpp/component_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/xmpp/component_test.go b/xmpp/component_test.go new file mode 100644 index 0000000..b540ad4 --- /dev/null +++ b/xmpp/component_test.go @@ -0,0 +1,54 @@ +package xmpp + +import ( + "encoding/xml" + "testing" + + "gosrc.io/xmpp/stanza" +) + +func testPresence(t *testing.T, presence stanza.Presence, reference string) { + byteXML, err := xml.Marshal(presence) + if err != nil { + t.Errorf("XML parse error: %v", err) + } + xmlText := string(byteXML) + if xmlText != reference { + t.Errorf("%v does not match %v", xmlText, reference) + } +} + +func TestPresenceFrom(t *testing.T) { + presence := newPresence("from@test", "to@test", SPFrom("test")) + testPresence(t, presence, "<presence from=\"test@from@test\" to=\"to@test\"></presence>") +} + +func TestPresenceNoFrom(t *testing.T) { + presence := newPresence("from@test", "to@test") + testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"></presence>") +} + +func TestPresenceType(t *testing.T) { + presence := newPresence("from@test", "to@test", SPType("subscribe")) + testPresence(t, presence, "<presence type=\"subscribe\" from=\"from@test\" to=\"to@test\"></presence>") +} + +func TestPresenceShow(t *testing.T) { + presence := newPresence("from@test", "to@test", SPShow("dnd")) + testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><show>dnd</show></presence>") +} + +func TestPresenceStatus(t *testing.T) { + presence := newPresence("from@test", "to@test", SPStatus("cooking")) + testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><status>cooking</status></presence>") +} + +func TestPresenceNickname(t *testing.T) { + presence := newPresence("from@test", "to@test", SPNickname("Ishmael")) + testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><nick xmlns=\"http://jabber.org/protocol/nick\">Ishmael</nick></presence>") +} + +func TestPresencePhoto(t *testing.T) { + presence := newPresence("from@test", "to@test", SPPhoto("01b87fcd030b72895ff8e88db57ec525450f000d")) + testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><x xmlns=\"vcard-temp:x:update\"><photo>01b87fcd030b72895ff8e88db57ec525450f000d</photo></x></presence>") +} |