1package xmpp
2
3import (
4	"encoding/xml"
5
6	"github.com/coyim/coyim/xmpp/data"
7
8	. "gopkg.in/check.v1"
9)
10
11type RosterXMPPSuite struct{}
12
13var _ = Suite(&RosterXMPPSuite{})
14
15type testStanzaValue struct{}
16
17func (s *RosterXMPPSuite) Test_ParseRoster_parsesRosterStanza(c *C) {
18	rep := data.Stanza{
19		Name: xml.Name{Local: "iq"},
20		Value: &data.ClientIQ{
21			Query: []byte("<query xmlns=\"jabber:iq:roster\"><item jid=\"alice@coy.im\" subscription=\"both\" name=\"Alice\"/><item jid=\"alice@coy.im/coyim\" subscription=\"both\" name=\"Alice using CoyIM\"/></query>"),
22		},
23	}
24
25	roster, _ := data.ParseRoster(rep)
26
27	c.Assert(len(roster), Equals, 2)
28	c.Assert(roster[0].Jid, Equals, "alice@coy.im")
29	c.Assert(roster[1].Jid, Equals, "alice@coy.im/coyim")
30}
31
32func (s *RosterXMPPSuite) Test_ParseRoster_failsIfItDoesntReceiveAClientIQ(c *C) {
33	rep := data.Stanza{
34		Name:  xml.Name{Local: "Foobarium"},
35		Value: testStanzaValue{},
36	}
37
38	_, err := data.ParseRoster(rep)
39	c.Assert(err.Error(), Equals, "xmpp: roster request resulted in tag of type Foobarium")
40}
41
42func (s *RosterXMPPSuite) Test_ParseRoster_failsIfTheRosterContentIsIncorrect(c *C) {
43	rep := data.Stanza{
44		Name: xml.Name{Local: "iq"},
45		Value: &data.ClientIQ{
46			Query: []byte("<foo></bar>"),
47		},
48	}
49
50	_, err := data.ParseRoster(rep)
51	c.Assert(err.Error(), Equals, "expected element type <query> but have <foo>")
52}
53