Add test_presence_resync
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
c884f38dc2
commit
44bec0e232
2 changed files with 73 additions and 2 deletions
|
@ -18,8 +18,9 @@ file.
|
||||||
* [ ] Multiple sessions non-MSN
|
* [ ] Multiple sessions non-MSN
|
||||||
* [ ] MSN
|
* [ ] MSN
|
||||||
- [ ] Presence
|
- [ ] Presence
|
||||||
* [ ] Probes
|
* [x] Updates
|
||||||
* [ ] Resync
|
* [x] Resync
|
||||||
|
* [ ] Probes (storing updates to answer probes)
|
||||||
- [ ] Iq
|
- [ ] Iq
|
||||||
* [ ] Ping answers
|
* [ ] Ping answers
|
||||||
* [ ] Ping probes?
|
* [ ] Ping probes?
|
||||||
|
|
70
src/tests.rs
70
src/tests.rs
|
@ -303,6 +303,76 @@ async fn test_join_presence_existing_room() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_presence_resync() {
|
||||||
|
let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();
|
||||||
|
let realjid2 = FullJid::from_str("qxx@bar/foo").unwrap();
|
||||||
|
let roomjid = COMPONENT_JID.clone().with_node("room");
|
||||||
|
let participant1 = roomjid.clone().with_resource("nick1");
|
||||||
|
let participant2 = roomjid.clone().with_resource("nick2");
|
||||||
|
|
||||||
|
let join1: Element = Presence::new(PresenceType::None)
|
||||||
|
.with_from(Jid::Full(realjid1.clone()))
|
||||||
|
.with_to(Jid::Full(participant1.clone()))
|
||||||
|
.with_payloads(vec![Muc::new().into()])
|
||||||
|
.into();
|
||||||
|
|
||||||
|
let join2: Element = Presence::new(PresenceType::None)
|
||||||
|
.with_from(Jid::Full(realjid2.clone()))
|
||||||
|
.with_to(Jid::Full(participant2.clone()))
|
||||||
|
.with_payloads(vec![Muc::new().into()])
|
||||||
|
.into();
|
||||||
|
|
||||||
|
let mut component = TestComponent::new(vec![join1.clone(), join2, join1]);
|
||||||
|
let mut rooms: HashMap<BareJid, Room> = HashMap::new();
|
||||||
|
|
||||||
|
// Self-presence for participant1
|
||||||
|
component.expect_presence(|_| ());
|
||||||
|
// Subject for participant1
|
||||||
|
component.expect_message(|_| ());
|
||||||
|
// Participant1 presence for participant2
|
||||||
|
component.expect_presence(|_| ());
|
||||||
|
// Participant2 presence for participant1
|
||||||
|
component.expect_presence(|_| ());
|
||||||
|
// Self-presence for participant2
|
||||||
|
component.expect_presence(|_| ());
|
||||||
|
// Subject for participant2
|
||||||
|
component.expect_message(|_| ());
|
||||||
|
|
||||||
|
// Resync: Participant2 presence for participant1
|
||||||
|
component.expect(
|
||||||
|
Presence::new(PresenceType::None)
|
||||||
|
.with_from(Jid::Full(participant2.clone()))
|
||||||
|
.with_to(Jid::Full(realjid1.clone()))
|
||||||
|
.with_payloads(vec![MucUser {
|
||||||
|
status: Vec::new(),
|
||||||
|
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],
|
||||||
|
}
|
||||||
|
.into()]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Resync: Participant1 self-presence
|
||||||
|
component.expect(
|
||||||
|
Presence::new(PresenceType::None)
|
||||||
|
.with_from(Jid::Full(participant1))
|
||||||
|
.with_to(Jid::Full(realjid1.clone()))
|
||||||
|
.with_payloads(vec![MucUser {
|
||||||
|
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
|
||||||
|
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],
|
||||||
|
}
|
||||||
|
.into()]),
|
||||||
|
);
|
||||||
|
|
||||||
|
handle_stanza(&mut component, &mut rooms).await.unwrap();
|
||||||
|
component.assert();
|
||||||
|
|
||||||
|
match rooms.get(&roomjid) {
|
||||||
|
Some(room) => assert_eq!(room.occupants.len(), 2),
|
||||||
|
None => panic!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_leave_non_existing_room() {
|
async fn test_leave_non_existing_room() {
|
||||||
let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();
|
let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();
|
||||||
|
|
Loading…
Reference in a new issue