tests/iq: test_self_ping_answer

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-09-24 01:47:59 +02:00
parent da12752d50
commit be1930c584
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -67,6 +67,64 @@ async fn test_iq_unimplemented() {
handle_stanza(&mut component, &mut rooms).await.unwrap();
}
#[tokio::test]
async fn test_self_ping_answer() {
let realjid1 = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap());
let roomjid = COMPONENT_JID.clone().with_node("room");
let participant1 = Jid::Full(roomjid.clone().with_resource("nick1"));
let join: Element = Presence::new(PresenceType::None)
.with_from(realjid1.clone())
.with_to(participant1.clone())
.with_payloads(vec![Muc::new().into()])
.into();
let disco: Element = Iq {
from: Some(realjid1.clone()),
to: Some(participant1.clone()),
id: String::from("disco"),
payload: IqType::Get(DiscoInfoQuery { node: None }.into()),
}
.into();
let ping: Element = Iq {
from: Some(realjid1.clone()),
to: Some(participant1.clone()),
id: String::from("ping"),
payload: IqType::Get(Ping {}.into()),
}
.into();
let mut component = TestComponent::new(vec![join, disco, ping]);
let mut rooms: HashMap<BareJid, Room> = HashMap::new();
component.expect_presence(|_| (), "Self-presence");
component.expect_message(|_| (), "Subject");
component.expect_iq(
|iq| {
if let IqType::Result(Some(el)) = iq.payload {
if let Ok(result) = DiscoInfoResult::try_from(el) {
assert!(result.features.contains(&Feature {
var: String::from("http://jabber.org/protocol/muc#self-ping-optimization")
}));
} else {
panic!("Should be a disco result");
}
} else {
panic!("Should be a disco result");
}
},
"Disco",
);
component.expect(Into::<Element>::into(
Iq::empty_result(realjid1.clone(), "ping").with_from(participant1.clone()),
));
handle_stanza(&mut component, &mut rooms).await.unwrap();
}
#[tokio::test]
async fn test_self_ping_participant_non_existing() {
let realjid1 = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap());