Skip to content

Commit

Permalink
update tests with permission and group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 committed Nov 11, 2024
1 parent 1fb89c8 commit 8db0e57
Showing 1 changed file with 87 additions and 8 deletions.
95 changes: 87 additions & 8 deletions extensions/warp-ipfs/tests/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ mod test {
constellation::Progression,
multipass::MultiPassEventKind,
raygun::{
AttachmentKind, ConversationType, Location, MessageEvent, MessageEventKind,
MessageType, PinState, RayGunEventKind, ReactionState,
AttachmentKind, ConversationType, GroupPermission, GroupPermissions, Location, MessageEvent, MessageEventKind, MessageType, PinState, RayGunEventKind, ReactionState
},
};

Expand Down Expand Up @@ -987,7 +986,9 @@ mod test {
let mut chat_subscribe_a = instance_a.raygun_subscribe().await?;
let mut chat_subscribe_b = instance_b.raygun_subscribe().await?;

instance_a.create_conversation(&did_b).await?;
let mut perms = GroupPermissions::new();
perms.insert(did_b.clone(), [GroupPermission::EditGroupInfo].into_iter().collect());
instance_a.create_group_conversation(None, vec![did_b.clone()], perms).await?;

let id_a = crate::common::timeout(Duration::from_secs(60), async {
loop {
Expand Down Expand Up @@ -1452,7 +1453,9 @@ mod test {
let mut chat_subscribe_a = instance_a.raygun_subscribe().await?;
let mut chat_subscribe_b = instance_b.raygun_subscribe().await?;

instance_a.create_conversation(&did_b).await?;
let mut perms = GroupPermissions::new();
perms.insert(did_b.clone(), [GroupPermission::EditGroupInfo].into_iter().collect());
instance_a.create_group_conversation(None, vec![did_b.clone()], perms).await?;

let conversation_id = crate::common::timeout(Duration::from_secs(60), async {
let mut id_a = None;
Expand All @@ -1475,7 +1478,7 @@ mod test {
}).await?;

let conversation = instance_a.get_conversation(conversation_id).await?;
assert_eq!(conversation.conversation_type(), ConversationType::Direct);
assert_eq!(conversation.conversation_type(), ConversationType::Group);
assert_eq!(conversation.recipients().len(), 2);
assert!(conversation.recipients().contains(&did_a));
assert!(conversation.recipients().contains(&did_b));
Expand All @@ -1494,7 +1497,6 @@ mod test {
},
)
.await?;

crate::common::timeout(Duration::from_secs(60), async {
let mut a_updated = false;
let mut b_updated = false;
Expand All @@ -1520,6 +1522,42 @@ mod test {

}).await??;

instance_b
.update_conversation_icon(
conversation_id,
Location::Stream {
name: "".into(),
size: Some(PROFILE_IMAGE.len()),
stream: futures::stream::once(async { Ok(PROFILE_IMAGE.to_vec().into()) })
.boxed(),
},
)
.await?;
crate::common::timeout(Duration::from_secs(60), async {
let mut a_updated = false;
let mut b_updated = false;

loop {
tokio::select! {
Some(MessageEventKind::ConversationUpdatedIcon { .. }) = conversation_stream_a.next() => {
b_updated = true;
let image = instance_b.conversation_icon(conversation_id).await?;
assert_eq!(image.data(), PROFILE_IMAGE);
},
Some(MessageEventKind::ConversationUpdatedIcon { .. }) = conversation_stream_b.next() => {
a_updated = true;
let image = instance_a.conversation_icon(conversation_id).await?;
assert_eq!(image.data(), PROFILE_IMAGE);
}
}

if a_updated && b_updated {
break Ok::<_, anyhow::Error>(())
}
}

}).await??;

instance_a.remove_conversation_icon(conversation_id).await?;

crate::common::timeout(Duration::from_secs(60), async {
Expand Down Expand Up @@ -1564,7 +1602,9 @@ mod test {
let mut chat_subscribe_a = instance_a.raygun_subscribe().await?;
let mut chat_subscribe_b = instance_b.raygun_subscribe().await?;

instance_a.create_conversation(&did_b).await?;
let mut perms = GroupPermissions::new();
perms.insert(did_b.clone(), [GroupPermission::EditGroupInfo].into_iter().collect());
instance_a.create_group_conversation(None, vec![did_b.clone()], perms).await?;

let conversation_id = crate::common::timeout(Duration::from_secs(60), async {
let mut id_a = None;
Expand All @@ -1587,7 +1627,7 @@ mod test {
}).await?;

let conversation = instance_a.get_conversation(conversation_id).await?;
assert_eq!(conversation.conversation_type(), ConversationType::Direct);
assert_eq!(conversation.conversation_type(), ConversationType::Group);
assert_eq!(conversation.recipients().len(), 2);
assert!(conversation.recipients().contains(&did_a));
assert!(conversation.recipients().contains(&did_b));
Expand Down Expand Up @@ -1631,6 +1671,45 @@ mod test {
}


}).await??;


instance_b
.update_conversation_banner(
conversation_id,
Location::Stream {
name: "".into(),
size: Some(PROFILE_IMAGE.len()),
stream: futures::stream::once(async { Ok(PROFILE_IMAGE.to_vec().into()) })
.boxed(),
},
)
.await?;

crate::common::timeout(Duration::from_secs(60), async {
let mut a_updated = false;
let mut b_updated = false;

loop {
tokio::select! {
Some(MessageEventKind::ConversationUpdatedBanner { .. }) = conversation_stream_a.next() => {
b_updated = true;
let image = instance_b.conversation_banner(conversation_id).await?;
assert_eq!(image.data(), PROFILE_IMAGE);
},
Some(MessageEventKind::ConversationUpdatedBanner { .. }) = conversation_stream_b.next() => {
a_updated = true;
let image = instance_a.conversation_banner(conversation_id).await?;
assert_eq!(image.data(), PROFILE_IMAGE);
}
}

if a_updated && b_updated {
break Ok::<_, anyhow::Error>(())
}
}


}).await??;

instance_a
Expand Down

0 comments on commit 8db0e57

Please sign in to comment.